By reading it, this would mean it is actually safe, and wouldn't invalidate my ptr, and the statement about the free allocation for objects doesn't apply here? |
Yes, it'd be fine to use
std::list subject to the rules in that table.
std::vector::push_back invalidates iterators, references, and pointers to its elements
if and only if the vector's
capacity is modified by the call. If you used a vector instead, it wouldn't be safe to
push_back into it unless you could guarantee that its capacity would not change (by reserving enough space ahead of time).
std::make_shared simply creates a shared_ptr and therefore is again an dynamic allocation. |
std::make_shared commonly eliminates an allocation by merging the allocation of internal reference counters with that of storage for the pointed-to object. But yes,
std::shared_ptr usually needs to allocate at least once.
std::unique_ptr has no shared control block and won't require additional allocations. In the common case where its deleter is an empty class,
std::unique_ptr is generally the same size (through empty-base optimization) as the raw pointer it represents.
std::vector<smartptr<Node>> seems to contain unnecessary allocations. |
If you store smart pointers you must have space for the smart pointer itself as well as the object the pointer owns. Doing this does prevent issues with iterator invalidation.