Re:Don’t blindly prefer emplace_back to push_back
by tummulfingur on Thursday March 04, 2021 @06:57AM
(#26341308)
>> or some other piece of code is known to keep direct references to the elements that should not be invalidated
> In that case, why not store the elements in a unique_ptr (and then everything in a vector)?
I recently ended up using std::list<Object*> because of pointer invalidation on vector resize. I see now that using smart pointers would have worked just as well. Thanks.
> In that case, why not store the elements in a unique_ptr (and then everything in a vector)?
I recently ended up using std::list<Object*> because of pointer invalidation on vector resize. I see now that using smart pointers would have worked just as well. Thanks.