In the following sections,
a
and
b
denote values of type
X or const X,
difference_type and reference refer to the
types iterator_traits<X>::difference_type and
iterator_traits<X>::reference, respectively,
n
denotes a value of
difference_type,
u,
tmp,
and
m
denote identifiers,
r
denotes a value of
X&,
t
denotes a value of value type
T,
o
denotes a value of some type that is writable to the output iterator.

[*Note 1*: — *end note*]

The *Cpp17Iterator* requirements form the basis of the iterator
taxonomy; every iterator meets the *Cpp17Iterator* requirements.

This
set of requirements specifies operations for dereferencing and incrementing
an iterator.

Most algorithms will require additional operations to
read ([input.iterators]) or write ([output.iterators]) values, or
to provide a richer set of iterator movements ([forward.iterators], [bidirectional.iterators], [random.access.iterators]).

A type X meets the *Cpp17Iterator* requirements if:

- X meets the
*Cpp17CopyConstructible*,*Cpp17CopyAssignable*,*Cpp17Swappable*, and*Cpp17Destructible*requirements ([utility.arg.requirements], [swappable.requirements]), and - iterator_traits<X>::difference_type is a signed integer type or void, and
- the expressions in Table 86 are valid and have the indicated semantics.

A class or pointer type
X
meets the requirements of an input iterator for the value type
T
if
X meets the *Cpp17Iterator* ([iterator.iterators]) and
*Cpp17EqualityComparable* (Table 28) requirements and
the expressions in Table 87 are valid and have
the indicated semantics.

In Table 87, the term
*the domain of ==*
is used in the ordinary mathematical sense to denote
the set of values over which
== is (required to be) defined.

This set can change over time.

Each algorithm places additional requirements on the domain of
== for the iterator values it uses.

Table 87: *Cpp17InputIterator* requirements (in addition to *Cpp17Iterator*) [tab:inputiterator]

Expression | Return type | Operational | Assertion/note | |

semantics | pre-/post-condition | |||

a != b | decltype(a != b) models boolean-testable | !(a == b) | ||

*a | reference, convertible to T | |||

a->m | (*a).m | |||

++r | X& | |||

(void)r++ | equivalent to (void)++r | |||

*r++ | convertible to T | { T tmp = *r; ++r; return tmp; } |

A class or pointer type
X
meets the requirements of an output iterator
if X meets the *Cpp17Iterator* requirements ([iterator.iterators])
and the expressions in Table 88
are valid and have the indicated semantics.

Table 88: *Cpp17OutputIterator* requirements (in addition to *Cpp17Iterator*) [tab:outputiterator]

Expression | Return type | Operational | Assertion/note | |

semantics | pre-/post-condition | |||

*r = o | result is not used | |||

++r | X& | |||

r++ | convertible to const X& | { X tmp = r; ++r; return tmp; } | ||

*r++ = o | result is not used |

A class or pointer type
X
meets the requirements of a forward iterator if

- X meets the
*Cpp17InputIterator*requirements ([input.iterators]), - X meets the
*Cpp17DefaultConstructible*requirements ([utility.arg.requirements]), - if X is a mutable iterator, reference is a reference to T; if X is a constant iterator, reference is a reference to const T,
- the expressions in Table 89 are valid and have the indicated semantics, and
- objects of type X offer the multi-pass guarantee, described below.

Two dereferenceable iterators a and b of type X offer the
*multi-pass guarantee* if:

- a == b implies ++a == ++b and
- X is a pointer type or the expression (void)++X(a), *a is equivalent to the expression *a.

[*Note 2*: *end note*]

The requirement that
a == b
implies
++a == ++b
(which is not true for input and output iterators)
and the removal of the restrictions on the number of the assignments through
a mutable iterator
(which applies to output iterators)
allows the use of multi-pass one-directional algorithms with forward iterators.

— If a and b are equal, then either a and b
are both dereferenceable
or else neither is dereferenceable.

Table 90: *Cpp17BidirectionalIterator* requirements (in addition to *Cpp17ForwardIterator*) [tab:bidirectionaliterator]

Expression | Return type | Operational | Assertion/note | |

semantics | pre-/post-condition | |||

--r | X& | |||

r-- | convertible to const X& | { X tmp = r; --r; return tmp; } | ||

*r-- | reference |

Table 91: *Cpp17RandomAccessIterator* 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; | ||

a - n | X | { X tmp = a; return tmp -= n; } | ||

b - a | difference_type | return n; | ||

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 | ||

a >= b | decltype(a >= b) models boolean-testable | !(a < b) | ||

a <= b | decltype(a <= b) models boolean-testable | !(a > b) |