Say I have this struct:
struct position
{
int x, y;
};
and another class that takes this as constructor argument:
class positioned
{
public:
positioned(position p) : pos(p) {}
private:
position pos;
};
How can I get the simple
auto bla = std::make_unique<positioned>({1,2});
to work?
Currently, the compiler tries to match through the initializer_list<int>
and invoke the array variant of make_unique
, which is silly, because positioned
has only one constructor. The same issue arises for emplace
and emplace_back
functions. Pretty much any function that forwards its variadic template arguments to a class's constructor seems to exhibit this behaviour.
I understand I can resolve this by
- giving
positioned
a twoint
argument constructor and dropping the{}
in the call tomake_unique
, or - explicitly specifying the type of the argument to
make_unique
asposition{1,2}
.
Both seem overly verbose, as it seems to me (with some effort in the make_unique implementation), this can be resolved without this overspecification of the argument type.
Is this a resolvable defect in the make_unique
implementation or is this an unresolvable, uninteresting edge-case no one should care about?