Why is reset(new()) used for controls?

When generating a Component view, I see that all the controls (Sliders, etc.) are defined as std::unique_ptr, but the constructor for the Component instantiates them via x.reset(new Slider(…)…). Why is that? I thought that the correct way to create a std::unique_ptr was to use std::make_unique, not new. Is there a specific reason to continue using new in this case? I am using std::make_unique for my attachments (SliderAttachment, for example), and it seems to work as expected. Why not the controls as well?

That code probably just dates back to the time when we couldn’t yet use std::make_unique because it wasn’t supported on some compilers, and maybe also when we were using ScopedPointer rather than unique_ptr. But yes, absolutely - in new code, std::make_unique is the way to go.


Except IDEs won’t be able to show you hints about the constructor arguments.

1 Like

They can hint when you fill in the template parameter of make_unique. You have to do that to see constructor param placeholders and then move the > to the right spot, but it works in xcode