4 ms·
If only make_unique (and make_shared) worked with uniform initialization... struct Foo { int i; float f; bool b; // No constructor }; s
by Kristine1975 11y ago
If only make_unique (and make_shared) worked with uniform initialization...
struct Foo {
int i;
float f;
bool b;
// No constructor
};
std::make_unique<Foo>(1, 2.3f, true);
Doesn't compile, since make_unique requires an appropriate constructor (see https://isocpp.org/files/papers/n3588.txt https://isocpp.org/files/papers/n3588.txt for the rationale).
It also doesn't work when Foo's constructor is private, even when called from a function that would have access to this private constructor.
And this is my beef with C++: Yes it's powerful, and I quite like it, but you sooner or later hit these speed bumps that unnecessarily complicate things.