Title
What does iterator validity mean?
Status
cd1
Section
[list.ops]
Submitter
P.J. Plauger

Created on 2000-11-27.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Rationale:

This resolution simply defines a term that the Standard uses but never defines, "invalid", in terms of a term that is defined, "singular".

Why do we say "may be singular", instead of "is singular"? That's becuase a valid iterator is one that is known to be nonsingular. Invalidating an iterator means changing it in such a way that it's no longer known to be nonsingular. An example: inserting an element into the middle of a vector is correctly said to invalidate all iterators pointing into the vector. That doesn't necessarily mean they all become singular.

Date: 2010-10-21.18:28:33

[ Redmond: General agreement with the intent, some objections to the wording. Dave provided new wording. ]

Date: 2010-10-21.18:28:33

[ post-Copenhagen: Matt provided wording. ]

Date: 2010-10-21.18:28:33

Proposed resolution:

Add the following text to the end of section [iterator.concepts], after paragraph 5:

An invalid iterator is an iterator that may be singular. [Footnote: This definition applies to pointers, since pointers are iterators. The effect of dereferencing an iterator that has been invalidated is undefined.]

Date: 2000-11-27.00:00:00

Section [list.ops] states that

  void splice(iterator position, list<T, Allocator>& x);

invalidates all iterators and references to list x.

But what does the C++ Standard mean by "invalidate"? You can still dereference the iterator to a spliced list element, but you'd better not use it to delimit a range within the original list. For the latter operation, it has definitely lost some of its validity.

If we accept the proposed resolution to issue 250, then we'd better clarify that a "valid" iterator need no longer designate an element within the same container as it once did. We then have to clarify what we mean by invalidating a past-the-end iterator, as when a vector or string grows by reallocation. Clearly, such an iterator has a different kind of validity. Perhaps we should introduce separate terms for the two kinds of "validity."

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg2091
2010-10-21 18:28:33adminsetmessages: + msg2090
2010-10-21 18:28:33adminsetmessages: + msg2089
2010-10-21 18:28:33adminsetmessages: + msg2088
2000-11-27 00:00:00admincreate