C++ Logo

std-proposals

Advanced search

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

From: Nikolay Mihaylov <nmmm_at_[hidden]>
Date: Tue, 9 Dec 2025 10:55:21 +0200
note - the point is, e never become invalid. It is just losing its meaning
as "the end" iterator.
e.g. the iterator stay valid, but is not point to the end()

On Tue, Dec 9, 2025 at 10:55 AM Ville Voutilainen via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> On Tue, 9 Dec 2025 at 10:51, David Brown via Std-Proposals
> <std-proposals_at_[hidden]> wrote:
> > void append(iterator b, iterator e) {
> > for (auto n = e - b; n; n--, ++b) {
> > vec.push_back(*b);
> > }
> > }
> >
> > Won't that give the same set of push_back's without needing "e" to
> > remain valid?
>
> It does so by completely changing the requirements for the iterators
> that code works with. But considering
> just the example provided, it indeed doesn't change anything, and does
> provide an alternative way
> that was claimed to be impossible to write. :)
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2025-12-09 08:58:11