Question Details

No question body available.

Tags

c++ iterator language-lawyer

Answers (1)

Accepted Answer Available
Accepted Answer
February 7, 2026 Score: 5 Rep: 10,201 Quality: Expert Completeness: 50%

The current Standard (C++23 draft N4950) or in the future C++26 (Trunk from Tim Song generated 2025-12-15) has the following general statement in [container.reqmts]/67:

Unless otherwise specified (either explicitly or by defining a function in terms of other functions), invoking a container member function or passing a container as an argument to a library function shall not invalidate iterators to, or change the values of, objects within that container.

There is a current issue (2321) which mentions this, and recommends adding phrasing to the standard which would explicitly provide this guarantee; as they argue that the above phrasing is not applicable to move assignments / constructors. This issue is from 2013-09-21, and last modified 2023-01-20, however it is still "Open" and thus not in the standard.

It should be noted that the proposal would conflict with proposal 2389 which was approved for C++23, and thus would require additional changes to the standard.