This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD Editorial status.

### 446. Iterator equality between different containers

Section: 23.3 [iterator.requirements], 22.2 [container.requirements] Status: NAD Editorial Submitter: Andy Koenig Opened: 2003-12-16 Last modified: 2016-01-28

Priority: Not Prioritized

View all other issues in [iterator.requirements].

View all issues with NAD Editorial status.

Discussion:

What requirements does the standard place on equality comparisons between iterators that refer to elements of different containers. For example, if `v1` and `v2` are empty vectors, is `v1.end() == v2.end()` allowed to yield true? Is it allowed to throw an exception?

The standard appears to be silent on both questions.

[Sydney: The intention is that comparing two iterators from different containers is undefined, but it's not clear if we say that, or even whether it's something we should be saying in clause 23 or in clause 24. Intuitively we might want to say that equality is defined only if one iterator is reachable from another, but figuring out how to say it in any sensible way is a bit tricky: reachability is defined in terms of equality, so we can't also define equality in terms of reachability. ]

[ 2009-07 Frankfurt ]

> Daniel volunteered to work on this.

[ 2009-09-20 Daniel provided wording. ]

[ 2009-10 Santa Cruz: ]

> Leave as Open. Alisdair has volunteered to refine the wording.

[ 2010 Pittsburgh: Moved to NAD Editorial. Rationale added below. ]

Rationale:

Solved by N3066.

Proposed resolution:

Insert a new paragraph between 23.3 [iterator.requirements]/7+8:

> [..] The result of the application of functions in the library to invalid ranges is undefined.

> The result of directly or indirectly evaluating any comparison function or the binary - operator with two iterator values as arguments that were obtained from two different ranges `r1` and `r2` (including their past-the-end values) which are not subranges of one common range is undefined, unless explicitly described otherwise.