Calling reset() on a unique_ptr<XmlElement> no longer compiles in VS2019?

Hi! I just upgraded to the last Juce version, and I have stuff that no longer compiles in VS2019. Can’t seem to figure out why. Here’s what I have:

I have a variable called ‘model’ that contains bits and pieces of my data model, declared with a smart pointer as follows

std::unique_ptr<XmlElement> model;

And now the following 2 lines no longer compile:

model.reset(AudioProcessor::getXmlFromBinary(data, sizeInBytes));

Both parse() and getXmlFromBinary() return a pointer to an XmlElement - model.reset() does not seem to accept this here and produces following error:

Error	C2664	'void std::unique_ptr<juce::XmlElement,std::default_delete<_Ty>>::reset(juce::XmlElement *) noexcept': cannot convert argument 1 from 'std::unique_ptr<juce::XmlElement,std::default_delete<_Ty>>' to 'juce::XmlElement *'

Strangely, if I do something like the following, the compiler happily accepts that:

model.reset(new XmlElement("Test"));

Anybody a clue what I’m doing wrong, and why this behavior ? Any clues would be appreciated!

reset takes a raw pointer, but parse and getXmlFromBinary return unique_ptr now

1 Like

Tx Reuk. Damn. Any clue how I should deal with this now then?

You can assign a unique_ptr just normal. It uses move semantic, so the pointer you are assigning from becomes nullptr.

std::unique_ptr<XmlElement> model;
model = AudioProcessor::getXmlFromBinary(data, sizeInBytes);
model = XmlDocument::parse(f);
model = std::make_unique<XmlElement>("Test");

should work.

Tx @daniel - I was WAY overthinking this < slapHead /> :slight_smile:

1 Like