live element allocated, no object moved-from invalid or UB

Costs

What invalidates iterators and references

Quirks worth knowing

Invalidation at a glance

What an insertion or erasure does to existing iterators and references into the container.

containerinserterase
vector, stringall, if it reallocates; otherwise those at or after the insertion pointthose at or after the erased element
dequeat either end: all iterators, but no references; in the middle: allat either end: only the erased; in the middle: all
list, forward_listnoneonly the erased
set, map, multi*noneonly the erased
unordered_*iterators, if it rehashes; references neveronly the erased
flat_map, flat_setallall
span, string_viewwhatever invalidates the underlying storage