I have a vector of unique_ptr\'s and I want to append them to another vector of unique_ptrs. I would normally do a simple insert:
std::vector
unique_ptr
is not assignable with normal assignment operator (the error says it's deleted). You can only move them:
bar.insert(bar.end(),
std::make_move_iterator(baz.begin()),
std::make_move_iterator(baz.end())
);
Of course, this transfers the ownership of the managed object and original pointers will have nullptr
value.
You can't copy them; you'll have to move them.
std::move(baz.begin(), baz.end(), std::back_inserter(bar));