Files
2025-10-25 03:02:53 +03:00

2.9 KiB

[random.access.iterators]

24 Iterators library [iterators]

24.3 Iterator requirements [iterator.requirements]

24.3.5 C++17 iterator requirements [iterator.cpp17]

24.3.5.7 Random access iterators [random.access.iterators]

1

#

A class or pointer typeX meets the requirements of a random access iterator if, in addition to meeting the Cpp17BidirectionalIterator requirements, the following expressions are valid as shown in Table 83.

Table 83Cpp17RandomAccessIterator requirements (in addition to Cpp17BidirectionalIterator) [tab:randomaccessiterator]

🔗
Expression
Return type Operational Assertion/note
🔗 semantics pre-/post-condition
🔗
r += n
X& { difference_type m = n; if (m >= 0) while (m--) ++r; else while (m++) --r; return r; }
🔗
a + n n + a
X { X tmp = a; return tmp += n; } a + n == n + a.
🔗
r -= n
X& return r += -n; Preconditions: the absolute value of n is in the range of representable values of difference_type.
🔗
a - n
X { X tmp = a; return tmp -= n; }
🔗
b - a
difference_type return n; Preconditions: there exists a value n of type difference_type such that a + n == b.
b == a + (b - a).
🔗
a[n]
convertible to reference *(a + n)
🔗
a < b
decltype(a < b) models boolean-testable Effects: Equivalent to: return b - a > 0; < is a total ordering relation
🔗
a > b
decltype(a > b) models boolean-testable b < a > is a total ordering relation opposite to <.
🔗
a >= b
decltype(a >= b) models boolean-testable !(a < b)
🔗
a <= b
decltype(a <= b) models boolean-testable !(a > b)