How do I move a unique_ptr
from one vector to another vector of unique_ptr
s in C++11? The unique pointer from the first vector should be completely removed and added to the second vector.
Well, in that case you have two conceptually independent operations:
Inserting an element into a container. As you want to obliterate the source (which is actually necessary because std::unique_ptr
is a move-only type), use std::move
to enable move-semantics.
destination.emplace(destination.begin() + m, std::move(source[n])); // or .insert()
Removing the plundered element from the container.
source.erase(source.begin() + n);
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments