I have two classes, say Base
and Derived: public Base
and two std::vector
s, one holding elements of type unique_ptr<Base>
and other one holds elements of type unique_ptr<Derived>
How can I transfer ownership of all elements from second vector into first one? I already tried:
vector<unique_ptr<Base>> v1;
vector<unique_ptr<Derived>> v2;
// do something
std::move(v2.begin(),v2.end(),v1.begin()); // This line crashed
v1 = std::move(v2); // And this gives a compiler error