A unique_ptr
cannot be copy-constructed or copy-assigned. In the case of a push_back
into a vector, it is moved, provided it is an rvalue. To test this, you can try pushing an lvalue. This would require the unique_ptr
to be copyable or assignable, and so would fail:
std::unique_ptr<CObject> p(new CObject());
std::vector<std::unique_ptr<CObject>> vec;
vec.push_back(p); // error!
vec.push_back(std::unique_ptr<CObject>(new CObject())); // OK
vec.push_back(std::move(p)); // OK