Files
cppdraft_translate/cppdraft/forward/iterators.md
2025-10-25 03:02:53 +03:00

3.7 KiB

[forward.iterators]

24 Iterators library [iterators]

24.3 Iterator requirements [iterator.requirements]

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

24.3.5.5 Forward iterators [forward.iterators]

1

#

A class or pointer typeX meets the Cpp17ForwardIterator requirements 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 81 are valid and have the indicated semantics, and

objects of type X offer the multi-pass guarantee, described below.

2

#

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

Value-initialized iterators behave as if they refer past the end of the same empty sequence.

— end note]

3

#

Two dereferenceable iterators a and b of type X offer themulti-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.

4

#

[Note 2:

The requirement thata == 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.

— end note]

Table 81Cpp17ForwardIterator requirements (in addition to Cpp17InputIterator) [tab:forwarditerator]

🔗
Expression
Return type Operational Assertion/note
🔗 semantics pre-/post-condition
🔗
r++
convertible to const X& { X tmp = r; ++r; return tmp; }
🔗
*r++
reference

5

#

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

6

#

If a and b are both dereferenceable, then a == b if and only if*a and *b are bound to the same object.