Title
Random access iterator requirements lack limiting relational operators domain to comparing those from the same range
Status
c++23
Section
[random.access.iterators]
Submitter
Peter Sommerlad

Created on 2019-07-15.00:00:00 last changed 5 months ago

Messages

Date: 2020-11-09.20:31:48

Proposed resolution:

This wording is relative to N4849.

  1. Modify [random.access.iterators] as indicated:

    Table 87: Cpp17RandomAccessIterator requirements (in addition to Cpp17BidirectionalIterator) [tab:randomaccessiterator]
    Expression Return type Operational semantics Assertion/note
    pre-/post-condition
    […]
    a < b contextually convertible to bool Effects: Equivalent to: return b - a > 0; < is a total ordering relation
Date: 2020-11-09.00:00:00

[ 2020-11-09 Approved In November virtual meeting. Status changed: Ready → WP. ]

Date: 2020-02-15.00:00:00

[ 2020-02-13, Prague ]

P3, but some hesitation to make it Immediate, therefore moving to Ready.

Date: 2019-07-15.00:00:00

[ 2019-07-29; Casey comments and provides wording ]

Change the "Operational Semantics" column of the "a < b" row of [tab:randomaccessiterator] to "Effects: Equivalent to: return b - a > 0;

It then follows that a < b is required to be well-defined over the domain for which b - a is required to be well-defined, which is the set of pairs (x, y) such that there exists a value n of type difference_type such that x + n == b.

Date: 2019-07-15.00:00:00

For forward iterators we have very clear wording regarding the restricted domain of operator== in [forward.iterators] p2:

The domain of == for forward iterators is that of iterators over the same underlying sequence. However, value-initialized iterators may be compared and shall compare equal to other value-initialized iterators of the same type. [Note: Value-initialized iterators behave as if they refer past the end of the same empty sequence. — end note]

But for the relational operators of random access iterators specified in [random.access.iterators], Table [tab:randomaccessiterator], no such domain constraints are clearly defined, except that we can infer that they are similarly constrained as the difference of the compared iterators by means of the operational semantics of operator<.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2020-11-09 20:31:48adminsetmessages: + msg11544
2020-11-09 20:31:48adminsetstatus: ready -> wp
2020-02-13 10:17:41adminsetmessages: + msg11048
2020-02-13 10:17:41adminsetstatus: new -> ready
2019-08-02 17:24:33adminsetmessages: + msg10528
2019-08-02 17:24:33adminsetmessages: + msg10527
2019-07-15 00:00:00admincreate