Search code examples
c++iteratorinsert-iterator

insert_iterator invalidation rules


What actions to an STL container can invalidate a C++ std::insert_iterator referencing that container? Is an insert_iterator valid iff its underlying iterator (protected member iter) is, subject to the usual Iterator invalidation rules?

Related: std::insert_iterator and iterator invalidation gives an example of an invalid insert_iterator but did not elucidate the rules.


Solution

  • Is an insert_iterator valid iff its underlying iterator (protected member iter) is,

    You are correct, that's the reason that protected member is listed in the spec and the functions that work on the insert_iterator (specifically, operator=, since the rest is no-ops) are defined in terms of functions that access iter