Say I have a vector of some generic T objects:
std::vector<T> vector_of_ts = {...};
That vector is basically a heap-allocated array of T objects, under the hood. Now, say I have the following:
std::unique_ptr<T> t = std::make_unique<T>(...);
Again, this is a heap-allocated T object under the hood. Is it possible to push back that object to the vector by moving it, without making temporary/extra copies? Something like:
vector_of_ts.move(*t)
vector_of_ts.emplace_back(std::move(*t))will let you move the T from the unique_ptr into the vector: exampleNote that after the move,
tpoints to the moved-fromTobject. The state of this object depends on what the move constructor does (std containers for example are left in a "valid but unspecified" state, meaning you shouldn't do anything with them except destroy them or reassign to them).