Std::unique_ptr in Projucer

When using the UI editor in the Projucer, I see that components added now use std::unique_ptr instead of ScopedPointer.
Although I really like the simplicity of the ScopedPointer I guess you have your reasons for this change.
I have one problem though, when changing a old file and resaving it, the components are now std::unique_ptr, but the code generated by the Projucer access the components as “comp->setBounds(…” , should it not be “comp.get()->setBounds(…” ?
at least in Clion I get errors.
This is what Projucer outputs:

label.reset (new Label (“new label”,
addAndMakeVisible (label.get());
label->setFont (Font (18.00f, Font::plain).withTypefaceStyle (“Regular”));
label->setJustificationType (Justification::centredLeft);
label->setEditable (false, false, false);
label->setColour (Label::textColourId, Colours::white);
label->setColour (TextEditor::textColourId, Colours::black);
label->setColour (TextEditor::backgroundColourId, Colour (0x00000000));

label->setBounds (0, 0, 184, 24);

Can’t see how that would work.
Projucer version 5.3.2

The -> operator is overloaded for std::unique_ptr.

What are the errors?

1 Like

I experience the CLion/AppCode syntax check to have some strange problems with std::unique_ptr. However the compiler doesn’t complain. So do you really experience compiler errors or just CLion warnings which might be some strange JetBrains bug?

@timur :slight_smile:

I once had the same problem. Back then I could solve it by changing the C++ language standard to “C++11” instead of “default (C++11)”. Maybe this still works. (Although you might want to use C++14 instead.

Thanks for getting back to me so fast.
For some reason, I just merged in the latest juce tip (master), and everything was fine. Can’t really explain it.