§23.1.2.8 in the standard states that insertion/deletion operations on a set/map will not invalidate any iterators to those objects (except iterators pointing to a deleted eleme
C++ Standard states that iterators should stay valid. And it is. Standard clearly states that in 23.1.2/8:
The insert members shall not affect the validity of iterators and references to the container, and the erase members shall invalidate only iterators and references to the erased elements.
And in 21.1/7:
end() returns an iterator which is the past-the-end value for the container.
So iterators old_end
and new_end
will be valid. That means that we could get --old_end
(call it it1
) and --new_end
(call it it2
) and it will be the-end value iterators (from definition of what end()
returns), since iterator of an associative container is of the bidirectional iterator category (according to 23.1.2/6) and according to definition of --r
operation (Table 75).
Now it1
should be equal it2
since it gives the-end value, which is only one (23.1.2/9). Then from 24.1.3 follows that: The condition that a == b implies ++a == ++b. And ++it1
and ++it2
will give old_end
and new_end
iterators (from definition of ++r operation Table 74). Now we get that old_end
and new_end
should be equal.