C++ named requirements: LegacyRandomAccessIterator - cppreference.com
From cppreference.com
A LegacyRandomAccessIterator is a LegacyBidirectionalIterator that can be moved to point to any element in constant time.
If a LegacyRandomAccessIterator it originates from a Container, then it's value_type is the same as the container's, so dereferencing (*it) obtains the container's value_type.
A pointer to an element of an array satisfies all requirements of LegacyRandomAccessIterator.
Requirements
The type It satisfies LegacyRandomAccessIterator if
- The type
Itsatisfies LegacyBidirectionalIterator
And, given
value_type, the type denoted bystd::iterator_traits<It>::value_typedifference_type, the type denoted bystd::iterator_traits<It>::difference_typereference, the type denoted bystd::iterator_traits<It>::referencei,a,b, objects of typeItorconst Itr, an lvalue of typeItn, an integer of typedifference_type
The following expressions must be valid and have their specified effects:
| Expression | Return type | Operational semantics | Notes | ||||
|---|---|---|---|---|---|---|---|
r += n
|
It&
|
difference_type m = n; if (m >= 0) while (m--) ++r; else while (m++) --r; return r;
|
| ||||
a + n
|
It
|
It temp = a; return temp += n;
|
| ||||
r -= n |
It& |
return r += -n;
|
The absolute value of n must be within the range of representable values of difference_type.
| ||||
i - n |
It |
It temp = i; return temp -= n; |
|||||
b - a |
difference_type |
return n;(see the precondition) |
Precondition:
Postcondition:
| ||||
i[n] |
convertible to reference |
*(i + n) |
|||||
a < b
|
|
Equivalent to return b - a > 0;
|
Precondition:
Strict total ordering relation:
| ||||
a > b
|
|
b < a
|
Total ordering relation opposite to a < b
| ||||
a >= b
|
|
!(a < b)
|
|||||
a <= b
|
|
!(a > b)
|
The above rules imply that LegacyRandomAccessIterator also implements LessThanComparable.
A mutable LegacyRandomAccessIterator is a LegacyRandomAccessIterator that additionally satisfies the LegacyOutputIterator requirements.
ConceptFor the definition of std::iterator_traits, the following exposition-only concept is defined.
where the exposition-only concept |
(since C++20) |
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 299 (N3066) |
C++98 | the return type of a[n] was requiredto be convertible to const value_type&
|
the return type is required to be convertible to reference
|
| LWG 448 | C++98 | the return type of a[n] was requiredto be convertible to value_type
|
the return type is required to be convertible to const value_type&[1]
|
| LWG 1079 | C++98 | b - a was defined using a < b,resulted in circular definition |
removed a < b from the definition
|
| LWG 2114 (P2167R3) |
C++98 | convertibility to bool was too weak to reflect the expectation of implementations
|
requirements strengthened |
- ↑ LWG issue 299 was reopened after this resolution.