Pointers to elements of std::vector and std::list

Vectors – No. Because the capacity of vectors never shrinks, it is guaranteed that references, pointers, and iterators remain valid even when elements are deleted or changed, provided they refer to a position before the manipulated elements. However, insertions may invalidate references, pointers, and iterators.

Lists – Yes, inserting and deleting elements does not invalidate pointers, references, and iterators to other elements

Leave a Comment