I have a class with two std::unique_ptr
members. I want to set those members through the constructor.
Currently I'm doing this:
std::unique_ptr<Assignment> assignment{new Assignment{
std::unique_ptr<Variable>{new Variable{"a"}},
std::unique_ptr<Expression>{new Variable{"b"}}
}};
With regular pointers, I would just have done this:
auto assignment = new Assignment{new Variable{"a"}, new Variable{"b"}};
delete assignment;
Can I make the smart pointer version less verbose somehow? I was hoping something like this might work.
std::unique_ptr<Assignment> assignment{new Variable{"a"},{new Variable{"b"}};
However, the constructor of unique_ptr
is explicit, so it doesn't.