C++ Logo

std-proposals

Advanced search

Re: [std-proposals] vector::push_back must not invalidate past-the-end iterator

From: Andre Kostur <andre_at_[hidden]>
Date: Mon, 8 Dec 2025 08:30:18 -0800
> > After that insertion: the references, iterators, and pointers that
> were formed before the insertion no longer point/refer to the same
> things they did before.
>
> no, there are no relocation

Yes, they are still referring to the same chunks of memory, the
contents of the objects may/would have been moved along. And by "same
things" I'm talking about the contents of the object, not their
addresses. If I had a pointer to the Player named "Parzival" before,
that might have become a pointer to "Aech".

>
> > Also, with sufficient magic, the end iterator in a vector could be
> some sentinel value
>
> no

Care to elaborate? If vector::iterator were implemented as a
full-blown class, it can have special logic to note that it has become
the "end" iterator and use a special internal value to represent that.

Also, my last question is still outstanding: "What's the use-case for
this change to be useful?"

Received on 2025-12-08 16:30:31