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

103 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[forward.iterators]
# 24 Iterators library [[iterators]](./#iterators)
## 24.3 Iterator requirements [[iterator.requirements]](iterator.requirements#forward.iterators)
### 24.3.5 C++17 iterator requirements [[iterator.cpp17]](iterator.cpp17#forward.iterators)
#### 24.3.5.5 Forward iterators [forward.iterators]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2230)
A class or pointer typeX meets the *Cpp17ForwardIterator* requirements if
- [(1.1)](#1.1)
X meets the *Cpp17InputIterator* requirements ([[input.iterators]](input.iterators "24.3.5.3Input iterators")),
- [(1.2)](#1.2)
X meets the *Cpp17DefaultConstructible* requirements ([[utility.arg.requirements]](utility.arg.requirements "16.4.4.2Template argument requirements")),
- [(1.3)](#1.3)
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,
- [(1.4)](#1.4)
the expressions in Table [81](#tab:forwarditerator "Table 81: Cpp17ForwardIterator requirements (in addition to Cpp17InputIterator)") are valid and have the indicated semantics, and
- [(1.5)](#1.5)
objects of type X offer the multi-pass guarantee, described below[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2249)
The domain of == for forward iterators is that of iterators over the same
underlying sequence[.](#2.sentence-1)
However, value-initialized iterators may be compared and
shall compare equal to other value-initialized iterators of the same type[.](#2.sentence-2)
[*Note [1](#note-1)*:
Value-initialized iterators behave as if they refer past the end of
the same empty sequence[.](#2.sentence-3)
— *end note*]
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2258)
Two dereferenceable iterators a and b of type X offer the[*multi-pass guarantee*](#def:multi-pass_guarantee "24.3.5.5Forward iterators[forward.iterators]") if
- [(3.1)](#3.1)
a == b implies ++a == ++b and
- [(3.2)](#3.2)
X is a pointer type or the expression(void)++X(a), *a is equivalent to the expression *a[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2267)
[*Note [2](#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[.](#4.sentence-1)
— *end note*]
Table [81](#tab:forwarditerator) — *Cpp17ForwardIterator* requirements (in addition to *Cpp17InputIterator*) [[tab:forwarditerator]](./tab:forwarditerator)
| [🔗](#tab:forwarditerator-row-1)<br>**Expression** | **Return type** | **Operational** | **Assertion/note** |
| --- | --- | --- | --- |
| [🔗](#tab:forwarditerator-row-2) | | **semantics** | **pre-/post-condition** |
| [🔗](#tab:forwarditerator-row-3)<br>r++ | convertible to const X& | { X tmp = r; ++r; return tmp; } | |
| [🔗](#tab:forwarditerator-row-4)<br>*r++ | reference | | |
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2297)
If a and b are equal, then either a and b are both dereferenceable
or else neither is dereferenceable[.](#5.sentence-1)
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/iterators.tex#L2302)
If a and b are both dereferenceable, then a == b if and only if*a and *b are bound to the same object[.](#6.sentence-1)