- tmp/tmpxz_dz54o/{from.md → to.md} +3499 -1016
tmp/tmpxz_dz54o/{from.md → to.md}
RENAMED
|
@@ -1,72 +1,509 @@
|
|
| 1 |
# Iterators library <a id="iterators">[[iterators]]</a>
|
| 2 |
|
| 3 |
## General <a id="iterators.general">[[iterators.general]]</a>
|
| 4 |
|
| 5 |
This Clause describes components that C++ programs may use to perform
|
| 6 |
-
iterations over containers
|
| 7 |
-
[[
|
| 8 |
|
| 9 |
The following subclauses describe iterator requirements, and components
|
| 10 |
for iterator primitives, predefined iterators, and stream iterators, as
|
| 11 |
-
summarized in
|
| 12 |
|
| 13 |
-
**Table: Iterators library summary** <a id="
|
| 14 |
|
| 15 |
| Subclause | | Header |
|
| 16 |
-
| ------------------------- | -------------------- | ------------ |
|
| 17 |
-
| [[iterator.requirements]] |
|
| 18 |
-
| [[iterator.primitives]] | Iterator primitives
|
| 19 |
-
| [[predef.iterators]] |
|
| 20 |
| [[stream.iterators]] | Stream iterators | |
|
|
|
|
| 21 |
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
## Iterator requirements <a id="iterator.requirements">[[iterator.requirements]]</a>
|
| 24 |
|
| 25 |
### In general <a id="iterator.requirements.general">[[iterator.requirements.general]]</a>
|
| 26 |
|
| 27 |
Iterators are a generalization of pointers that allow a C++ program to
|
| 28 |
-
work with different data structures (
|
| 29 |
-
be able to construct template algorithms that
|
| 30 |
-
efficiently on different types of data structures,
|
| 31 |
-
formalizes not just the interfaces but also the semantics
|
| 32 |
-
assumptions of iterators. An input iterator `i` supports
|
| 33 |
-
`*i`, resulting in a value of some object type `T`,
|
| 34 |
-
type* of the iterator. An output iterator `i` has a
|
| 35 |
-
types that are
|
| 36 |
-
expression `*i = o` is valid where `o` is a
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
corresponding signed integer type called the *difference type* of the
|
| 41 |
-
iterator.
|
| 42 |
|
| 43 |
-
Since iterators are an abstraction of pointers, their semantics
|
| 44 |
generalization of most of the semantics of pointers in C++. This ensures
|
| 45 |
that every function template that takes iterators works as well with
|
| 46 |
-
regular pointers. This
|
| 47 |
-
|
| 48 |
-
iterators*, *
|
| 49 |
-
iterators* and *
|
| 50 |
-
[[
|
| 51 |
|
| 52 |
-
**Table: Relations among iterator categories** <a id="
|
| 53 |
|
| 54 |
-
|
|
| 55 |
-
| ----------------- | ------------------------------- | ------------------------- | ------------------------ |
|
| 56 |
-
| **Random Access** | $\rightarrow$ **Bidirectional** | $\rightarrow$ **Forward** | $\rightarrow$ **Input** |
|
| 57 |
-
|
|
| 58 |
|
| 59 |
|
| 60 |
-
|
| 61 |
-
can be used whenever an input iterator is specified; Bidirectional
|
| 62 |
-
iterators also satisfy all the requirements of forward iterators and can
|
| 63 |
-
be used whenever a forward iterator is specified; Random access
|
| 64 |
-
iterators also satisfy all the requirements of bidirectional iterators
|
| 65 |
-
and can be used whenever a bidirectional iterator is specified.
|
| 66 |
|
| 67 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
called *mutable iterators*. Nonmutable iterators are referred to as
|
| 69 |
*constant iterators*.
|
| 70 |
|
| 71 |
In addition to the requirements in this subclause, the nested
|
| 72 |
*typedef-name*s specified in [[iterator.traits]] shall be provided for
|
|
@@ -74,24 +511,14 @@ the iterator type.
|
|
| 74 |
|
| 75 |
[*Note 1*: Either the iterator type must provide the *typedef-name*s
|
| 76 |
directly (in which case `iterator_traits` pick them up automatically),
|
| 77 |
or an `iterator_traits` specialization must provide them. — *end note*]
|
| 78 |
|
| 79 |
-
Iterators that further satisfy the requirement that, for integral values
|
| 80 |
-
`n` and dereferenceable iterator values `a` and `(a + n)`, `*(a + n)` is
|
| 81 |
-
equivalent to `*(addressof(*a) + n)`, are called *contiguous iterators*.
|
| 82 |
-
|
| 83 |
-
[*Note 2*: For example, the type “pointer to `int`” is a contiguous
|
| 84 |
-
iterator, but `reverse_iterator<int *>` is not. For a valid iterator
|
| 85 |
-
range [`a`,`b`) with dereferenceable `a`, the corresponding range
|
| 86 |
-
denoted by pointers is [`addressof(*a)`,`addressof(*a) + (b - a)`); `b`
|
| 87 |
-
might not be dereferenceable. — *end note*]
|
| 88 |
-
|
| 89 |
Just as a regular pointer to an array guarantees that there is a pointer
|
| 90 |
value pointing past the last element of the array, so for any iterator
|
| 91 |
type there is an iterator value that points past the last element of a
|
| 92 |
-
corresponding sequence.
|
| 93 |
Values of an iterator `i` for which the expression `*i` is defined are
|
| 94 |
called *dereferenceable*. The library never assumes that past-the-end
|
| 95 |
values are dereferenceable. Iterators can also have singular values that
|
| 96 |
are not associated with any sequence.
|
| 97 |
|
|
@@ -100,135 +527,1123 @@ with `int* x;`), `x` must always be assumed to have a singular value of
|
|
| 100 |
a pointer. — *end example*]
|
| 101 |
|
| 102 |
Results of most expressions are undefined for singular values; the only
|
| 103 |
exceptions are destroying an iterator that holds a singular value, the
|
| 104 |
assignment of a non-singular value to an iterator that holds a singular
|
| 105 |
-
value, and, for iterators that
|
| 106 |
requirements, using a value-initialized iterator as the source of a copy
|
| 107 |
or move operation.
|
| 108 |
|
| 109 |
-
[*Note
|
| 110 |
although the distinction only matters for types with trivial default
|
| 111 |
constructors such as pointers or aggregates holding
|
| 112 |
pointers. — *end note*]
|
| 113 |
|
| 114 |
In these cases the singular value is overwritten the same way as any
|
| 115 |
other value. Dereferenceable values are always non-singular.
|
| 116 |
|
| 117 |
-
An iterator `j` is called *reachable* from an iterator `i` if and only
|
| 118 |
-
if there is a finite sequence of applications of the expression `++i`
|
| 119 |
-
that makes `i == j`. If `j` is reachable from `i`, they refer to
|
| 120 |
-
elements of the same sequence.
|
| 121 |
-
|
| 122 |
Most of the library’s algorithmic templates that operate on data
|
| 123 |
-
structures have interfaces that use ranges. A *range* is
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
`i`
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
All the categories of iterators require only those functions that are
|
| 133 |
realizable for a given category in constant time (amortized). Therefore,
|
| 134 |
-
requirement tables for the iterators do not
|
|
|
|
| 135 |
|
| 136 |
-
Destruction of
|
| 137 |
-
previously obtained from that iterator.
|
| 138 |
|
| 139 |
-
An *invalid
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
In the following sections, `a` and `b` denote values of type `X` or
|
| 142 |
`const X`, `difference_type` and `reference` refer to the types
|
| 143 |
`iterator_traits<X>::difference_type` and
|
| 144 |
`iterator_traits<X>::reference`, respectively, `n` denotes a value of
|
| 145 |
`difference_type`, `u`, `tmp`, and `m` denote identifiers, `r` denotes a
|
| 146 |
value of `X&`, `t` denotes a value of value type `T`, `o` denotes a
|
| 147 |
value of some type that is writable to the output iterator.
|
| 148 |
|
| 149 |
-
[*Note
|
| 150 |
-
`iterator_traits<X>`
|
| 151 |
|
| 152 |
-
###
|
| 153 |
|
| 154 |
-
The
|
| 155 |
-
taxonomy; every iterator
|
| 156 |
-
of requirements specifies operations for dereferencing and
|
| 157 |
-
an iterator. Most algorithms will require additional
|
| 158 |
-
read
|
| 159 |
-
to provide a richer set of iterator movements (
|
| 160 |
-
[[
|
|
|
|
| 161 |
|
| 162 |
-
A type `X`
|
| 163 |
|
| 164 |
-
- `X`
|
| 165 |
-
|
| 166 |
-
lvalues of type `X` are swappable
|
| 167 |
-
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
### Input iterators <a id="input.iterators">[[input.iterators]]</a>
|
| 171 |
-
|
| 172 |
-
A class or pointer type `X` satisfies the requirements of an input
|
| 173 |
-
iterator for the value type `T` if `X` satisfies the `Iterator` (
|
| 174 |
-
[[iterator.iterators]]) and `EqualityComparable` (Table
|
| 175 |
-
[[tab:equalitycomparable]]) requirements and the expressions in Table
|
| 176 |
-
[[tab:iterator.input.requirements]] are valid and have the indicated
|
| 177 |
semantics.
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
|
| 186 |
[*Example 1*: The call `find(a,b,x)` is defined only if the value of
|
| 187 |
`a` has the property *p* defined as follows: `b` has property *p* and a
|
| 188 |
value `i` has property *p* if (`*i==x`) or if (`*i!=x` and `++i` has
|
| 189 |
property *p*). — *end example*]
|
| 190 |
|
| 191 |
[*Note 1*: For input iterators, `a == b` does not imply `++a == ++b`.
|
| 192 |
(Equality does not guarantee the substitution property or referential
|
| 193 |
transparency.) Algorithms on input iterators should never attempt to
|
| 194 |
pass through the same iterator twice. They should be *single pass*
|
| 195 |
-
algorithms. Value type `T` is not required to be a
|
| 196 |
-
(
|
| 197 |
istreams as the source of the input data through the `istream_iterator`
|
| 198 |
class template. — *end note*]
|
| 199 |
|
| 200 |
-
### Output iterators <a id="output.iterators">[[output.iterators]]</a>
|
| 201 |
|
| 202 |
-
A class or pointer type `X`
|
| 203 |
-
|
| 204 |
-
[[
|
| 205 |
-
[[tab:iterator.output.requirements]] are valid and have the indicated
|
| 206 |
semantics.
|
| 207 |
|
| 208 |
[*Note 1*: The only valid use of an `operator*` is on the left side of
|
| 209 |
-
the assignment statement.
|
| 210 |
-
iterator happens only once.
|
| 211 |
-
attempt to pass through the same iterator twice. They should be
|
| 212 |
-
pass
|
| 213 |
-
|
| 214 |
-
destination for placing data through the `ostream_iterator` class as
|
| 215 |
-
well as with insert iterators and insert pointers. — *end note*]
|
| 216 |
|
| 217 |
-
### Forward iterators <a id="forward.iterators">[[forward.iterators]]</a>
|
| 218 |
|
| 219 |
-
A class or pointer type `X`
|
| 220 |
-
|
| 221 |
|
| 222 |
-
- `X`
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
[[utility.arg.requirements]]),
|
| 226 |
- if `X` is a mutable iterator, `reference` is a reference to `T`; if
|
| 227 |
`X` is a constant iterator, `reference` is a reference to `const T`,
|
| 228 |
-
- the expressions in
|
| 229 |
-
|
| 230 |
- objects of type `X` offer the multi-pass guarantee, described below.
|
| 231 |
|
| 232 |
The domain of `==` for forward iterators is that of iterators over the
|
| 233 |
same underlying sequence. However, value-initialized iterators may be
|
| 234 |
compared and shall compare equal to other value-initialized iterators of
|
|
@@ -254,325 +1669,329 @@ If `a` and `b` are equal, then either `a` and `b` are both
|
|
| 254 |
dereferenceable or else neither is dereferenceable.
|
| 255 |
|
| 256 |
If `a` and `b` are both dereferenceable, then `a == b` if and only if
|
| 257 |
`*a` and `*b` are bound to the same object.
|
| 258 |
|
| 259 |
-
### Bidirectional iterators <a id="bidirectional.iterators">[[bidirectional.iterators]]</a>
|
| 260 |
|
| 261 |
-
A class or pointer type `X`
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
|
| 266 |
[*Note 1*: Bidirectional iterators allow algorithms to move iterators
|
| 267 |
backward as well as forward. — *end note*]
|
| 268 |
|
| 269 |
-
### Random access iterators <a id="random.access.iterators">[[random.access.iterators]]</a>
|
| 270 |
|
| 271 |
-
A class or pointer type `X`
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
|
| 276 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 277 |
|
| 278 |
``` cpp
|
| 279 |
namespace std {
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
struct
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
// [iterator.operations], iterator operations
|
| 292 |
-
template <class InputIterator, class Distance>
|
| 293 |
-
constexpr void advance(InputIterator& i, Distance n);
|
| 294 |
-
template <class InputIterator>
|
| 295 |
-
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 296 |
-
distance(InputIterator first, InputIterator last);
|
| 297 |
-
template <class InputIterator>
|
| 298 |
-
constexpr InputIterator next(InputIterator x,
|
| 299 |
-
typename iterator_traits<InputIterator>::difference_type n = 1);
|
| 300 |
-
template <class BidirectionalIterator>
|
| 301 |
-
constexpr BidirectionalIterator prev(BidirectionalIterator x,
|
| 302 |
-
typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
|
| 303 |
-
|
| 304 |
-
// [predef.iterators], predefined iterators
|
| 305 |
-
template <class Iterator> class reverse_iterator;
|
| 306 |
-
|
| 307 |
-
template <class Iterator1, class Iterator2>
|
| 308 |
-
constexpr bool operator==(
|
| 309 |
-
const reverse_iterator<Iterator1>& x,
|
| 310 |
-
const reverse_iterator<Iterator2>& y);
|
| 311 |
-
template <class Iterator1, class Iterator2>
|
| 312 |
-
constexpr bool operator<(
|
| 313 |
-
const reverse_iterator<Iterator1>& x,
|
| 314 |
-
const reverse_iterator<Iterator2>& y);
|
| 315 |
-
template <class Iterator1, class Iterator2>
|
| 316 |
-
constexpr bool operator!=(
|
| 317 |
-
const reverse_iterator<Iterator1>& x,
|
| 318 |
-
const reverse_iterator<Iterator2>& y);
|
| 319 |
-
template <class Iterator1, class Iterator2>
|
| 320 |
-
constexpr bool operator>(
|
| 321 |
-
const reverse_iterator<Iterator1>& x,
|
| 322 |
-
const reverse_iterator<Iterator2>& y);
|
| 323 |
-
template <class Iterator1, class Iterator2>
|
| 324 |
-
constexpr bool operator>=(
|
| 325 |
-
const reverse_iterator<Iterator1>& x,
|
| 326 |
-
const reverse_iterator<Iterator2>& y);
|
| 327 |
-
template <class Iterator1, class Iterator2>
|
| 328 |
-
constexpr bool operator<=(
|
| 329 |
-
const reverse_iterator<Iterator1>& x,
|
| 330 |
-
const reverse_iterator<Iterator2>& y);
|
| 331 |
-
|
| 332 |
-
template <class Iterator1, class Iterator2>
|
| 333 |
-
constexpr auto operator-(
|
| 334 |
-
const reverse_iterator<Iterator1>& x,
|
| 335 |
-
const reverse_iterator<Iterator2>& y) ->decltype(y.base() - x.base());
|
| 336 |
-
template <class Iterator>
|
| 337 |
-
constexpr reverse_iterator<Iterator>
|
| 338 |
-
operator+(
|
| 339 |
-
typename reverse_iterator<Iterator>::difference_type n,
|
| 340 |
-
const reverse_iterator<Iterator>& x);
|
| 341 |
-
|
| 342 |
-
template <class Iterator>
|
| 343 |
-
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 344 |
-
|
| 345 |
-
template <class Container> class back_insert_iterator;
|
| 346 |
-
template <class Container>
|
| 347 |
-
back_insert_iterator<Container> back_inserter(Container& x);
|
| 348 |
-
|
| 349 |
-
template <class Container> class front_insert_iterator;
|
| 350 |
-
template <class Container>
|
| 351 |
-
front_insert_iterator<Container> front_inserter(Container& x);
|
| 352 |
-
|
| 353 |
-
template <class Container> class insert_iterator;
|
| 354 |
-
template <class Container>
|
| 355 |
-
insert_iterator<Container> inserter(Container& x, typename Container::iterator i);
|
| 356 |
-
|
| 357 |
-
template <class Iterator> class move_iterator;
|
| 358 |
-
template <class Iterator1, class Iterator2>
|
| 359 |
-
constexpr bool operator==(
|
| 360 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 361 |
-
template <class Iterator1, class Iterator2>
|
| 362 |
-
constexpr bool operator!=(
|
| 363 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 364 |
-
template <class Iterator1, class Iterator2>
|
| 365 |
-
constexpr bool operator<(
|
| 366 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 367 |
-
template <class Iterator1, class Iterator2>
|
| 368 |
-
constexpr bool operator<=(
|
| 369 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 370 |
-
template <class Iterator1, class Iterator2>
|
| 371 |
-
constexpr bool operator>(
|
| 372 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 373 |
-
template <class Iterator1, class Iterator2>
|
| 374 |
-
constexpr bool operator>=(
|
| 375 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 376 |
-
|
| 377 |
-
template <class Iterator1, class Iterator2>
|
| 378 |
-
constexpr auto operator-(
|
| 379 |
-
const move_iterator<Iterator1>& x,
|
| 380 |
-
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 381 |
-
template <class Iterator>
|
| 382 |
-
constexpr move_iterator<Iterator> operator+(
|
| 383 |
-
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 384 |
-
template <class Iterator>
|
| 385 |
-
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 386 |
-
|
| 387 |
-
// [stream.iterators], stream iterators
|
| 388 |
-
template <class T, class charT = char, class traits = char_traits<charT>,
|
| 389 |
-
class Distance = ptrdiff_t>
|
| 390 |
-
class istream_iterator;
|
| 391 |
-
template <class T, class charT, class traits, class Distance>
|
| 392 |
-
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
| 393 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 394 |
-
template <class T, class charT, class traits, class Distance>
|
| 395 |
-
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
|
| 396 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 397 |
-
|
| 398 |
-
template <class T, class charT = char, class traits = char_traits<charT>>
|
| 399 |
-
class ostream_iterator;
|
| 400 |
-
|
| 401 |
-
template<class charT, class traits = char_traits<charT>>
|
| 402 |
-
class istreambuf_iterator;
|
| 403 |
-
template <class charT, class traits>
|
| 404 |
-
bool operator==(const istreambuf_iterator<charT,traits>& a,
|
| 405 |
-
const istreambuf_iterator<charT,traits>& b);
|
| 406 |
-
template <class charT, class traits>
|
| 407 |
-
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 408 |
-
const istreambuf_iterator<charT,traits>& b);
|
| 409 |
-
|
| 410 |
-
template <class charT, class traits = char_traits<charT>>
|
| 411 |
-
class ostreambuf_iterator;
|
| 412 |
-
|
| 413 |
-
// [iterator.range], range access
|
| 414 |
-
template <class C> constexpr auto begin(C& c) -> decltype(c.begin());
|
| 415 |
-
template <class C> constexpr auto begin(const C& c) -> decltype(c.begin());
|
| 416 |
-
template <class C> constexpr auto end(C& c) -> decltype(c.end());
|
| 417 |
-
template <class C> constexpr auto end(const C& c) -> decltype(c.end());
|
| 418 |
-
template <class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
|
| 419 |
-
template <class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
|
| 420 |
-
template <class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c)))
|
| 421 |
-
-> decltype(std::begin(c));
|
| 422 |
-
template <class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c)))
|
| 423 |
-
-> decltype(std::end(c));
|
| 424 |
-
template <class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin());
|
| 425 |
-
template <class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin());
|
| 426 |
-
template <class C> constexpr auto rend(C& c) -> decltype(c.rend());
|
| 427 |
-
template <class C> constexpr auto rend(const C& c) -> decltype(c.rend());
|
| 428 |
-
template <class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]);
|
| 429 |
-
template <class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]);
|
| 430 |
-
template <class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il);
|
| 431 |
-
template <class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il);
|
| 432 |
-
template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));
|
| 433 |
-
template <class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
|
| 434 |
-
|
| 435 |
-
// [iterator.container], container access
|
| 436 |
-
template <class C> constexpr auto size(const C& c) -> decltype(c.size());
|
| 437 |
-
template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept;
|
| 438 |
-
template <class C> constexpr auto empty(const C& c) -> decltype(c.empty());
|
| 439 |
-
template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept;
|
| 440 |
-
template <class E> constexpr bool empty(initializer_list<E> il) noexcept;
|
| 441 |
-
template <class C> constexpr auto data(C& c) -> decltype(c.data());
|
| 442 |
-
template <class C> constexpr auto data(const C& c) -> decltype(c.data());
|
| 443 |
-
template <class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;
|
| 444 |
-
template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
|
| 445 |
}
|
| 446 |
```
|
| 447 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
## Iterator primitives <a id="iterator.primitives">[[iterator.primitives]]</a>
|
| 449 |
|
| 450 |
-
To simplify the
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
### Iterator traits <a id="iterator.traits">[[iterator.traits]]</a>
|
| 454 |
-
|
| 455 |
-
To implement algorithms only in terms of iterators, it is often
|
| 456 |
-
necessary to determine the value and difference types that correspond to
|
| 457 |
-
a particular iterator type. Accordingly, it is required that if
|
| 458 |
-
`Iterator` is the type of an iterator, the types
|
| 459 |
-
|
| 460 |
-
``` cpp
|
| 461 |
-
iterator_traits<Iterator>::difference_type
|
| 462 |
-
iterator_traits<Iterator>::value_type
|
| 463 |
-
iterator_traits<Iterator>::iterator_category
|
| 464 |
-
```
|
| 465 |
-
|
| 466 |
-
be defined as the iterator’s difference type, value type and iterator
|
| 467 |
-
category, respectively. In addition, the types
|
| 468 |
-
|
| 469 |
-
``` cpp
|
| 470 |
-
iterator_traits<Iterator>::reference
|
| 471 |
-
iterator_traits<Iterator>::pointer
|
| 472 |
-
```
|
| 473 |
-
|
| 474 |
-
shall be defined as the iterator’s reference and pointer types, that is,
|
| 475 |
-
for an iterator object `a`, the same type as the type of `*a` and `a->`,
|
| 476 |
-
respectively. In the case of an output iterator, the types
|
| 477 |
-
|
| 478 |
-
``` cpp
|
| 479 |
-
iterator_traits<Iterator>::difference_type
|
| 480 |
-
iterator_traits<Iterator>::value_type
|
| 481 |
-
iterator_traits<Iterator>::reference
|
| 482 |
-
iterator_traits<Iterator>::pointer
|
| 483 |
-
```
|
| 484 |
-
|
| 485 |
-
may be defined as `void`.
|
| 486 |
-
|
| 487 |
-
If `Iterator` has valid ([[temp.deduct]]) member types
|
| 488 |
-
`difference_type`, `value_type`, `pointer`, `reference`, and
|
| 489 |
-
`iterator_category`, `iterator_traits<Iterator>` shall have the
|
| 490 |
-
following as publicly accessible members:
|
| 491 |
-
|
| 492 |
-
``` cpp
|
| 493 |
-
using difference_type = typename Iterator::difference_type;
|
| 494 |
-
using value_type = typename Iterator::value_type;
|
| 495 |
-
using pointer = typename Iterator::pointer;
|
| 496 |
-
using reference = typename Iterator::reference;
|
| 497 |
-
using iterator_category = typename Iterator::iterator_category;
|
| 498 |
-
```
|
| 499 |
-
|
| 500 |
-
Otherwise, `iterator_traits<Iterator>` shall have no members by any of
|
| 501 |
-
the above names.
|
| 502 |
-
|
| 503 |
-
It is specialized for pointers as
|
| 504 |
-
|
| 505 |
-
``` cpp
|
| 506 |
-
namespace std {
|
| 507 |
-
template<class T> struct iterator_traits<T*> {
|
| 508 |
-
using difference_type = ptrdiff_t;
|
| 509 |
-
using value_type = T;
|
| 510 |
-
using pointer = T*;
|
| 511 |
-
using reference = T&;
|
| 512 |
-
using iterator_category = random_access_iterator_tag;
|
| 513 |
-
};
|
| 514 |
-
}
|
| 515 |
-
```
|
| 516 |
-
|
| 517 |
-
and for pointers to const as
|
| 518 |
-
|
| 519 |
-
``` cpp
|
| 520 |
-
namespace std {
|
| 521 |
-
template<class T> struct iterator_traits<const T*> {
|
| 522 |
-
using difference_type = ptrdiff_t;
|
| 523 |
-
using value_type = T;
|
| 524 |
-
using pointer = const T*;
|
| 525 |
-
using reference = const T&;
|
| 526 |
-
using iterator_category = random_access_iterator_tag;
|
| 527 |
-
};
|
| 528 |
-
}
|
| 529 |
-
```
|
| 530 |
-
|
| 531 |
-
[*Example 1*:
|
| 532 |
-
|
| 533 |
-
To implement a generic `reverse` function, a C++program can do the
|
| 534 |
-
following:
|
| 535 |
-
|
| 536 |
-
``` cpp
|
| 537 |
-
template <class BidirectionalIterator>
|
| 538 |
-
void reverse(BidirectionalIterator first, BidirectionalIterator last) {
|
| 539 |
-
typename iterator_traits<BidirectionalIterator>::difference_type n =
|
| 540 |
-
distance(first, last);
|
| 541 |
-
--n;
|
| 542 |
-
while(n > 0) {
|
| 543 |
-
typename iterator_traits<BidirectionalIterator>::value_type
|
| 544 |
-
tmp = *first;
|
| 545 |
-
*first++ = *--last;
|
| 546 |
-
*last = tmp;
|
| 547 |
-
n -= 2;
|
| 548 |
-
}
|
| 549 |
-
}
|
| 550 |
-
```
|
| 551 |
-
|
| 552 |
-
— *end example*]
|
| 553 |
|
| 554 |
### Standard iterator tags <a id="std.iterator.tags">[[std.iterator.tags]]</a>
|
| 555 |
|
| 556 |
It is often desirable for a function template specialization to find out
|
| 557 |
what is the most specific category of its iterator argument, so that the
|
| 558 |
function can select the most efficient algorithm at compile time. To
|
| 559 |
facilitate this, the library introduces *category tag* classes which are
|
| 560 |
used as compile time tags for algorithm selection. They are:
|
| 561 |
-
`
|
| 562 |
-
`bidirectional_iterator_tag`
|
| 563 |
-
iterator of type `
|
| 564 |
-
`iterator_traits<
|
| 565 |
-
|
|
|
|
|
|
|
| 566 |
|
| 567 |
``` cpp
|
| 568 |
namespace std {
|
| 569 |
-
struct input_iterator_tag { };
|
| 570 |
struct output_iterator_tag { };
|
|
|
|
| 571 |
struct forward_iterator_tag: public input_iterator_tag { };
|
| 572 |
struct bidirectional_iterator_tag: public forward_iterator_tag { };
|
| 573 |
struct random_access_iterator_tag: public bidirectional_iterator_tag { };
|
|
|
|
| 574 |
}
|
| 575 |
```
|
| 576 |
|
| 577 |
[*Example 1*:
|
| 578 |
|
|
@@ -592,11 +2011,11 @@ template<class T> struct iterator_traits<BinaryTreeIterator<T>> {
|
|
| 592 |
|
| 593 |
— *end example*]
|
| 594 |
|
| 595 |
[*Example 2*:
|
| 596 |
|
| 597 |
-
If `evolve()` is well
|
| 598 |
implemented more efficiently for random access iterators, then the
|
| 599 |
implementation is as follows:
|
| 600 |
|
| 601 |
``` cpp
|
| 602 |
template<class BidirectionalIterator>
|
|
@@ -632,31 +2051,29 @@ iterators they use `++` to provide linear time implementations.
|
|
| 632 |
``` cpp
|
| 633 |
template<class InputIterator, class Distance>
|
| 634 |
constexpr void advance(InputIterator& i, Distance n);
|
| 635 |
```
|
| 636 |
|
| 637 |
-
*
|
| 638 |
-
access iterators.
|
| 639 |
|
| 640 |
-
*Effects:* Increments
|
| 641 |
-
|
| 642 |
|
| 643 |
``` cpp
|
| 644 |
template<class InputIterator>
|
| 645 |
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 646 |
distance(InputIterator first, InputIterator last);
|
| 647 |
```
|
| 648 |
|
| 649 |
-
*
|
| 650 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 651 |
increments needed to get from `first` to `last`.
|
| 652 |
|
| 653 |
-
*Requires:* If `InputIterator` meets the requirements of random access
|
| 654 |
-
iterator, `last` shall be reachable from `first` or `first` shall be
|
| 655 |
-
reachable from `last`; otherwise, `last` shall be reachable from
|
| 656 |
-
`first`.
|
| 657 |
-
|
| 658 |
``` cpp
|
| 659 |
template<class InputIterator>
|
| 660 |
constexpr InputIterator next(InputIterator x,
|
| 661 |
typename iterator_traits<InputIterator>::difference_type n = 1);
|
| 662 |
```
|
|
@@ -669,42 +2086,224 @@ template <class BidirectionalIterator>
|
|
| 669 |
typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
|
| 670 |
```
|
| 671 |
|
| 672 |
*Effects:* Equivalent to: `advance(x, -n); return x;`
|
| 673 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 674 |
## Iterator adaptors <a id="predef.iterators">[[predef.iterators]]</a>
|
| 675 |
|
| 676 |
### Reverse iterators <a id="reverse.iterators">[[reverse.iterators]]</a>
|
| 677 |
|
| 678 |
Class template `reverse_iterator` is an iterator adaptor that iterates
|
| 679 |
from the end of the sequence defined by its underlying iterator to the
|
| 680 |
-
beginning of that sequence.
|
| 681 |
-
iterator and its corresponding iterator `i` is established by the
|
| 682 |
-
identity: `&*(reverse_iterator(i)) == &*(i - 1)`.
|
| 683 |
|
| 684 |
#### Class template `reverse_iterator` <a id="reverse.iterator">[[reverse.iterator]]</a>
|
| 685 |
|
| 686 |
``` cpp
|
| 687 |
namespace std {
|
| 688 |
template<class Iterator>
|
| 689 |
class reverse_iterator {
|
| 690 |
public:
|
| 691 |
using iterator_type = Iterator;
|
| 692 |
-
using
|
| 693 |
-
using
|
| 694 |
-
using
|
|
|
|
| 695 |
using pointer = typename iterator_traits<Iterator>::pointer;
|
| 696 |
-
using reference =
|
| 697 |
|
| 698 |
constexpr reverse_iterator();
|
| 699 |
constexpr explicit reverse_iterator(Iterator x);
|
| 700 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 701 |
template<class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
|
| 702 |
|
| 703 |
-
constexpr Iterator base() const;
|
| 704 |
constexpr reference operator*() const;
|
| 705 |
-
constexpr pointer operator->() const;
|
| 706 |
|
| 707 |
constexpr reverse_iterator& operator++();
|
| 708 |
constexpr reverse_iterator operator++(int);
|
| 709 |
constexpr reverse_iterator& operator--();
|
| 710 |
constexpr reverse_iterator operator--(int);
|
|
@@ -712,72 +2311,60 @@ namespace std {
|
|
| 712 |
constexpr reverse_iterator operator+ (difference_type n) const;
|
| 713 |
constexpr reverse_iterator& operator+=(difference_type n);
|
| 714 |
constexpr reverse_iterator operator- (difference_type n) const;
|
| 715 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 716 |
constexpr unspecified operator[](difference_type n) const;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 717 |
protected:
|
| 718 |
Iterator current;
|
| 719 |
};
|
| 720 |
-
|
| 721 |
-
template <class Iterator1, class Iterator2>
|
| 722 |
-
constexpr bool operator==(
|
| 723 |
-
const reverse_iterator<Iterator1>& x,
|
| 724 |
-
const reverse_iterator<Iterator2>& y);
|
| 725 |
-
template <class Iterator1, class Iterator2>
|
| 726 |
-
constexpr bool operator<(
|
| 727 |
-
const reverse_iterator<Iterator1>& x,
|
| 728 |
-
const reverse_iterator<Iterator2>& y);
|
| 729 |
-
template <class Iterator1, class Iterator2>
|
| 730 |
-
constexpr bool operator!=(
|
| 731 |
-
const reverse_iterator<Iterator1>& x,
|
| 732 |
-
const reverse_iterator<Iterator2>& y);
|
| 733 |
-
template <class Iterator1, class Iterator2>
|
| 734 |
-
constexpr bool operator>(
|
| 735 |
-
const reverse_iterator<Iterator1>& x,
|
| 736 |
-
const reverse_iterator<Iterator2>& y);
|
| 737 |
-
template <class Iterator1, class Iterator2>
|
| 738 |
-
constexpr bool operator>=(
|
| 739 |
-
const reverse_iterator<Iterator1>& x,
|
| 740 |
-
const reverse_iterator<Iterator2>& y);
|
| 741 |
-
template <class Iterator1, class Iterator2>
|
| 742 |
-
constexpr bool operator<=(
|
| 743 |
-
const reverse_iterator<Iterator1>& x,
|
| 744 |
-
const reverse_iterator<Iterator2>& y);
|
| 745 |
-
template <class Iterator1, class Iterator2>
|
| 746 |
-
constexpr auto operator-(
|
| 747 |
-
const reverse_iterator<Iterator1>& x,
|
| 748 |
-
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 749 |
-
template <class Iterator>
|
| 750 |
-
constexpr reverse_iterator<Iterator> operator+(
|
| 751 |
-
typename reverse_iterator<Iterator>::difference_type n,
|
| 752 |
-
const reverse_iterator<Iterator>& x);
|
| 753 |
-
|
| 754 |
-
template <class Iterator>
|
| 755 |
-
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 756 |
}
|
| 757 |
```
|
| 758 |
|
| 759 |
-
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
`
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 779 |
|
| 780 |
``` cpp
|
| 781 |
constexpr reverse_iterator();
|
| 782 |
```
|
| 783 |
|
|
@@ -796,31 +2383,29 @@ constexpr explicit reverse_iterator(Iterator x);
|
|
| 796 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 797 |
```
|
| 798 |
|
| 799 |
*Effects:* Initializes `current` with `u.current`.
|
| 800 |
|
| 801 |
-
##### `reverse_iterator::operator=` <a id="reverse.iter.op=">[[reverse.iter.op=]]</a>
|
| 802 |
-
|
| 803 |
``` cpp
|
| 804 |
template<class U>
|
| 805 |
constexpr reverse_iterator&
|
| 806 |
operator=(const reverse_iterator<U>& u);
|
| 807 |
```
|
| 808 |
|
| 809 |
-
*Effects:* Assigns `u.base()` to current.
|
| 810 |
|
| 811 |
*Returns:* `*this`.
|
| 812 |
|
| 813 |
-
####
|
| 814 |
|
| 815 |
``` cpp
|
| 816 |
constexpr Iterator base() const; // explicit
|
| 817 |
```
|
| 818 |
|
| 819 |
*Returns:* `current`.
|
| 820 |
|
| 821 |
-
####
|
| 822 |
|
| 823 |
``` cpp
|
| 824 |
constexpr reference operator*() const;
|
| 825 |
```
|
| 826 |
|
|
@@ -829,195 +2414,245 @@ constexpr reference operator*() const;
|
|
| 829 |
``` cpp
|
| 830 |
Iterator tmp = current;
|
| 831 |
return *--tmp;
|
| 832 |
```
|
| 833 |
|
| 834 |
-
##### `operator->` <a id="reverse.iter.opref">[[reverse.iter.opref]]</a>
|
| 835 |
-
|
| 836 |
-
``` cpp
|
| 837 |
-
constexpr pointer operator->() const;
|
| 838 |
-
```
|
| 839 |
-
|
| 840 |
-
*Returns:* `addressof(operator*())`.
|
| 841 |
-
|
| 842 |
-
##### `operator++` <a id="reverse.iter.op++">[[reverse.iter.op++]]</a>
|
| 843 |
-
|
| 844 |
-
``` cpp
|
| 845 |
-
constexpr reverse_iterator& operator++();
|
| 846 |
-
```
|
| 847 |
-
|
| 848 |
-
*Effects:* As if by: `current;`
|
| 849 |
-
|
| 850 |
-
*Returns:* `*this`.
|
| 851 |
-
|
| 852 |
``` cpp
|
| 853 |
-
constexpr
|
|
|
|
|
|
|
| 854 |
```
|
| 855 |
|
| 856 |
-
*Effects:*
|
| 857 |
|
| 858 |
-
``
|
| 859 |
-
|
| 860 |
-
-
|
| 861 |
-
return tmp;
|
| 862 |
-
```
|
| 863 |
-
|
| 864 |
-
\[reverse.iter.op\]`operator\dcr`
|
| 865 |
|
| 866 |
``` cpp
|
| 867 |
-
constexpr
|
| 868 |
```
|
| 869 |
|
| 870 |
-
*
|
| 871 |
-
|
| 872 |
-
*Returns:* `*this`.
|
| 873 |
-
|
| 874 |
-
``` cpp
|
| 875 |
-
constexpr reverse_iterator operator--(int);
|
| 876 |
-
```
|
| 877 |
-
|
| 878 |
-
*Effects:* As if by:
|
| 879 |
-
|
| 880 |
-
``` cpp
|
| 881 |
-
reverse_iterator tmp = *this;
|
| 882 |
-
++current;
|
| 883 |
-
return tmp;
|
| 884 |
-
```
|
| 885 |
|
| 886 |
-
####
|
| 887 |
|
| 888 |
``` cpp
|
| 889 |
constexpr reverse_iterator operator+(difference_type n) const;
|
| 890 |
```
|
| 891 |
|
| 892 |
*Returns:* `reverse_iterator(current-n)`.
|
| 893 |
|
| 894 |
-
##### `operator+=` <a id="reverse.iter.op+=">[[reverse.iter.op+=]]</a>
|
| 895 |
-
|
| 896 |
-
``` cpp
|
| 897 |
-
constexpr reverse_iterator& operator+=(difference_type n);
|
| 898 |
-
```
|
| 899 |
-
|
| 900 |
-
*Effects:* As if by: `current -= n;`
|
| 901 |
-
|
| 902 |
-
*Returns:* `*this`.
|
| 903 |
-
|
| 904 |
-
##### `operator-` <a id="reverse.iter.op-">[[reverse.iter.op-]]</a>
|
| 905 |
-
|
| 906 |
``` cpp
|
| 907 |
constexpr reverse_iterator operator-(difference_type n) const;
|
| 908 |
```
|
| 909 |
|
| 910 |
*Returns:* `reverse_iterator(current+n)`.
|
| 911 |
|
| 912 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 913 |
|
| 914 |
``` cpp
|
| 915 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 916 |
```
|
| 917 |
|
| 918 |
*Effects:* As if by: `current += n;`
|
| 919 |
|
| 920 |
*Returns:* `*this`.
|
| 921 |
|
| 922 |
-
####
|
| 923 |
-
|
| 924 |
-
``` cpp
|
| 925 |
-
constexpr unspecified operator[](difference_type n) const;
|
| 926 |
-
```
|
| 927 |
-
|
| 928 |
-
*Returns:* `current[-n-1]`.
|
| 929 |
-
|
| 930 |
-
##### `operator==` <a id="reverse.iter.op==">[[reverse.iter.op==]]</a>
|
| 931 |
|
| 932 |
``` cpp
|
| 933 |
template<class Iterator1, class Iterator2>
|
| 934 |
constexpr bool operator==(
|
| 935 |
const reverse_iterator<Iterator1>& x,
|
| 936 |
const reverse_iterator<Iterator2>& y);
|
| 937 |
```
|
| 938 |
|
| 939 |
-
*
|
|
|
|
| 940 |
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
``` cpp
|
| 944 |
-
template <class Iterator1, class Iterator2>
|
| 945 |
-
constexpr bool operator<(
|
| 946 |
-
const reverse_iterator<Iterator1>& x,
|
| 947 |
-
const reverse_iterator<Iterator2>& y);
|
| 948 |
-
```
|
| 949 |
-
|
| 950 |
-
*Returns:* `x.current > y.current`.
|
| 951 |
-
|
| 952 |
-
##### `operator!=` <a id="reverse.iter.op!=">[[reverse.iter.op!=]]</a>
|
| 953 |
|
| 954 |
``` cpp
|
| 955 |
template<class Iterator1, class Iterator2>
|
| 956 |
constexpr bool operator!=(
|
| 957 |
const reverse_iterator<Iterator1>& x,
|
| 958 |
const reverse_iterator<Iterator2>& y);
|
| 959 |
```
|
| 960 |
|
| 961 |
-
*
|
|
|
|
| 962 |
|
| 963 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
|
| 965 |
``` cpp
|
| 966 |
template<class Iterator1, class Iterator2>
|
| 967 |
constexpr bool operator>(
|
| 968 |
const reverse_iterator<Iterator1>& x,
|
| 969 |
const reverse_iterator<Iterator2>& y);
|
| 970 |
```
|
| 971 |
|
| 972 |
-
*
|
|
|
|
| 973 |
|
| 974 |
-
|
| 975 |
-
|
| 976 |
-
``` cpp
|
| 977 |
-
template <class Iterator1, class Iterator2>
|
| 978 |
-
constexpr bool operator>=(
|
| 979 |
-
const reverse_iterator<Iterator1>& x,
|
| 980 |
-
const reverse_iterator<Iterator2>& y);
|
| 981 |
-
```
|
| 982 |
-
|
| 983 |
-
*Returns:* `x.current <= y.current`.
|
| 984 |
-
|
| 985 |
-
##### `operator<=` <a id="reverse.iter.op<=">[[reverse.iter.op<=]]</a>
|
| 986 |
|
| 987 |
``` cpp
|
| 988 |
template<class Iterator1, class Iterator2>
|
| 989 |
constexpr bool operator<=(
|
| 990 |
const reverse_iterator<Iterator1>& x,
|
| 991 |
const reverse_iterator<Iterator2>& y);
|
| 992 |
```
|
| 993 |
|
| 994 |
-
*
|
|
|
|
| 995 |
|
| 996 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 997 |
|
| 998 |
``` cpp
|
| 999 |
template<class Iterator1, class Iterator2>
|
| 1000 |
constexpr auto operator-(
|
| 1001 |
const reverse_iterator<Iterator1>& x,
|
| 1002 |
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 1003 |
```
|
| 1004 |
|
| 1005 |
-
*Returns:* `y.
|
| 1006 |
-
|
| 1007 |
-
##### `operator+` <a id="reverse.iter.opsum">[[reverse.iter.opsum]]</a>
|
| 1008 |
|
| 1009 |
``` cpp
|
| 1010 |
template<class Iterator>
|
| 1011 |
constexpr reverse_iterator<Iterator> operator+(
|
| 1012 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 1013 |
const reverse_iterator<Iterator>& x);
|
| 1014 |
```
|
| 1015 |
|
| 1016 |
-
*Returns:* `reverse_iterator<Iterator>
|
| 1017 |
|
| 1018 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1019 |
|
| 1020 |
``` cpp
|
| 1021 |
template<class Iterator>
|
| 1022 |
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 1023 |
```
|
|
@@ -1040,16 +2675,16 @@ insert corresponding elements into the container. This device allows all
|
|
| 1040 |
of the copying algorithms in the library to work in the *insert mode*
|
| 1041 |
instead of the *regular overwrite* mode.
|
| 1042 |
|
| 1043 |
An insert iterator is constructed from a container and possibly one of
|
| 1044 |
its iterators pointing to where insertion takes place if it is neither
|
| 1045 |
-
at the beginning nor at the end of the container. Insert iterators
|
| 1046 |
-
|
| 1047 |
-
|
| 1048 |
-
|
| 1049 |
-
|
| 1050 |
-
|
| 1051 |
insertion takes place. `back_insert_iterator` inserts elements at the
|
| 1052 |
end of a container, `front_insert_iterator` inserts elements at the
|
| 1053 |
beginning of a container, and `insert_iterator` inserts elements where
|
| 1054 |
the iterator points to in a container. `back_inserter`,
|
| 1055 |
`front_inserter`, and `inserter` are three functions making the insert
|
|
@@ -1060,84 +2695,74 @@ iterators out of a container.
|
|
| 1060 |
``` cpp
|
| 1061 |
namespace std {
|
| 1062 |
template<class Container>
|
| 1063 |
class back_insert_iterator {
|
| 1064 |
protected:
|
| 1065 |
-
Container* container;
|
| 1066 |
|
| 1067 |
public:
|
| 1068 |
using iterator_category = output_iterator_tag;
|
| 1069 |
using value_type = void;
|
| 1070 |
-
using difference_type =
|
| 1071 |
using pointer = void;
|
| 1072 |
using reference = void;
|
| 1073 |
using container_type = Container;
|
| 1074 |
|
| 1075 |
-
|
| 1076 |
-
|
| 1077 |
-
back_insert_iterator& operator=(typename Container::value_type&
|
|
|
|
| 1078 |
|
| 1079 |
-
back_insert_iterator& operator*();
|
| 1080 |
-
back_insert_iterator& operator++();
|
| 1081 |
-
back_insert_iterator operator++(int);
|
| 1082 |
};
|
| 1083 |
-
|
| 1084 |
-
template <class Container>
|
| 1085 |
-
back_insert_iterator<Container> back_inserter(Container& x);
|
| 1086 |
}
|
| 1087 |
```
|
| 1088 |
|
| 1089 |
-
####
|
| 1090 |
-
|
| 1091 |
-
##### `back_insert_iterator` constructor <a id="back.insert.iter.cons">[[back.insert.iter.cons]]</a>
|
| 1092 |
|
| 1093 |
``` cpp
|
| 1094 |
-
explicit back_insert_iterator(Container& x);
|
| 1095 |
```
|
| 1096 |
|
| 1097 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 1098 |
|
| 1099 |
-
##### `back_insert_iterator::operator=` <a id="back.insert.iter.op=">[[back.insert.iter.op=]]</a>
|
| 1100 |
-
|
| 1101 |
``` cpp
|
| 1102 |
-
back_insert_iterator& operator=(const typename Container::value_type& value);
|
| 1103 |
```
|
| 1104 |
|
| 1105 |
*Effects:* As if by: `container->push_back(value);`
|
| 1106 |
|
| 1107 |
*Returns:* `*this`.
|
| 1108 |
|
| 1109 |
``` cpp
|
| 1110 |
-
back_insert_iterator& operator=(typename Container::value_type&& value);
|
| 1111 |
```
|
| 1112 |
|
| 1113 |
*Effects:* As if by: `container->push_back(std::move(value));`
|
| 1114 |
|
| 1115 |
*Returns:* `*this`.
|
| 1116 |
|
| 1117 |
-
##### `back_insert_iterator::operator*` <a id="back.insert.iter.op*">[[back.insert.iter.op*]]</a>
|
| 1118 |
-
|
| 1119 |
``` cpp
|
| 1120 |
-
back_insert_iterator& operator*();
|
| 1121 |
```
|
| 1122 |
|
| 1123 |
*Returns:* `*this`.
|
| 1124 |
|
| 1125 |
-
##### `back_insert_iterator::operator++` <a id="back.insert.iter.op++">[[back.insert.iter.op++]]</a>
|
| 1126 |
-
|
| 1127 |
``` cpp
|
| 1128 |
-
back_insert_iterator& operator++();
|
| 1129 |
-
back_insert_iterator operator++(int);
|
| 1130 |
```
|
| 1131 |
|
| 1132 |
*Returns:* `*this`.
|
| 1133 |
|
| 1134 |
##### `back_inserter` <a id="back.inserter">[[back.inserter]]</a>
|
| 1135 |
|
| 1136 |
``` cpp
|
| 1137 |
template<class Container>
|
| 1138 |
-
back_insert_iterator<Container> back_inserter(Container& x);
|
| 1139 |
```
|
| 1140 |
|
| 1141 |
*Returns:* `back_insert_iterator<Container>(x)`.
|
| 1142 |
|
| 1143 |
#### Class template `front_insert_iterator` <a id="front.insert.iterator">[[front.insert.iterator]]</a>
|
|
@@ -1145,84 +2770,74 @@ template <class Container>
|
|
| 1145 |
``` cpp
|
| 1146 |
namespace std {
|
| 1147 |
template<class Container>
|
| 1148 |
class front_insert_iterator {
|
| 1149 |
protected:
|
| 1150 |
-
Container* container;
|
| 1151 |
|
| 1152 |
public:
|
| 1153 |
using iterator_category = output_iterator_tag;
|
| 1154 |
using value_type = void;
|
| 1155 |
-
using difference_type =
|
| 1156 |
using pointer = void;
|
| 1157 |
using reference = void;
|
| 1158 |
using container_type = Container;
|
| 1159 |
|
| 1160 |
-
|
| 1161 |
-
|
| 1162 |
-
front_insert_iterator& operator=(typename Container::value_type&
|
|
|
|
| 1163 |
|
| 1164 |
-
front_insert_iterator& operator*();
|
| 1165 |
-
front_insert_iterator& operator++();
|
| 1166 |
-
front_insert_iterator operator++(int);
|
| 1167 |
};
|
| 1168 |
-
|
| 1169 |
-
template <class Container>
|
| 1170 |
-
front_insert_iterator<Container> front_inserter(Container& x);
|
| 1171 |
}
|
| 1172 |
```
|
| 1173 |
|
| 1174 |
-
####
|
| 1175 |
-
|
| 1176 |
-
##### `front_insert_iterator` constructor <a id="front.insert.iter.cons">[[front.insert.iter.cons]]</a>
|
| 1177 |
|
| 1178 |
``` cpp
|
| 1179 |
-
explicit front_insert_iterator(Container& x);
|
| 1180 |
```
|
| 1181 |
|
| 1182 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 1183 |
|
| 1184 |
-
##### `front_insert_iterator::operator=` <a id="front.insert.iter.op=">[[front.insert.iter.op=]]</a>
|
| 1185 |
-
|
| 1186 |
``` cpp
|
| 1187 |
-
front_insert_iterator& operator=(const typename Container::value_type& value);
|
| 1188 |
```
|
| 1189 |
|
| 1190 |
*Effects:* As if by: `container->push_front(value);`
|
| 1191 |
|
| 1192 |
*Returns:* `*this`.
|
| 1193 |
|
| 1194 |
``` cpp
|
| 1195 |
-
front_insert_iterator& operator=(typename Container::value_type&& value);
|
| 1196 |
```
|
| 1197 |
|
| 1198 |
*Effects:* As if by: `container->push_front(std::move(value));`
|
| 1199 |
|
| 1200 |
*Returns:* `*this`.
|
| 1201 |
|
| 1202 |
-
##### `front_insert_iterator::operator*` <a id="front.insert.iter.op*">[[front.insert.iter.op*]]</a>
|
| 1203 |
-
|
| 1204 |
``` cpp
|
| 1205 |
-
front_insert_iterator& operator*();
|
| 1206 |
```
|
| 1207 |
|
| 1208 |
*Returns:* `*this`.
|
| 1209 |
|
| 1210 |
-
##### `front_insert_iterator::operator++` <a id="front.insert.iter.op++">[[front.insert.iter.op++]]</a>
|
| 1211 |
-
|
| 1212 |
``` cpp
|
| 1213 |
-
front_insert_iterator& operator++();
|
| 1214 |
-
front_insert_iterator operator++(int);
|
| 1215 |
```
|
| 1216 |
|
| 1217 |
*Returns:* `*this`.
|
| 1218 |
|
| 1219 |
##### `front_inserter` <a id="front.inserter">[[front.inserter]]</a>
|
| 1220 |
|
| 1221 |
``` cpp
|
| 1222 |
template<class Container>
|
| 1223 |
-
front_insert_iterator<Container> front_inserter(Container& x);
|
| 1224 |
```
|
| 1225 |
|
| 1226 |
*Returns:* `front_insert_iterator<Container>(x)`.
|
| 1227 |
|
| 1228 |
#### Class template `insert_iterator` <a id="insert.iterator">[[insert.iterator]]</a>
|
|
@@ -1230,50 +2845,44 @@ template <class Container>
|
|
| 1230 |
``` cpp
|
| 1231 |
namespace std {
|
| 1232 |
template<class Container>
|
| 1233 |
class insert_iterator {
|
| 1234 |
protected:
|
| 1235 |
-
Container* container;
|
| 1236 |
-
|
| 1237 |
|
| 1238 |
public:
|
| 1239 |
using iterator_category = output_iterator_tag;
|
| 1240 |
using value_type = void;
|
| 1241 |
-
using difference_type =
|
| 1242 |
using pointer = void;
|
| 1243 |
using reference = void;
|
| 1244 |
using container_type = Container;
|
| 1245 |
|
| 1246 |
-
insert_iterator(
|
| 1247 |
-
insert_iterator&
|
| 1248 |
-
insert_iterator& operator=(typename Container::value_type&
|
|
|
|
| 1249 |
|
| 1250 |
-
insert_iterator& operator*();
|
| 1251 |
-
insert_iterator& operator++();
|
| 1252 |
-
insert_iterator& operator++(int);
|
| 1253 |
};
|
| 1254 |
-
|
| 1255 |
-
template <class Container>
|
| 1256 |
-
insert_iterator<Container> inserter(Container& x, typename Container::iterator i);
|
| 1257 |
}
|
| 1258 |
```
|
| 1259 |
|
| 1260 |
-
####
|
| 1261 |
-
|
| 1262 |
-
##### `insert_iterator` constructor <a id="insert.iter.cons">[[insert.iter.cons]]</a>
|
| 1263 |
|
| 1264 |
``` cpp
|
| 1265 |
-
insert_iterator(Container& x,
|
| 1266 |
```
|
| 1267 |
|
| 1268 |
*Effects:* Initializes `container` with `addressof(x)` and `iter` with
|
| 1269 |
`i`.
|
| 1270 |
|
| 1271 |
-
##### `insert_iterator::operator=` <a id="insert.iter.op=">[[insert.iter.op=]]</a>
|
| 1272 |
-
|
| 1273 |
``` cpp
|
| 1274 |
-
insert_iterator& operator=(const typename Container::value_type& value);
|
| 1275 |
```
|
| 1276 |
|
| 1277 |
*Effects:* As if by:
|
| 1278 |
|
| 1279 |
``` cpp
|
|
@@ -1282,11 +2891,11 @@ iter = container->insert(iter, value);
|
|
| 1282 |
```
|
| 1283 |
|
| 1284 |
*Returns:* `*this`.
|
| 1285 |
|
| 1286 |
``` cpp
|
| 1287 |
-
insert_iterator& operator=(typename Container::value_type&& value);
|
| 1288 |
```
|
| 1289 |
|
| 1290 |
*Effects:* As if by:
|
| 1291 |
|
| 1292 |
``` cpp
|
|
@@ -1294,37 +2903,34 @@ iter = container->insert(iter, std::move(value));
|
|
| 1294 |
++iter;
|
| 1295 |
```
|
| 1296 |
|
| 1297 |
*Returns:* `*this`.
|
| 1298 |
|
| 1299 |
-
##### `insert_iterator::operator*` <a id="insert.iter.op*">[[insert.iter.op*]]</a>
|
| 1300 |
-
|
| 1301 |
``` cpp
|
| 1302 |
-
insert_iterator& operator*();
|
| 1303 |
```
|
| 1304 |
|
| 1305 |
*Returns:* `*this`.
|
| 1306 |
|
| 1307 |
-
##### `insert_iterator::operator++` <a id="insert.iter.op++">[[insert.iter.op++]]</a>
|
| 1308 |
-
|
| 1309 |
``` cpp
|
| 1310 |
-
insert_iterator& operator++();
|
| 1311 |
-
insert_iterator& operator++(int);
|
| 1312 |
```
|
| 1313 |
|
| 1314 |
*Returns:* `*this`.
|
| 1315 |
|
| 1316 |
##### `inserter` <a id="inserter">[[inserter]]</a>
|
| 1317 |
|
| 1318 |
``` cpp
|
| 1319 |
template<class Container>
|
| 1320 |
-
insert_iterator<Container>
|
|
|
|
| 1321 |
```
|
| 1322 |
|
| 1323 |
*Returns:* `insert_iterator<Container>(x, i)`.
|
| 1324 |
|
| 1325 |
-
### Move iterators <a id="move.iterators">[[move.iterators]]</a>
|
| 1326 |
|
| 1327 |
Class template `move_iterator` is an iterator adaptor with the same
|
| 1328 |
behavior as the underlying iterator except that its indirection operator
|
| 1329 |
implicitly converts the value returned by the underlying iterator’s
|
| 1330 |
indirection operator to an rvalue. Some generic algorithms can be called
|
|
@@ -1348,89 +2954,82 @@ vector<string> v2(make_move_iterator(s.begin()),
|
|
| 1348 |
namespace std {
|
| 1349 |
template<class Iterator>
|
| 1350 |
class move_iterator {
|
| 1351 |
public:
|
| 1352 |
using iterator_type = Iterator;
|
| 1353 |
-
using
|
| 1354 |
-
using
|
| 1355 |
-
using
|
|
|
|
| 1356 |
using pointer = Iterator;
|
| 1357 |
-
using reference =
|
| 1358 |
|
| 1359 |
constexpr move_iterator();
|
| 1360 |
constexpr explicit move_iterator(Iterator i);
|
| 1361 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 1362 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 1363 |
|
| 1364 |
-
constexpr iterator_type base() const;
|
|
|
|
| 1365 |
constexpr reference operator*() const;
|
| 1366 |
-
constexpr pointer operator->() const;
|
| 1367 |
|
| 1368 |
constexpr move_iterator& operator++();
|
| 1369 |
-
constexpr
|
| 1370 |
constexpr move_iterator& operator--();
|
| 1371 |
constexpr move_iterator operator--(int);
|
| 1372 |
|
| 1373 |
constexpr move_iterator operator+(difference_type n) const;
|
| 1374 |
constexpr move_iterator& operator+=(difference_type n);
|
| 1375 |
constexpr move_iterator operator-(difference_type n) const;
|
| 1376 |
constexpr move_iterator& operator-=(difference_type n);
|
| 1377 |
-
constexpr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1378 |
|
| 1379 |
private:
|
| 1380 |
Iterator current; // exposition only
|
| 1381 |
};
|
| 1382 |
-
|
| 1383 |
-
template <class Iterator1, class Iterator2>
|
| 1384 |
-
constexpr bool operator==(
|
| 1385 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1386 |
-
template <class Iterator1, class Iterator2>
|
| 1387 |
-
constexpr bool operator!=(
|
| 1388 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1389 |
-
template <class Iterator1, class Iterator2>
|
| 1390 |
-
constexpr bool operator<(
|
| 1391 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1392 |
-
template <class Iterator1, class Iterator2>
|
| 1393 |
-
constexpr bool operator<=(
|
| 1394 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1395 |
-
template <class Iterator1, class Iterator2>
|
| 1396 |
-
constexpr bool operator>(
|
| 1397 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1398 |
-
template <class Iterator1, class Iterator2>
|
| 1399 |
-
constexpr bool operator>=(
|
| 1400 |
-
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1401 |
-
|
| 1402 |
-
template <class Iterator1, class Iterator2>
|
| 1403 |
-
constexpr auto operator-(
|
| 1404 |
-
const move_iterator<Iterator1>& x,
|
| 1405 |
-
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 1406 |
-
template <class Iterator>
|
| 1407 |
-
constexpr move_iterator<Iterator> operator+(
|
| 1408 |
-
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 1409 |
-
template <class Iterator>
|
| 1410 |
-
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 1411 |
}
|
| 1412 |
```
|
| 1413 |
|
| 1414 |
-
|
| 1415 |
-
`is_reference_v<R>` is `true`, the template specialization
|
| 1416 |
-
`move_iterator<Iterator>` shall define the nested type named `reference`
|
| 1417 |
-
as a synonym for `remove_reference_t<R>&&`, otherwise as a synonym for
|
| 1418 |
-
`R`.
|
| 1419 |
|
| 1420 |
-
|
|
|
|
|
|
|
|
|
|
| 1421 |
|
| 1422 |
-
|
| 1423 |
-
input iterator ([[input.iterators]]). Additionally, if any of the
|
| 1424 |
-
bidirectional or random access traversal functions are instantiated, the
|
| 1425 |
-
template parameter shall meet the requirements for a Bidirectional
|
| 1426 |
-
Iterator ([[bidirectional.iterators]]) or a Random Access Iterator (
|
| 1427 |
-
[[random.access.iterators]]), respectively.
|
| 1428 |
|
| 1429 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1430 |
|
| 1431 |
-
####
|
| 1432 |
|
| 1433 |
``` cpp
|
| 1434 |
constexpr move_iterator();
|
| 1435 |
```
|
| 1436 |
|
|
@@ -1442,78 +3041,84 @@ value-initialized iterator of type `Iterator`.
|
|
| 1442 |
``` cpp
|
| 1443 |
constexpr explicit move_iterator(Iterator i);
|
| 1444 |
```
|
| 1445 |
|
| 1446 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 1447 |
-
`i`.
|
| 1448 |
|
| 1449 |
``` cpp
|
| 1450 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 1451 |
```
|
| 1452 |
|
|
|
|
|
|
|
| 1453 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 1454 |
`u.base()`.
|
| 1455 |
|
| 1456 |
-
*Requires:* `U` shall be convertible to `Iterator`.
|
| 1457 |
-
|
| 1458 |
-
##### `move_iterator::operator=` <a id="move.iter.op=">[[move.iter.op=]]</a>
|
| 1459 |
-
|
| 1460 |
``` cpp
|
| 1461 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 1462 |
```
|
| 1463 |
|
|
|
|
|
|
|
| 1464 |
*Effects:* Assigns `u.base()` to `current`.
|
| 1465 |
|
| 1466 |
-
|
| 1467 |
-
|
| 1468 |
-
##### `move_iterator` conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
|
| 1469 |
|
| 1470 |
``` cpp
|
| 1471 |
-
constexpr Iterator base() const;
|
| 1472 |
```
|
| 1473 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1474 |
*Returns:* `current`.
|
| 1475 |
|
| 1476 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1477 |
|
| 1478 |
``` cpp
|
| 1479 |
constexpr reference operator*() const;
|
| 1480 |
```
|
| 1481 |
|
| 1482 |
-
*
|
| 1483 |
-
|
| 1484 |
-
##### `move_iterator::operator->` <a id="move.iter.op.ref">[[move.iter.op.ref]]</a>
|
| 1485 |
|
| 1486 |
``` cpp
|
| 1487 |
-
constexpr
|
| 1488 |
```
|
| 1489 |
|
| 1490 |
-
*
|
| 1491 |
|
| 1492 |
-
####
|
| 1493 |
|
| 1494 |
``` cpp
|
| 1495 |
constexpr move_iterator& operator++();
|
| 1496 |
```
|
| 1497 |
|
| 1498 |
*Effects:* As if by `++current`.
|
| 1499 |
|
| 1500 |
*Returns:* `*this`.
|
| 1501 |
|
| 1502 |
``` cpp
|
| 1503 |
-
constexpr
|
| 1504 |
```
|
| 1505 |
|
| 1506 |
-
*Effects:*
|
| 1507 |
|
| 1508 |
``` cpp
|
| 1509 |
move_iterator tmp = *this;
|
| 1510 |
++current;
|
| 1511 |
return tmp;
|
| 1512 |
```
|
| 1513 |
|
| 1514 |
-
|
| 1515 |
|
| 1516 |
``` cpp
|
| 1517 |
constexpr move_iterator& operator--();
|
| 1518 |
```
|
| 1519 |
|
|
@@ -1531,123 +3136,977 @@ constexpr move_iterator operator--(int);
|
|
| 1531 |
move_iterator tmp = *this;
|
| 1532 |
--current;
|
| 1533 |
return tmp;
|
| 1534 |
```
|
| 1535 |
|
| 1536 |
-
##### `move_iterator::operator+` <a id="move.iter.op.+">[[move.iter.op.+]]</a>
|
| 1537 |
-
|
| 1538 |
``` cpp
|
| 1539 |
constexpr move_iterator operator+(difference_type n) const;
|
| 1540 |
```
|
| 1541 |
|
| 1542 |
*Returns:* `move_iterator(current + n)`.
|
| 1543 |
|
| 1544 |
-
##### `move_iterator::operator+=` <a id="move.iter.op.+=">[[move.iter.op.+=]]</a>
|
| 1545 |
-
|
| 1546 |
``` cpp
|
| 1547 |
constexpr move_iterator& operator+=(difference_type n);
|
| 1548 |
```
|
| 1549 |
|
| 1550 |
*Effects:* As if by: `current += n;`
|
| 1551 |
|
| 1552 |
*Returns:* `*this`.
|
| 1553 |
|
| 1554 |
-
##### `move_iterator::operator-` <a id="move.iter.op.-">[[move.iter.op.-]]</a>
|
| 1555 |
-
|
| 1556 |
``` cpp
|
| 1557 |
constexpr move_iterator operator-(difference_type n) const;
|
| 1558 |
```
|
| 1559 |
|
| 1560 |
*Returns:* `move_iterator(current - n)`.
|
| 1561 |
|
| 1562 |
-
##### `move_iterator::operator-=` <a id="move.iter.op.-=">[[move.iter.op.-=]]</a>
|
| 1563 |
-
|
| 1564 |
``` cpp
|
| 1565 |
constexpr move_iterator& operator-=(difference_type n);
|
| 1566 |
```
|
| 1567 |
|
| 1568 |
*Effects:* As if by: `current -= n;`
|
| 1569 |
|
| 1570 |
*Returns:* `*this`.
|
| 1571 |
|
| 1572 |
-
####
|
| 1573 |
-
|
| 1574 |
-
``` cpp
|
| 1575 |
-
constexpr unspecified operator[](difference_type n) const;
|
| 1576 |
-
```
|
| 1577 |
-
|
| 1578 |
-
*Returns:* `std::move(current[n])`.
|
| 1579 |
-
|
| 1580 |
-
##### `move_iterator` comparisons <a id="move.iter.op.comp">[[move.iter.op.comp]]</a>
|
| 1581 |
|
| 1582 |
``` cpp
|
| 1583 |
template<class Iterator1, class Iterator2>
|
| 1584 |
-
constexpr bool operator==(const move_iterator<Iterator1>& x,
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1585 |
```
|
| 1586 |
|
|
|
|
|
|
|
|
|
|
| 1587 |
*Returns:* `x.base() == y.base()`.
|
| 1588 |
|
| 1589 |
-
``` cpp
|
| 1590 |
-
template <class Iterator1, class Iterator2>
|
| 1591 |
-
constexpr bool operator!=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1592 |
-
```
|
| 1593 |
-
|
| 1594 |
-
*Returns:* `!(x == y)`.
|
| 1595 |
-
|
| 1596 |
``` cpp
|
| 1597 |
template<class Iterator1, class Iterator2>
|
| 1598 |
constexpr bool operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1599 |
```
|
| 1600 |
|
|
|
|
|
|
|
|
|
|
| 1601 |
*Returns:* `x.base() < y.base()`.
|
| 1602 |
|
| 1603 |
-
``` cpp
|
| 1604 |
-
template <class Iterator1, class Iterator2>
|
| 1605 |
-
constexpr bool operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1606 |
-
```
|
| 1607 |
-
|
| 1608 |
-
*Returns:* `!(y < x)`.
|
| 1609 |
-
|
| 1610 |
``` cpp
|
| 1611 |
template<class Iterator1, class Iterator2>
|
| 1612 |
constexpr bool operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1613 |
```
|
| 1614 |
|
|
|
|
|
|
|
|
|
|
| 1615 |
*Returns:* `y < x`.
|
| 1616 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1617 |
``` cpp
|
| 1618 |
template<class Iterator1, class Iterator2>
|
| 1619 |
constexpr bool operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 1620 |
```
|
| 1621 |
|
|
|
|
|
|
|
|
|
|
| 1622 |
*Returns:* `!(x < y)`.
|
| 1623 |
|
| 1624 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1625 |
|
| 1626 |
``` cpp
|
| 1627 |
template<class Iterator1, class Iterator2>
|
| 1628 |
-
|
| 1629 |
-
|
| 1630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1631 |
```
|
| 1632 |
|
| 1633 |
*Returns:* `x.base() - y.base()`.
|
| 1634 |
|
| 1635 |
``` cpp
|
| 1636 |
template<class Iterator>
|
| 1637 |
-
constexpr move_iterator<Iterator>
|
| 1638 |
-
|
| 1639 |
```
|
| 1640 |
|
|
|
|
|
|
|
| 1641 |
*Returns:* `x + n`.
|
| 1642 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1643 |
``` cpp
|
| 1644 |
template<class Iterator>
|
| 1645 |
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 1646 |
```
|
| 1647 |
|
| 1648 |
-
*Returns:* `move_iterator<Iterator>(i)`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1649 |
|
| 1650 |
## Stream iterators <a id="stream.iterators">[[stream.iterators]]</a>
|
| 1651 |
|
| 1652 |
To make it possible for algorithmic templates to work directly with
|
| 1653 |
input/output streams, appropriate iterator-like class templates are
|
|
@@ -1666,31 +4125,13 @@ the partial sums onto `cout`.
|
|
| 1666 |
|
| 1667 |
— *end example*]
|
| 1668 |
|
| 1669 |
### Class template `istream_iterator` <a id="istream.iterator">[[istream.iterator]]</a>
|
| 1670 |
|
| 1671 |
-
The class template `istream_iterator` is an input iterator
|
| 1672 |
-
[[input.iterators]]
|
| 1673 |
-
|
| 1674 |
-
constructed, and every time `++` is used, the iterator reads and stores
|
| 1675 |
-
a value of `T`. If the iterator fails to read and store a value of `T`
|
| 1676 |
-
(`fail()` on the stream returns `true`), the iterator becomes equal to
|
| 1677 |
-
the *end-of-stream* iterator value. The constructor with no arguments
|
| 1678 |
-
`istream_iterator()` always constructs an end-of-stream input iterator
|
| 1679 |
-
object, which is the only legitimate iterator to be used for the end
|
| 1680 |
-
condition. The result of `operator*` on an end-of-stream iterator is not
|
| 1681 |
-
defined. For any other iterator value a `const T&` is returned. The
|
| 1682 |
-
result of `operator->` on an end-of-stream iterator is not defined. For
|
| 1683 |
-
any other iterator value a `const T*` is returned. The behavior of a
|
| 1684 |
-
program that applies `operator++()` to an end-of-stream iterator is
|
| 1685 |
-
undefined. It is impossible to store things into istream iterators. The
|
| 1686 |
-
type `T` shall meet the `DefaultConstructible`, `CopyConstructible`, and
|
| 1687 |
-
`CopyAssignable` requirements.
|
| 1688 |
-
|
| 1689 |
-
Two end-of-stream iterators are always equal. An end-of-stream iterator
|
| 1690 |
-
is not equal to a non-end-of-stream iterator. Two non-end-of-stream
|
| 1691 |
-
iterators are equal when they are constructed from the same stream.
|
| 1692 |
|
| 1693 |
``` cpp
|
| 1694 |
namespace std {
|
| 1695 |
template<class T, class charT = char, class traits = char_traits<charT>,
|
| 1696 |
class Distance = ptrdiff_t>
|
|
@@ -1704,107 +4145,117 @@ namespace std {
|
|
| 1704 |
using char_type = charT;
|
| 1705 |
using traits_type = traits;
|
| 1706 |
using istream_type = basic_istream<charT,traits>;
|
| 1707 |
|
| 1708 |
constexpr istream_iterator();
|
|
|
|
| 1709 |
istream_iterator(istream_type& s);
|
| 1710 |
istream_iterator(const istream_iterator& x) = default;
|
| 1711 |
~istream_iterator() = default;
|
|
|
|
| 1712 |
|
| 1713 |
const T& operator*() const;
|
| 1714 |
const T* operator->() const;
|
| 1715 |
istream_iterator& operator++();
|
| 1716 |
istream_iterator operator++(int);
|
|
|
|
|
|
|
|
|
|
| 1717 |
private:
|
| 1718 |
basic_istream<charT,traits>* in_stream; // exposition only
|
| 1719 |
T value; // exposition only
|
| 1720 |
};
|
| 1721 |
-
|
| 1722 |
-
template <class T, class charT, class traits, class Distance>
|
| 1723 |
-
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
| 1724 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 1725 |
-
template <class T, class charT, class traits, class Distance>
|
| 1726 |
-
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
|
| 1727 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 1728 |
}
|
| 1729 |
```
|
| 1730 |
|
| 1731 |
-
|
|
|
|
|
|
|
|
|
|
| 1732 |
|
| 1733 |
``` cpp
|
| 1734 |
constexpr istream_iterator();
|
|
|
|
| 1735 |
```
|
| 1736 |
|
| 1737 |
-
*Effects:* Constructs the end-of-stream iterator
|
| 1738 |
-
`
|
| 1739 |
-
constructor is a constexpr constructor.
|
| 1740 |
|
| 1741 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1742 |
|
| 1743 |
``` cpp
|
| 1744 |
istream_iterator(istream_type& s);
|
| 1745 |
```
|
| 1746 |
|
| 1747 |
-
*Effects:* Initializes `in_stream` with `addressof(s)`
|
| 1748 |
-
|
| 1749 |
-
|
| 1750 |
-
*Postconditions:* `in_stream == addressof(s)`.
|
| 1751 |
|
| 1752 |
``` cpp
|
| 1753 |
istream_iterator(const istream_iterator& x) = default;
|
| 1754 |
```
|
| 1755 |
|
| 1756 |
-
*
|
| 1757 |
-
`is_trivially_copy_constructible_v<T>` is `true`, then this constructor
|
| 1758 |
-
is a trivial copy constructor.
|
| 1759 |
|
| 1760 |
-
*
|
|
|
|
| 1761 |
|
| 1762 |
``` cpp
|
| 1763 |
~istream_iterator() = default;
|
| 1764 |
```
|
| 1765 |
|
| 1766 |
-
*
|
| 1767 |
-
|
| 1768 |
-
trivial destructor.
|
| 1769 |
|
| 1770 |
-
####
|
| 1771 |
|
| 1772 |
``` cpp
|
| 1773 |
const T& operator*() const;
|
| 1774 |
```
|
| 1775 |
|
|
|
|
|
|
|
| 1776 |
*Returns:* `value`.
|
| 1777 |
|
| 1778 |
``` cpp
|
| 1779 |
const T* operator->() const;
|
| 1780 |
```
|
| 1781 |
|
| 1782 |
-
*
|
|
|
|
|
|
|
| 1783 |
|
| 1784 |
``` cpp
|
| 1785 |
istream_iterator& operator++();
|
| 1786 |
```
|
| 1787 |
|
| 1788 |
-
*
|
| 1789 |
|
| 1790 |
-
*Effects:*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1791 |
|
| 1792 |
*Returns:* `*this`.
|
| 1793 |
|
| 1794 |
``` cpp
|
| 1795 |
istream_iterator operator++(int);
|
| 1796 |
```
|
| 1797 |
|
| 1798 |
-
*
|
| 1799 |
|
| 1800 |
-
*Effects:*
|
| 1801 |
|
| 1802 |
``` cpp
|
| 1803 |
istream_iterator tmp = *this;
|
| 1804 |
-
*
|
| 1805 |
-
return
|
| 1806 |
```
|
| 1807 |
|
| 1808 |
``` cpp
|
| 1809 |
template<class T, class charT, class traits, class Distance>
|
| 1810 |
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
|
@@ -1812,104 +4263,82 @@ template <class T, class charT, class traits, class Distance>
|
|
| 1812 |
```
|
| 1813 |
|
| 1814 |
*Returns:* `x.in_stream == y.in_stream`.
|
| 1815 |
|
| 1816 |
``` cpp
|
| 1817 |
-
|
| 1818 |
-
bool operator!=(const istream_iterator<T,charT,traits,Distance>& x,
|
| 1819 |
-
const istream_iterator<T,charT,traits,Distance>& y);
|
| 1820 |
```
|
| 1821 |
|
| 1822 |
-
*Returns:* `!
|
| 1823 |
|
| 1824 |
### Class template `ostream_iterator` <a id="ostream.iterator">[[ostream.iterator]]</a>
|
| 1825 |
|
| 1826 |
`ostream_iterator` writes (using `operator<<`) successive elements onto
|
| 1827 |
the output stream from which it was constructed. If it was constructed
|
| 1828 |
with `charT*` as a constructor argument, this string, called a
|
| 1829 |
*delimiter string*, is written to the stream after every `T` is written.
|
| 1830 |
-
It is not possible to get a value out of the output iterator. Its only
|
| 1831 |
-
use is as an output iterator in situations like
|
| 1832 |
-
|
| 1833 |
-
``` cpp
|
| 1834 |
-
while (first != last)
|
| 1835 |
-
*result++ = *first++;
|
| 1836 |
-
```
|
| 1837 |
-
|
| 1838 |
-
`ostream_iterator`
|
| 1839 |
-
|
| 1840 |
-
is defined as:
|
| 1841 |
|
| 1842 |
``` cpp
|
| 1843 |
namespace std {
|
| 1844 |
template<class T, class charT = char, class traits = char_traits<charT>>
|
| 1845 |
class ostream_iterator {
|
| 1846 |
public:
|
| 1847 |
using iterator_category = output_iterator_tag;
|
| 1848 |
using value_type = void;
|
| 1849 |
-
using difference_type =
|
| 1850 |
using pointer = void;
|
| 1851 |
using reference = void;
|
| 1852 |
using char_type = charT;
|
| 1853 |
using traits_type = traits;
|
| 1854 |
using ostream_type = basic_ostream<charT,traits>;
|
| 1855 |
|
|
|
|
| 1856 |
ostream_iterator(ostream_type& s);
|
| 1857 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 1858 |
ostream_iterator(const ostream_iterator& x);
|
| 1859 |
~ostream_iterator();
|
|
|
|
| 1860 |
ostream_iterator& operator=(const T& value);
|
| 1861 |
|
| 1862 |
ostream_iterator& operator*();
|
| 1863 |
ostream_iterator& operator++();
|
| 1864 |
ostream_iterator& operator++(int);
|
|
|
|
| 1865 |
private:
|
| 1866 |
-
basic_ostream<charT,traits>* out_stream;
|
| 1867 |
-
const charT* delim;
|
| 1868 |
};
|
| 1869 |
}
|
| 1870 |
```
|
| 1871 |
|
| 1872 |
-
####
|
| 1873 |
|
| 1874 |
``` cpp
|
| 1875 |
ostream_iterator(ostream_type& s);
|
| 1876 |
```
|
| 1877 |
|
| 1878 |
*Effects:* Initializes `out_stream` with `addressof(s)` and `delim` with
|
| 1879 |
-
|
| 1880 |
|
| 1881 |
``` cpp
|
| 1882 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 1883 |
```
|
| 1884 |
|
| 1885 |
*Effects:* Initializes `out_stream` with `addressof(s)` and `delim` with
|
| 1886 |
`delimiter`.
|
| 1887 |
|
| 1888 |
-
|
| 1889 |
-
ostream_iterator(const ostream_iterator& x);
|
| 1890 |
-
```
|
| 1891 |
-
|
| 1892 |
-
*Effects:* Constructs a copy of `x`.
|
| 1893 |
-
|
| 1894 |
-
``` cpp
|
| 1895 |
-
~ostream_iterator();
|
| 1896 |
-
```
|
| 1897 |
-
|
| 1898 |
-
*Effects:* The iterator is destroyed.
|
| 1899 |
-
|
| 1900 |
-
#### `ostream_iterator` operations <a id="ostream.iterator.ops">[[ostream.iterator.ops]]</a>
|
| 1901 |
|
| 1902 |
``` cpp
|
| 1903 |
ostream_iterator& operator=(const T& value);
|
| 1904 |
```
|
| 1905 |
|
| 1906 |
*Effects:* As if by:
|
| 1907 |
|
| 1908 |
``` cpp
|
| 1909 |
*out_stream << value;
|
| 1910 |
-
if (delim
|
| 1911 |
*out_stream << delim;
|
| 1912 |
return *this;
|
| 1913 |
```
|
| 1914 |
|
| 1915 |
``` cpp
|
|
@@ -1925,22 +4354,23 @@ ostream_iterator& operator++(int);
|
|
| 1925 |
|
| 1926 |
*Returns:* `*this`.
|
| 1927 |
|
| 1928 |
### Class template `istreambuf_iterator` <a id="istreambuf.iterator">[[istreambuf.iterator]]</a>
|
| 1929 |
|
| 1930 |
-
The class template `istreambuf_iterator` defines an input iterator
|
| 1931 |
-
[[input.iterators]]
|
| 1932 |
streambuf for which it was constructed. `operator*` provides access to
|
| 1933 |
the current input character, if any. Each time `operator++` is
|
| 1934 |
evaluated, the iterator advances to the next input character. If the end
|
| 1935 |
of stream is reached (`streambuf_type::sgetc()` returns
|
| 1936 |
`traits::eof()`), the iterator becomes equal to the *end-of-stream*
|
| 1937 |
iterator value. The default constructor `istreambuf_iterator()` and the
|
| 1938 |
-
constructor `istreambuf_iterator(
|
| 1939 |
-
iterator object suitable for use as an end-of-range. All
|
| 1940 |
-
of `istreambuf_iterator` shall have a trivial copy
|
| 1941 |
-
`constexpr` default constructor, and a trivial
|
|
|
|
| 1942 |
|
| 1943 |
The result of `operator*()` on an end-of-stream iterator is undefined.
|
| 1944 |
For any other iterator value a `char_type` value is returned. It is
|
| 1945 |
impossible to assign a character via an input iterator.
|
| 1946 |
|
|
@@ -1961,64 +4391,63 @@ namespace std {
|
|
| 1961 |
using istream_type = basic_istream<charT,traits>;
|
| 1962 |
|
| 1963 |
class proxy; // exposition only
|
| 1964 |
|
| 1965 |
constexpr istreambuf_iterator() noexcept;
|
|
|
|
| 1966 |
istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
|
| 1967 |
~istreambuf_iterator() = default;
|
| 1968 |
istreambuf_iterator(istream_type& s) noexcept;
|
| 1969 |
istreambuf_iterator(streambuf_type* s) noexcept;
|
| 1970 |
istreambuf_iterator(const proxy& p) noexcept;
|
|
|
|
| 1971 |
charT operator*() const;
|
| 1972 |
istreambuf_iterator& operator++();
|
| 1973 |
proxy operator++(int);
|
| 1974 |
bool equal(const istreambuf_iterator& b) const;
|
|
|
|
|
|
|
|
|
|
| 1975 |
private:
|
| 1976 |
streambuf_type* sbuf_; // exposition only
|
| 1977 |
};
|
| 1978 |
-
|
| 1979 |
-
template <class charT, class traits>
|
| 1980 |
-
bool operator==(const istreambuf_iterator<charT,traits>& a,
|
| 1981 |
-
const istreambuf_iterator<charT,traits>& b);
|
| 1982 |
-
template <class charT, class traits>
|
| 1983 |
-
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 1984 |
-
const istreambuf_iterator<charT,traits>& b);
|
| 1985 |
}
|
| 1986 |
```
|
| 1987 |
|
| 1988 |
-
#### Class
|
| 1989 |
-
|
| 1990 |
-
``` cpp
|
| 1991 |
-
namespace std {
|
| 1992 |
-
template <class charT, class traits = char_traits<charT>>
|
| 1993 |
-
class istreambuf_iterator<charT, traits>::proxy { // exposition only
|
| 1994 |
-
charT keep_;
|
| 1995 |
-
basic_streambuf<charT,traits>* sbuf_;
|
| 1996 |
-
proxy(charT c, basic_streambuf<charT,traits>* sbuf)
|
| 1997 |
-
: keep_(c), sbuf_(sbuf) { }
|
| 1998 |
-
public:
|
| 1999 |
-
charT operator*() { return keep_; }
|
| 2000 |
-
};
|
| 2001 |
-
}
|
| 2002 |
-
```
|
| 2003 |
|
| 2004 |
Class `istreambuf_iterator<charT,traits>::proxy` is for exposition only.
|
| 2005 |
An implementation is permitted to provide equivalent functionality
|
| 2006 |
without providing a class with this name. Class
|
| 2007 |
`istreambuf_iterator<charT, traits>::proxy` provides a temporary
|
| 2008 |
placeholder as the return value of the post-increment operator
|
| 2009 |
(`operator++`). It keeps the character pointed to by the previous value
|
| 2010 |
of the iterator for some possible future access to get the character.
|
| 2011 |
|
| 2012 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2013 |
|
| 2014 |
-
|
|
|
|
|
|
|
| 2015 |
end-of-stream iterator is constructed if and only if the exposition-only
|
| 2016 |
member `sbuf_` is initialized with a null pointer value.
|
| 2017 |
|
| 2018 |
``` cpp
|
| 2019 |
constexpr istreambuf_iterator() noexcept;
|
|
|
|
| 2020 |
```
|
| 2021 |
|
| 2022 |
*Effects:* Initializes `sbuf_` with `nullptr`.
|
| 2023 |
|
| 2024 |
``` cpp
|
|
@@ -2037,14 +4466,14 @@ istreambuf_iterator(streambuf_type* s) noexcept;
|
|
| 2037 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 2038 |
```
|
| 2039 |
|
| 2040 |
*Effects:* Initializes `sbuf_` with `p.sbuf_`.
|
| 2041 |
|
| 2042 |
-
####
|
| 2043 |
|
| 2044 |
``` cpp
|
| 2045 |
-
charT operator*() const
|
| 2046 |
```
|
| 2047 |
|
| 2048 |
*Returns:* The character obtained via the `streambuf` member
|
| 2049 |
`sbuf_->sgetc()`.
|
| 2050 |
|
|
@@ -2058,11 +4487,11 @@ istreambuf_iterator& operator++();
|
|
| 2058 |
|
| 2059 |
``` cpp
|
| 2060 |
proxy operator++(int);
|
| 2061 |
```
|
| 2062 |
|
| 2063 |
-
*Returns:* `proxy(sbuf_->sbumpc(), sbuf_)`.
|
| 2064 |
|
| 2065 |
``` cpp
|
| 2066 |
bool equal(const istreambuf_iterator& b) const;
|
| 2067 |
```
|
| 2068 |
|
|
@@ -2077,72 +4506,70 @@ template <class charT, class traits>
|
|
| 2077 |
```
|
| 2078 |
|
| 2079 |
*Returns:* `a.equal(b)`.
|
| 2080 |
|
| 2081 |
``` cpp
|
| 2082 |
-
|
| 2083 |
-
bool operator!=(const istreambuf_iterator<charT,traits>& a,
|
| 2084 |
-
const istreambuf_iterator<charT,traits>& b);
|
| 2085 |
```
|
| 2086 |
|
| 2087 |
-
*Returns:* `
|
| 2088 |
|
| 2089 |
### Class template `ostreambuf_iterator` <a id="ostreambuf.iterator">[[ostreambuf.iterator]]</a>
|
| 2090 |
|
| 2091 |
-
``` cpp
|
| 2092 |
-
namespace std {
|
| 2093 |
-
template <class charT, class traits = char_traits<charT>>
|
| 2094 |
-
class ostreambuf_iterator {
|
| 2095 |
-
public:
|
| 2096 |
-
using iterator_category = output_iterator_tag;
|
| 2097 |
-
using value_type = void;
|
| 2098 |
-
using difference_type = void;
|
| 2099 |
-
using pointer = void;
|
| 2100 |
-
using reference = void;
|
| 2101 |
-
using char_type = charT;
|
| 2102 |
-
using traits_type = traits;
|
| 2103 |
-
using streambuf_type = basic_streambuf<charT,traits>;
|
| 2104 |
-
using ostream_type = basic_ostream<charT,traits>;
|
| 2105 |
-
|
| 2106 |
-
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 2107 |
-
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 2108 |
-
ostreambuf_iterator& operator=(charT c);
|
| 2109 |
-
|
| 2110 |
-
ostreambuf_iterator& operator*();
|
| 2111 |
-
ostreambuf_iterator& operator++();
|
| 2112 |
-
ostreambuf_iterator& operator++(int);
|
| 2113 |
-
bool failed() const noexcept;
|
| 2114 |
-
|
| 2115 |
-
private:
|
| 2116 |
-
streambuf_type* sbuf_; // exposition only
|
| 2117 |
-
};
|
| 2118 |
-
}
|
| 2119 |
-
```
|
| 2120 |
-
|
| 2121 |
The class template `ostreambuf_iterator` writes successive *characters*
|
| 2122 |
-
onto the output stream from which it was constructed.
|
| 2123 |
-
to get a character value out of the output iterator.
|
| 2124 |
|
| 2125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2126 |
|
| 2127 |
``` cpp
|
| 2128 |
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 2129 |
```
|
| 2130 |
|
| 2131 |
-
*
|
| 2132 |
|
| 2133 |
*Effects:* Initializes `sbuf_` with `s.rdbuf()`.
|
| 2134 |
|
| 2135 |
``` cpp
|
| 2136 |
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 2137 |
```
|
| 2138 |
|
| 2139 |
-
*
|
| 2140 |
|
| 2141 |
*Effects:* Initializes `sbuf_` with `s`.
|
| 2142 |
|
| 2143 |
-
####
|
| 2144 |
|
| 2145 |
``` cpp
|
| 2146 |
ostreambuf_iterator& operator=(charT c);
|
| 2147 |
```
|
| 2148 |
|
|
@@ -2174,12 +4601,14 @@ bool failed() const noexcept;
|
|
| 2174 |
## Range access <a id="iterator.range">[[iterator.range]]</a>
|
| 2175 |
|
| 2176 |
In addition to being available via inclusion of the `<iterator>` header,
|
| 2177 |
the function templates in [[iterator.range]] are available when any of
|
| 2178 |
the following headers are included: `<array>`, `<deque>`,
|
| 2179 |
-
`<forward_list>`, `<list>`, `<map>`, `<regex>`, `<set>`, `<
|
| 2180 |
-
`<
|
|
|
|
|
|
|
| 2181 |
|
| 2182 |
``` cpp
|
| 2183 |
template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
|
| 2184 |
template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
|
| 2185 |
```
|
|
@@ -2267,18 +4696,10 @@ template <class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c)
|
|
| 2267 |
template<class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
|
| 2268 |
```
|
| 2269 |
|
| 2270 |
*Returns:* `std::rend(c)`.
|
| 2271 |
|
| 2272 |
-
## Container access <a id="iterator.container">[[iterator.container]]</a>
|
| 2273 |
-
|
| 2274 |
-
In addition to being available via inclusion of the `<iterator>` header,
|
| 2275 |
-
the function templates in [[iterator.container]] are available when any
|
| 2276 |
-
of the following headers are included: `<array>`, `<deque>`,
|
| 2277 |
-
`<forward_list>`, `<list>`, `<map>`, `<regex>`, `<set>`, `<string>`,
|
| 2278 |
-
`<unordered_map>`, `<unordered_set>`, and `<vector>`.
|
| 2279 |
-
|
| 2280 |
``` cpp
|
| 2281 |
template<class C> constexpr auto size(const C& c) -> decltype(c.size());
|
| 2282 |
```
|
| 2283 |
|
| 2284 |
*Returns:* `c.size()`.
|
|
@@ -2288,23 +4709,40 @@ template <class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept
|
|
| 2288 |
```
|
| 2289 |
|
| 2290 |
*Returns:* `N`.
|
| 2291 |
|
| 2292 |
``` cpp
|
| 2293 |
-
template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2294 |
```
|
| 2295 |
|
| 2296 |
*Returns:* `c.empty()`.
|
| 2297 |
|
| 2298 |
``` cpp
|
| 2299 |
-
template
|
| 2300 |
```
|
| 2301 |
|
| 2302 |
*Returns:* `false`.
|
| 2303 |
|
| 2304 |
``` cpp
|
| 2305 |
-
template
|
| 2306 |
```
|
| 2307 |
|
| 2308 |
*Returns:* `il.size() == 0`.
|
| 2309 |
|
| 2310 |
``` cpp
|
|
@@ -2325,32 +4763,65 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
|
|
| 2325 |
```
|
| 2326 |
|
| 2327 |
*Returns:* `il.begin()`.
|
| 2328 |
|
| 2329 |
<!-- Link reference definitions -->
|
| 2330 |
-
[
|
| 2331 |
-
[
|
| 2332 |
-
[
|
| 2333 |
-
[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2334 |
[back.insert.iter.ops]: #back.insert.iter.ops
|
| 2335 |
[back.insert.iterator]: #back.insert.iterator
|
| 2336 |
[back.inserter]: #back.inserter
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2337 |
[bidirectional.iterators]: #bidirectional.iterators
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2338 |
[containers]: containers.md#containers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2339 |
[forward.iterators]: #forward.iterators
|
| 2340 |
-
[
|
| 2341 |
-
[front.insert.iter.op*]: #front.insert.iter.op*
|
| 2342 |
-
[front.insert.iter.op++]: #front.insert.iter.op++
|
| 2343 |
-
[front.insert.iter.op=]: #front.insert.iter.op=
|
| 2344 |
[front.insert.iter.ops]: #front.insert.iter.ops
|
| 2345 |
[front.insert.iterator]: #front.insert.iterator
|
| 2346 |
[front.inserter]: #front.inserter
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2347 |
[input.iterators]: #input.iterators
|
| 2348 |
-
[
|
| 2349 |
-
[insert.iter.op*]: #insert.iter.op*
|
| 2350 |
-
[insert.iter.op++]: #insert.iter.op++
|
| 2351 |
-
[insert.iter.op=]: #insert.iter.op=
|
| 2352 |
[insert.iter.ops]: #insert.iter.ops
|
| 2353 |
[insert.iterator]: #insert.iterator
|
| 2354 |
[insert.iterators]: #insert.iterators
|
| 2355 |
[inserter]: #inserter
|
| 2356 |
[iostream.format]: input.md#iostream.format
|
|
@@ -2359,88 +4830,100 @@ template <class E> constexpr const E* data(initializer_list<E> il) noexcept;
|
|
| 2359 |
[istream.iterator.ops]: #istream.iterator.ops
|
| 2360 |
[istreambuf.iterator]: #istreambuf.iterator
|
| 2361 |
[istreambuf.iterator.cons]: #istreambuf.iterator.cons
|
| 2362 |
[istreambuf.iterator.ops]: #istreambuf.iterator.ops
|
| 2363 |
[istreambuf.iterator.proxy]: #istreambuf.iterator.proxy
|
| 2364 |
-
[iterator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2365 |
[iterator.iterators]: #iterator.iterators
|
| 2366 |
[iterator.operations]: #iterator.operations
|
| 2367 |
[iterator.primitives]: #iterator.primitives
|
| 2368 |
[iterator.range]: #iterator.range
|
| 2369 |
[iterator.requirements]: #iterator.requirements
|
| 2370 |
[iterator.requirements.general]: #iterator.requirements.general
|
| 2371 |
[iterator.synopsis]: #iterator.synopsis
|
| 2372 |
[iterator.traits]: #iterator.traits
|
| 2373 |
[iterators]: #iterators
|
|
|
|
|
|
|
| 2374 |
[iterators.general]: #iterators.general
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2375 |
[move.iter.nonmember]: #move.iter.nonmember
|
| 2376 |
-
[move.iter.op.+]: #move.iter.op.+
|
| 2377 |
-
[move.iter.op.+=]: #move.iter.op.+=
|
| 2378 |
-
[move.iter.op.-]: #move.iter.op.-
|
| 2379 |
-
[move.iter.op.-=]: #move.iter.op.-=
|
| 2380 |
[move.iter.op.comp]: #move.iter.op.comp
|
| 2381 |
-
[move.iter.op.const]: #move.iter.op.const
|
| 2382 |
[move.iter.op.conv]: #move.iter.op.conv
|
| 2383 |
-
[move.iter.op.decr]: #move.iter.op.decr
|
| 2384 |
-
[move.iter.op.incr]: #move.iter.op.incr
|
| 2385 |
-
[move.iter.op.index]: #move.iter.op.index
|
| 2386 |
-
[move.iter.op.ref]: #move.iter.op.ref
|
| 2387 |
-
[move.iter.op.star]: #move.iter.op.star
|
| 2388 |
-
[move.iter.op=]: #move.iter.op=
|
| 2389 |
-
[move.iter.ops]: #move.iter.ops
|
| 2390 |
[move.iter.requirements]: #move.iter.requirements
|
| 2391 |
[move.iterator]: #move.iterator
|
| 2392 |
[move.iterators]: #move.iterators
|
|
|
|
|
|
|
|
|
|
| 2393 |
[ostream.iterator]: #ostream.iterator
|
| 2394 |
[ostream.iterator.cons.des]: #ostream.iterator.cons.des
|
| 2395 |
[ostream.iterator.ops]: #ostream.iterator.ops
|
| 2396 |
[ostreambuf.iter.cons]: #ostreambuf.iter.cons
|
| 2397 |
[ostreambuf.iter.ops]: #ostreambuf.iter.ops
|
| 2398 |
[ostreambuf.iterator]: #ostreambuf.iterator
|
| 2399 |
[output.iterators]: #output.iterators
|
|
|
|
| 2400 |
[predef.iterators]: #predef.iterators
|
|
|
|
| 2401 |
[random.access.iterators]: #random.access.iterators
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2402 |
[reverse.iter.cons]: #reverse.iter.cons
|
| 2403 |
[reverse.iter.conv]: #reverse.iter.conv
|
| 2404 |
-
[reverse.iter.
|
| 2405 |
-
[reverse.iter.
|
| 2406 |
-
[reverse.iter.
|
| 2407 |
-
[reverse.iter.op++]: #reverse.iter.op++
|
| 2408 |
-
[reverse.iter.op+=]: #reverse.iter.op+=
|
| 2409 |
-
[reverse.iter.op-]: #reverse.iter.op-
|
| 2410 |
-
[reverse.iter.op-=]: #reverse.iter.op-=
|
| 2411 |
-
[reverse.iter.op.star]: #reverse.iter.op.star
|
| 2412 |
-
[reverse.iter.op<]: #reverse.iter.op<
|
| 2413 |
-
[reverse.iter.op<=]: #reverse.iter.op<=
|
| 2414 |
-
[reverse.iter.op=]: #reverse.iter.op=
|
| 2415 |
-
[reverse.iter.op==]: #reverse.iter.op==
|
| 2416 |
-
[reverse.iter.op>]: #reverse.iter.op>
|
| 2417 |
-
[reverse.iter.op>=]: #reverse.iter.op>=
|
| 2418 |
-
[reverse.iter.opdiff]: #reverse.iter.opdiff
|
| 2419 |
-
[reverse.iter.opindex]: #reverse.iter.opindex
|
| 2420 |
-
[reverse.iter.opref]: #reverse.iter.opref
|
| 2421 |
-
[reverse.iter.ops]: #reverse.iter.ops
|
| 2422 |
-
[reverse.iter.opsum]: #reverse.iter.opsum
|
| 2423 |
[reverse.iter.requirements]: #reverse.iter.requirements
|
| 2424 |
[reverse.iterator]: #reverse.iterator
|
| 2425 |
[reverse.iterators]: #reverse.iterators
|
| 2426 |
[std.iterator.tags]: #std.iterator.tags
|
| 2427 |
[stream.buffers]: input.md#stream.buffers
|
| 2428 |
[stream.iterators]: #stream.iterators
|
| 2429 |
[swappable.requirements]: library.md#swappable.requirements
|
| 2430 |
-
[tab:copyassignable]: #tab:copyassignable
|
| 2431 |
-
[tab:equalitycomparable]: #tab:equalitycomparable
|
| 2432 |
-
[tab:iterator.bidirectional.requirements]: #tab:iterator.bidirectional.requirements
|
| 2433 |
-
[tab:iterator.forward.requirements]: #tab:iterator.forward.requirements
|
| 2434 |
-
[tab:iterator.input.requirements]: #tab:iterator.input.requirements
|
| 2435 |
-
[tab:iterator.output.requirements]: #tab:iterator.output.requirements
|
| 2436 |
-
[tab:iterator.random.access.requirements]: #tab:iterator.random.access.requirements
|
| 2437 |
-
[tab:iterator.requirements]: #tab:iterator.requirements
|
| 2438 |
-
[tab:iterators.lib.summary]: #tab:iterators.lib.summary
|
| 2439 |
-
[tab:iterators.relations]: #tab:iterators.relations
|
| 2440 |
[temp.deduct]: temp.md#temp.deduct
|
|
|
|
| 2441 |
[temp.inst]: temp.md#temp.inst
|
|
|
|
|
|
|
| 2442 |
[utility.arg.requirements]: library.md#utility.arg.requirements
|
| 2443 |
|
| 2444 |
-
[^1]:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2445 |
The effect of dereferencing an iterator that has been invalidated is
|
| 2446 |
undefined.
|
|
|
|
| 1 |
# Iterators library <a id="iterators">[[iterators]]</a>
|
| 2 |
|
| 3 |
## General <a id="iterators.general">[[iterators.general]]</a>
|
| 4 |
|
| 5 |
This Clause describes components that C++ programs may use to perform
|
| 6 |
+
iterations over containers [[containers]], streams [[iostream.format]],
|
| 7 |
+
stream buffers [[stream.buffers]], and other ranges [[ranges]].
|
| 8 |
|
| 9 |
The following subclauses describe iterator requirements, and components
|
| 10 |
for iterator primitives, predefined iterators, and stream iterators, as
|
| 11 |
+
summarized in [[iterators.summary]].
|
| 12 |
|
| 13 |
+
**Table: Iterators library summary** <a id="iterators.summary">[iterators.summary]</a>
|
| 14 |
|
| 15 |
| Subclause | | Header |
|
| 16 |
+
| ------------------------- | --------------------- | ------------ |
|
| 17 |
+
| [[iterator.requirements]] | Iterator requirements | `<iterator>` |
|
| 18 |
+
| [[iterator.primitives]] | Iterator primitives | |
|
| 19 |
+
| [[predef.iterators]] | Iterator adaptors | |
|
| 20 |
| [[stream.iterators]] | Stream iterators | |
|
| 21 |
+
| [[iterator.range]] | Range access | |
|
| 22 |
|
| 23 |
|
| 24 |
+
## Header `<iterator>` synopsis <a id="iterator.synopsis">[[iterator.synopsis]]</a>
|
| 25 |
+
|
| 26 |
+
``` cpp
|
| 27 |
+
#include <compare> // see [compare.syn]
|
| 28 |
+
#include <concepts> // see [concepts.syn]
|
| 29 |
+
|
| 30 |
+
namespace std {
|
| 31 |
+
template<class T> using with-reference = T&; // exposition only
|
| 32 |
+
template<class T> concept can-reference // exposition only
|
| 33 |
+
= requires { typename with-reference<T>; };
|
| 34 |
+
template<class T> concept dereferenceable // exposition only
|
| 35 |
+
= requires(T& t) {
|
| 36 |
+
{ *t } -> can-reference; // not required to be equality-preserving
|
| 37 |
+
};
|
| 38 |
+
|
| 39 |
+
// [iterator.assoc.types], associated types
|
| 40 |
+
// [incrementable.traits], incrementable traits
|
| 41 |
+
template<class> struct incrementable_traits;
|
| 42 |
+
template<class T>
|
| 43 |
+
using iter_difference_t = see below;
|
| 44 |
+
|
| 45 |
+
// [readable.traits], indirectly readable traits
|
| 46 |
+
template<class> struct indirectly_readable_traits;
|
| 47 |
+
template<class T>
|
| 48 |
+
using iter_value_t = see below;
|
| 49 |
+
|
| 50 |
+
// [iterator.traits], iterator traits
|
| 51 |
+
template<class I> struct iterator_traits;
|
| 52 |
+
template<class T> requires is_object_v<T> struct iterator_traits<T*>;
|
| 53 |
+
|
| 54 |
+
template<dereferenceable T>
|
| 55 |
+
using iter_reference_t = decltype(*declval<T&>());
|
| 56 |
+
|
| 57 |
+
namespace ranges {
|
| 58 |
+
// [iterator.cust], customization points
|
| 59 |
+
inline namespace unspecified {
|
| 60 |
+
// [iterator.cust.move], ranges::iter_move
|
| 61 |
+
inline constexpr unspecified iter_move = unspecified;
|
| 62 |
+
|
| 63 |
+
// [iterator.cust.swap], ranges::iter_swap
|
| 64 |
+
inline constexpr unspecified iter_swap = unspecified;
|
| 65 |
+
}
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
template<dereferenceable T>
|
| 69 |
+
requires requires(T& t) {
|
| 70 |
+
{ ranges::iter_move(t) } -> can-reference;
|
| 71 |
+
}
|
| 72 |
+
using iter_rvalue_reference_t
|
| 73 |
+
= decltype(ranges::iter_move(declval<T&>()));
|
| 74 |
+
|
| 75 |
+
// [iterator.concepts], iterator concepts
|
| 76 |
+
// [iterator.concept.readable], concept indirectly_readable
|
| 77 |
+
template<class In>
|
| 78 |
+
concept indirectly_readable = see below;
|
| 79 |
+
|
| 80 |
+
template<indirectly_readable T>
|
| 81 |
+
using iter_common_reference_t =
|
| 82 |
+
common_reference_t<iter_reference_t<T>, iter_value_t<T>&>;
|
| 83 |
+
|
| 84 |
+
// [iterator.concept.writable], concept indirectly_writable
|
| 85 |
+
template<class Out, class T>
|
| 86 |
+
concept indirectly_writable = see below;
|
| 87 |
+
|
| 88 |
+
// [iterator.concept.winc], concept weakly_incrementable
|
| 89 |
+
template<class I>
|
| 90 |
+
concept weakly_incrementable = see below;
|
| 91 |
+
|
| 92 |
+
// [iterator.concept.inc], concept incrementable
|
| 93 |
+
template<class I>
|
| 94 |
+
concept incrementable = see below;
|
| 95 |
+
|
| 96 |
+
// [iterator.concept.iterator], concept input_or_output_iterator
|
| 97 |
+
template<class I>
|
| 98 |
+
concept input_or_output_iterator = see below;
|
| 99 |
+
|
| 100 |
+
// [iterator.concept.sentinel], concept sentinel_for
|
| 101 |
+
template<class S, class I>
|
| 102 |
+
concept sentinel_for = see below;
|
| 103 |
+
|
| 104 |
+
// [iterator.concept.sizedsentinel], concept sized_sentinel_for
|
| 105 |
+
template<class S, class I>
|
| 106 |
+
inline constexpr bool disable_sized_sentinel_for = false;
|
| 107 |
+
|
| 108 |
+
template<class S, class I>
|
| 109 |
+
concept sized_sentinel_for = see below;
|
| 110 |
+
|
| 111 |
+
// [iterator.concept.input], concept input_iterator
|
| 112 |
+
template<class I>
|
| 113 |
+
concept input_iterator = see below;
|
| 114 |
+
|
| 115 |
+
// [iterator.concept.output], concept output_iterator
|
| 116 |
+
template<class I, class T>
|
| 117 |
+
concept output_iterator = see below;
|
| 118 |
+
|
| 119 |
+
// [iterator.concept.forward], concept forward_iterator
|
| 120 |
+
template<class I>
|
| 121 |
+
concept forward_iterator = see below;
|
| 122 |
+
|
| 123 |
+
// [iterator.concept.bidir], concept bidirectional_iterator
|
| 124 |
+
template<class I>
|
| 125 |
+
concept bidirectional_iterator = see below;
|
| 126 |
+
|
| 127 |
+
// [iterator.concept.random.access], concept random_access_iterator
|
| 128 |
+
template<class I>
|
| 129 |
+
concept random_access_iterator = see below;
|
| 130 |
+
|
| 131 |
+
// [iterator.concept.contiguous], concept contiguous_iterator
|
| 132 |
+
template<class I>
|
| 133 |
+
concept contiguous_iterator = see below;
|
| 134 |
+
|
| 135 |
+
// [indirectcallable], indirect callable requirements
|
| 136 |
+
// [indirectcallable.indirectinvocable], indirect callables
|
| 137 |
+
template<class F, class I>
|
| 138 |
+
concept indirectly_unary_invocable = see below;
|
| 139 |
+
|
| 140 |
+
template<class F, class I>
|
| 141 |
+
concept indirectly_regular_unary_invocable = see below;
|
| 142 |
+
|
| 143 |
+
template<class F, class I>
|
| 144 |
+
concept indirect_unary_predicate = see below;
|
| 145 |
+
|
| 146 |
+
template<class F, class I1, class I2>
|
| 147 |
+
concept indirect_binary_predicate = see below;
|
| 148 |
+
|
| 149 |
+
template<class F, class I1, class I2 = I1>
|
| 150 |
+
concept indirect_equivalence_relation = see below;
|
| 151 |
+
|
| 152 |
+
template<class F, class I1, class I2 = I1>
|
| 153 |
+
concept indirect_strict_weak_order = see below;
|
| 154 |
+
|
| 155 |
+
template<class F, class... Is>
|
| 156 |
+
requires (indirectly_readable<Is> && ...) && invocable<F, iter_reference_t<Is>...>
|
| 157 |
+
using indirect_result_t = invoke_result_t<F, iter_reference_t<Is>...>;
|
| 158 |
+
|
| 159 |
+
// [projected], projected
|
| 160 |
+
template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
|
| 161 |
+
struct projected;
|
| 162 |
+
|
| 163 |
+
template<weakly_incrementable I, class Proj>
|
| 164 |
+
struct incrementable_traits<projected<I, Proj>>;
|
| 165 |
+
|
| 166 |
+
// [alg.req], common algorithm requirements
|
| 167 |
+
// [alg.req.ind.move], concept indirectly_movable
|
| 168 |
+
template<class In, class Out>
|
| 169 |
+
concept indirectly_movable = see below;
|
| 170 |
+
|
| 171 |
+
template<class In, class Out>
|
| 172 |
+
concept indirectly_movable_storable = see below;
|
| 173 |
+
|
| 174 |
+
// [alg.req.ind.copy], concept indirectly_copyable
|
| 175 |
+
template<class In, class Out>
|
| 176 |
+
concept indirectly_copyable = see below;
|
| 177 |
+
|
| 178 |
+
template<class In, class Out>
|
| 179 |
+
concept indirectly_copyable_storable = see below;
|
| 180 |
+
|
| 181 |
+
// [alg.req.ind.swap], concept indirectly_swappable
|
| 182 |
+
template<class I1, class I2 = I1>
|
| 183 |
+
concept indirectly_swappable = see below;
|
| 184 |
+
|
| 185 |
+
// [alg.req.ind.cmp], concept indirectly_comparable
|
| 186 |
+
template<class I1, class I2, class R, class P1 = identity, class P2 = identity>
|
| 187 |
+
concept indirectly_comparable = see below;
|
| 188 |
+
|
| 189 |
+
// [alg.req.permutable], concept permutable
|
| 190 |
+
template<class I>
|
| 191 |
+
concept permutable = see below;
|
| 192 |
+
|
| 193 |
+
// [alg.req.mergeable], concept mergeable
|
| 194 |
+
template<class I1, class I2, class Out,
|
| 195 |
+
class R = ranges::less, class P1 = identity, class P2 = identity>
|
| 196 |
+
concept mergeable = see below;
|
| 197 |
+
|
| 198 |
+
// [alg.req.sortable], concept sortable
|
| 199 |
+
template<class I, class R = ranges::less, class P = identity>
|
| 200 |
+
concept sortable = see below;
|
| 201 |
+
|
| 202 |
+
// [iterator.primitives], primitives
|
| 203 |
+
// [std.iterator.tags], iterator tags
|
| 204 |
+
struct input_iterator_tag { };
|
| 205 |
+
struct output_iterator_tag { };
|
| 206 |
+
struct forward_iterator_tag: public input_iterator_tag { };
|
| 207 |
+
struct bidirectional_iterator_tag: public forward_iterator_tag { };
|
| 208 |
+
struct random_access_iterator_tag: public bidirectional_iterator_tag { };
|
| 209 |
+
struct contiguous_iterator_tag: public random_access_iterator_tag { };
|
| 210 |
+
|
| 211 |
+
// [iterator.operations], iterator operations
|
| 212 |
+
template<class InputIterator, class Distance>
|
| 213 |
+
constexpr void
|
| 214 |
+
advance(InputIterator& i, Distance n);
|
| 215 |
+
template<class InputIterator>
|
| 216 |
+
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 217 |
+
distance(InputIterator first, InputIterator last);
|
| 218 |
+
template<class InputIterator>
|
| 219 |
+
constexpr InputIterator
|
| 220 |
+
next(InputIterator x,
|
| 221 |
+
typename iterator_traits<InputIterator>::difference_type n = 1);
|
| 222 |
+
template<class BidirectionalIterator>
|
| 223 |
+
constexpr BidirectionalIterator
|
| 224 |
+
prev(BidirectionalIterator x,
|
| 225 |
+
typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
|
| 226 |
+
|
| 227 |
+
// [range.iter.ops], range iterator operations
|
| 228 |
+
namespace ranges {
|
| 229 |
+
// [range.iter.op.advance], ranges::advance
|
| 230 |
+
template<input_or_output_iterator I>
|
| 231 |
+
constexpr void advance(I& i, iter_difference_t<I> n);
|
| 232 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 233 |
+
constexpr void advance(I& i, S bound);
|
| 234 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 235 |
+
constexpr iter_difference_t<I> advance(I& i, iter_difference_t<I> n, S bound);
|
| 236 |
+
|
| 237 |
+
// [range.iter.op.distance], ranges::distance
|
| 238 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 239 |
+
constexpr iter_difference_t<I> distance(I first, S last);
|
| 240 |
+
template<range R>
|
| 241 |
+
constexpr range_difference_t<R> distance(R&& r);
|
| 242 |
+
|
| 243 |
+
// [range.iter.op.next], ranges::next
|
| 244 |
+
template<input_or_output_iterator I>
|
| 245 |
+
constexpr I next(I x);
|
| 246 |
+
template<input_or_output_iterator I>
|
| 247 |
+
constexpr I next(I x, iter_difference_t<I> n);
|
| 248 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 249 |
+
constexpr I next(I x, S bound);
|
| 250 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 251 |
+
constexpr I next(I x, iter_difference_t<I> n, S bound);
|
| 252 |
+
|
| 253 |
+
// [range.iter.op.prev], ranges::prev
|
| 254 |
+
template<bidirectional_iterator I>
|
| 255 |
+
constexpr I prev(I x);
|
| 256 |
+
template<bidirectional_iterator I>
|
| 257 |
+
constexpr I prev(I x, iter_difference_t<I> n);
|
| 258 |
+
template<bidirectional_iterator I>
|
| 259 |
+
constexpr I prev(I x, iter_difference_t<I> n, I bound);
|
| 260 |
+
}
|
| 261 |
+
|
| 262 |
+
// [predef.iterators], predefined iterators and sentinels
|
| 263 |
+
// [reverse.iterators], reverse iterators
|
| 264 |
+
template<class Iterator> class reverse_iterator;
|
| 265 |
+
|
| 266 |
+
template<class Iterator1, class Iterator2>
|
| 267 |
+
constexpr bool operator==(
|
| 268 |
+
const reverse_iterator<Iterator1>& x,
|
| 269 |
+
const reverse_iterator<Iterator2>& y);
|
| 270 |
+
template<class Iterator1, class Iterator2>
|
| 271 |
+
constexpr bool operator!=(
|
| 272 |
+
const reverse_iterator<Iterator1>& x,
|
| 273 |
+
const reverse_iterator<Iterator2>& y);
|
| 274 |
+
template<class Iterator1, class Iterator2>
|
| 275 |
+
constexpr bool operator<(
|
| 276 |
+
const reverse_iterator<Iterator1>& x,
|
| 277 |
+
const reverse_iterator<Iterator2>& y);
|
| 278 |
+
template<class Iterator1, class Iterator2>
|
| 279 |
+
constexpr bool operator>(
|
| 280 |
+
const reverse_iterator<Iterator1>& x,
|
| 281 |
+
const reverse_iterator<Iterator2>& y);
|
| 282 |
+
template<class Iterator1, class Iterator2>
|
| 283 |
+
constexpr bool operator<=(
|
| 284 |
+
const reverse_iterator<Iterator1>& x,
|
| 285 |
+
const reverse_iterator<Iterator2>& y);
|
| 286 |
+
template<class Iterator1, class Iterator2>
|
| 287 |
+
constexpr bool operator>=(
|
| 288 |
+
const reverse_iterator<Iterator1>& x,
|
| 289 |
+
const reverse_iterator<Iterator2>& y);
|
| 290 |
+
template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
|
| 291 |
+
constexpr compare_three_way_result_t<Iterator1, Iterator2>
|
| 292 |
+
operator<=>(const reverse_iterator<Iterator1>& x,
|
| 293 |
+
const reverse_iterator<Iterator2>& y);
|
| 294 |
+
|
| 295 |
+
template<class Iterator1, class Iterator2>
|
| 296 |
+
constexpr auto operator-(
|
| 297 |
+
const reverse_iterator<Iterator1>& x,
|
| 298 |
+
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 299 |
+
template<class Iterator>
|
| 300 |
+
constexpr reverse_iterator<Iterator>
|
| 301 |
+
operator+(
|
| 302 |
+
typename reverse_iterator<Iterator>::difference_type n,
|
| 303 |
+
const reverse_iterator<Iterator>& x);
|
| 304 |
+
|
| 305 |
+
template<class Iterator>
|
| 306 |
+
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 307 |
+
|
| 308 |
+
template<class Iterator1, class Iterator2>
|
| 309 |
+
requires (!sized_sentinel_for<Iterator1, Iterator2>)
|
| 310 |
+
inline constexpr bool disable_sized_sentinel_for<reverse_iterator<Iterator1>,
|
| 311 |
+
reverse_iterator<Iterator2>> = true;
|
| 312 |
+
|
| 313 |
+
// [insert.iterators], insert iterators
|
| 314 |
+
template<class Container> class back_insert_iterator;
|
| 315 |
+
template<class Container>
|
| 316 |
+
constexpr back_insert_iterator<Container> back_inserter(Container& x);
|
| 317 |
+
|
| 318 |
+
template<class Container> class front_insert_iterator;
|
| 319 |
+
template<class Container>
|
| 320 |
+
constexpr front_insert_iterator<Container> front_inserter(Container& x);
|
| 321 |
+
|
| 322 |
+
template<class Container> class insert_iterator;
|
| 323 |
+
template<class Container>
|
| 324 |
+
constexpr insert_iterator<Container>
|
| 325 |
+
inserter(Container& x, ranges::iterator_t<Container> i);
|
| 326 |
+
|
| 327 |
+
// [move.iterators], move iterators and sentinels
|
| 328 |
+
template<class Iterator> class move_iterator;
|
| 329 |
+
|
| 330 |
+
template<class Iterator1, class Iterator2>
|
| 331 |
+
constexpr bool operator==(
|
| 332 |
+
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 333 |
+
template<class Iterator1, class Iterator2>
|
| 334 |
+
constexpr bool operator<(
|
| 335 |
+
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 336 |
+
template<class Iterator1, class Iterator2>
|
| 337 |
+
constexpr bool operator>(
|
| 338 |
+
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 339 |
+
template<class Iterator1, class Iterator2>
|
| 340 |
+
constexpr bool operator<=(
|
| 341 |
+
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 342 |
+
template<class Iterator1, class Iterator2>
|
| 343 |
+
constexpr bool operator>=(
|
| 344 |
+
const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 345 |
+
template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
|
| 346 |
+
constexpr compare_three_way_result_t<Iterator1, Iterator2>
|
| 347 |
+
operator<=>(const move_iterator<Iterator1>& x,
|
| 348 |
+
const move_iterator<Iterator2>& y);
|
| 349 |
+
|
| 350 |
+
template<class Iterator1, class Iterator2>
|
| 351 |
+
constexpr auto operator-(
|
| 352 |
+
const move_iterator<Iterator1>& x,
|
| 353 |
+
const move_iterator<Iterator2>& y) -> decltype(x.base() - y.base());
|
| 354 |
+
template<class Iterator>
|
| 355 |
+
constexpr move_iterator<Iterator> operator+(
|
| 356 |
+
typename move_iterator<Iterator>::difference_type n, const move_iterator<Iterator>& x);
|
| 357 |
+
|
| 358 |
+
template<class Iterator>
|
| 359 |
+
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 360 |
+
|
| 361 |
+
template<semiregular S> class move_sentinel;
|
| 362 |
+
|
| 363 |
+
// [iterators.common], common iterators
|
| 364 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 365 |
+
requires (!same_as<I, S> && copyable<I>)
|
| 366 |
+
class common_iterator;
|
| 367 |
+
|
| 368 |
+
template<class I, class S>
|
| 369 |
+
struct incrementable_traits<common_iterator<I, S>>;
|
| 370 |
+
|
| 371 |
+
template<input_iterator I, class S>
|
| 372 |
+
struct iterator_traits<common_iterator<I, S>>;
|
| 373 |
+
|
| 374 |
+
// [default.sentinels], default sentinels
|
| 375 |
+
struct default_sentinel_t;
|
| 376 |
+
inline constexpr default_sentinel_t default_sentinel{};
|
| 377 |
+
|
| 378 |
+
// [iterators.counted], counted iterators
|
| 379 |
+
template<input_or_output_iterator I> class counted_iterator;
|
| 380 |
+
|
| 381 |
+
template<class I>
|
| 382 |
+
struct incrementable_traits<counted_iterator<I>>;
|
| 383 |
+
|
| 384 |
+
template<input_iterator I>
|
| 385 |
+
struct iterator_traits<counted_iterator<I>>;
|
| 386 |
+
|
| 387 |
+
// [unreachable.sentinels], unreachable sentinels
|
| 388 |
+
struct unreachable_sentinel_t;
|
| 389 |
+
inline constexpr unreachable_sentinel_t unreachable_sentinel{};
|
| 390 |
+
|
| 391 |
+
// [stream.iterators], stream iterators
|
| 392 |
+
template<class T, class charT = char, class traits = char_traits<charT>,
|
| 393 |
+
class Distance = ptrdiff_t>
|
| 394 |
+
class istream_iterator;
|
| 395 |
+
template<class T, class charT, class traits, class Distance>
|
| 396 |
+
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
| 397 |
+
const istream_iterator<T,charT,traits,Distance>& y);
|
| 398 |
+
|
| 399 |
+
template<class T, class charT = char, class traits = char_traits<charT>>
|
| 400 |
+
class ostream_iterator;
|
| 401 |
+
|
| 402 |
+
template<class charT, class traits = char_traits<charT>>
|
| 403 |
+
class istreambuf_iterator;
|
| 404 |
+
template<class charT, class traits>
|
| 405 |
+
bool operator==(const istreambuf_iterator<charT,traits>& a,
|
| 406 |
+
const istreambuf_iterator<charT,traits>& b);
|
| 407 |
+
|
| 408 |
+
template<class charT, class traits = char_traits<charT>>
|
| 409 |
+
class ostreambuf_iterator;
|
| 410 |
+
|
| 411 |
+
// [iterator.range], range access
|
| 412 |
+
template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
|
| 413 |
+
template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
|
| 414 |
+
template<class C> constexpr auto end(C& c) -> decltype(c.end());
|
| 415 |
+
template<class C> constexpr auto end(const C& c) -> decltype(c.end());
|
| 416 |
+
template<class T, size_t N> constexpr T* begin(T (&array)[N]) noexcept;
|
| 417 |
+
template<class T, size_t N> constexpr T* end(T (&array)[N]) noexcept;
|
| 418 |
+
template<class C> constexpr auto cbegin(const C& c) noexcept(noexcept(std::begin(c)))
|
| 419 |
+
-> decltype(std::begin(c));
|
| 420 |
+
template<class C> constexpr auto cend(const C& c) noexcept(noexcept(std::end(c)))
|
| 421 |
+
-> decltype(std::end(c));
|
| 422 |
+
template<class C> constexpr auto rbegin(C& c) -> decltype(c.rbegin());
|
| 423 |
+
template<class C> constexpr auto rbegin(const C& c) -> decltype(c.rbegin());
|
| 424 |
+
template<class C> constexpr auto rend(C& c) -> decltype(c.rend());
|
| 425 |
+
template<class C> constexpr auto rend(const C& c) -> decltype(c.rend());
|
| 426 |
+
template<class T, size_t N> constexpr reverse_iterator<T*> rbegin(T (&array)[N]);
|
| 427 |
+
template<class T, size_t N> constexpr reverse_iterator<T*> rend(T (&array)[N]);
|
| 428 |
+
template<class E> constexpr reverse_iterator<const E*> rbegin(initializer_list<E> il);
|
| 429 |
+
template<class E> constexpr reverse_iterator<const E*> rend(initializer_list<E> il);
|
| 430 |
+
template<class C> constexpr auto crbegin(const C& c) -> decltype(std::rbegin(c));
|
| 431 |
+
template<class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
|
| 432 |
+
|
| 433 |
+
template<class C> constexpr auto size(const C& c) -> decltype(c.size());
|
| 434 |
+
template<class T, size_t N> constexpr size_t size(const T (&array)[N]) noexcept;
|
| 435 |
+
template<class C> constexpr auto ssize(const C& c)
|
| 436 |
+
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
|
| 437 |
+
template<class T, ptrdiff_t N> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept;
|
| 438 |
+
template<class C> [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());
|
| 439 |
+
template<class T, size_t N> [[nodiscard]] constexpr bool empty(const T (&array)[N]) noexcept;
|
| 440 |
+
template<class E> [[nodiscard]] constexpr bool empty(initializer_list<E> il) noexcept;
|
| 441 |
+
template<class C> constexpr auto data(C& c) -> decltype(c.data());
|
| 442 |
+
template<class C> constexpr auto data(const C& c) -> decltype(c.data());
|
| 443 |
+
template<class T, size_t N> constexpr T* data(T (&array)[N]) noexcept;
|
| 444 |
+
template<class E> constexpr const E* data(initializer_list<E> il) noexcept;
|
| 445 |
+
}
|
| 446 |
+
```
|
| 447 |
+
|
| 448 |
## Iterator requirements <a id="iterator.requirements">[[iterator.requirements]]</a>
|
| 449 |
|
| 450 |
### In general <a id="iterator.requirements.general">[[iterator.requirements.general]]</a>
|
| 451 |
|
| 452 |
Iterators are a generalization of pointers that allow a C++ program to
|
| 453 |
+
work with different data structures (for example, containers and ranges)
|
| 454 |
+
in a uniform manner. To be able to construct template algorithms that
|
| 455 |
+
work correctly and efficiently on different types of data structures,
|
| 456 |
+
the library formalizes not just the interfaces but also the semantics
|
| 457 |
+
and complexity assumptions of iterators. An input iterator `i` supports
|
| 458 |
+
the expression `*i`, resulting in a value of some object type `T`,
|
| 459 |
+
called the *value type* of the iterator. An output iterator `i` has a
|
| 460 |
+
non-empty set of types that are `indirectly_writable` to the iterator;
|
| 461 |
+
for each such type `T`, the expression `*i = o` is valid where `o` is a
|
| 462 |
+
value of type `T`. For every iterator type `X`, there is a corresponding
|
| 463 |
+
signed integer-like type [[iterator.concept.winc]] called the
|
| 464 |
+
*difference type* of the iterator.
|
|
|
|
|
|
|
| 465 |
|
| 466 |
+
Since iterators are an abstraction of pointers, their semantics are a
|
| 467 |
generalization of most of the semantics of pointers in C++. This ensures
|
| 468 |
that every function template that takes iterators works as well with
|
| 469 |
+
regular pointers. This document defines six categories of iterators,
|
| 470 |
+
according to the operations defined on them: *input iterators*, *output
|
| 471 |
+
iterators*, *forward iterators*, *bidirectional iterators*, *random
|
| 472 |
+
access iterators*, and *contiguous iterators*, as shown in
|
| 473 |
+
[[iterators.relations]].
|
| 474 |
|
| 475 |
+
**Table: Relations among iterator categories** <a id="iterators.relations">[iterators.relations]</a>
|
| 476 |
|
| 477 |
+
| | | | | |
|
| 478 |
+
| -------------- | ------------------------------- | ------------------------------- | ------------------------- | ------------------------ |
|
| 479 |
+
| **Contiguous** | $\rightarrow$ **Random Access** | $\rightarrow$ **Bidirectional** | $\rightarrow$ **Forward** | $\rightarrow$ **Input** |
|
| 480 |
+
| | | | | $\rightarrow$ **Output** |
|
| 481 |
|
| 482 |
|
| 483 |
+
The six categories of iterators correspond to the iterator concepts
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
|
| 485 |
+
- `input_iterator` [[iterator.concept.input]],
|
| 486 |
+
- `output_iterator` [[iterator.concept.output]],
|
| 487 |
+
- `forward_iterator` [[iterator.concept.forward]],
|
| 488 |
+
- `bidirectional_iterator` [[iterator.concept.bidir]]
|
| 489 |
+
- `random_access_iterator` [[iterator.concept.random.access]], and
|
| 490 |
+
- `contiguous_iterator` [[iterator.concept.contiguous]],
|
| 491 |
+
|
| 492 |
+
respectively. The generic term *iterator* refers to any type that models
|
| 493 |
+
the `input_or_output_iterator` concept [[iterator.concept.iterator]].
|
| 494 |
+
|
| 495 |
+
Forward iterators meet all the requirements of input iterators and can
|
| 496 |
+
be used whenever an input iterator is specified; Bidirectional iterators
|
| 497 |
+
also meet all the requirements of forward iterators and can be used
|
| 498 |
+
whenever a forward iterator is specified; Random access iterators also
|
| 499 |
+
meet all the requirements of bidirectional iterators and can be used
|
| 500 |
+
whenever a bidirectional iterator is specified; Contiguous iterators
|
| 501 |
+
also meet all the requirements of random access iterators and can be
|
| 502 |
+
used whenever a random access iterator is specified.
|
| 503 |
+
|
| 504 |
+
Iterators that further meet the requirements of output iterators are
|
| 505 |
called *mutable iterators*. Nonmutable iterators are referred to as
|
| 506 |
*constant iterators*.
|
| 507 |
|
| 508 |
In addition to the requirements in this subclause, the nested
|
| 509 |
*typedef-name*s specified in [[iterator.traits]] shall be provided for
|
|
|
|
| 511 |
|
| 512 |
[*Note 1*: Either the iterator type must provide the *typedef-name*s
|
| 513 |
directly (in which case `iterator_traits` pick them up automatically),
|
| 514 |
or an `iterator_traits` specialization must provide them. — *end note*]
|
| 515 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 516 |
Just as a regular pointer to an array guarantees that there is a pointer
|
| 517 |
value pointing past the last element of the array, so for any iterator
|
| 518 |
type there is an iterator value that points past the last element of a
|
| 519 |
+
corresponding sequence. Such a value is called a *past-the-end value*.
|
| 520 |
Values of an iterator `i` for which the expression `*i` is defined are
|
| 521 |
called *dereferenceable*. The library never assumes that past-the-end
|
| 522 |
values are dereferenceable. Iterators can also have singular values that
|
| 523 |
are not associated with any sequence.
|
| 524 |
|
|
|
|
| 527 |
a pointer. — *end example*]
|
| 528 |
|
| 529 |
Results of most expressions are undefined for singular values; the only
|
| 530 |
exceptions are destroying an iterator that holds a singular value, the
|
| 531 |
assignment of a non-singular value to an iterator that holds a singular
|
| 532 |
+
value, and, for iterators that meet the *Cpp17DefaultConstructible*
|
| 533 |
requirements, using a value-initialized iterator as the source of a copy
|
| 534 |
or move operation.
|
| 535 |
|
| 536 |
+
[*Note 2*: This guarantee is not offered for default-initialization,
|
| 537 |
although the distinction only matters for types with trivial default
|
| 538 |
constructors such as pointers or aggregates holding
|
| 539 |
pointers. — *end note*]
|
| 540 |
|
| 541 |
In these cases the singular value is overwritten the same way as any
|
| 542 |
other value. Dereferenceable values are always non-singular.
|
| 543 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 544 |
Most of the library’s algorithmic templates that operate on data
|
| 545 |
+
structures have interfaces that use ranges. A *range* is an iterator and
|
| 546 |
+
a *sentinel* that designate the beginning and end of the computation, or
|
| 547 |
+
an iterator and a count that designate the beginning and the number of
|
| 548 |
+
elements to which the computation is to be applied.[^1]
|
| 549 |
+
|
| 550 |
+
An iterator and a sentinel denoting a range are comparable. A range
|
| 551 |
+
\[`i`, `s`) is empty if `i == s`; otherwise, \[`i`, `s`) refers to the
|
| 552 |
+
elements in the data structure starting with the element pointed to by
|
| 553 |
+
`i` and up to but not including the element, if any, pointed to by the
|
| 554 |
+
first iterator `j` such that `j == s`.
|
| 555 |
+
|
| 556 |
+
A sentinel `s` is called *reachable from* an iterator `i` if and only if
|
| 557 |
+
there is a finite sequence of applications of the expression `++i` that
|
| 558 |
+
makes `i == s`. If `s` is reachable from `i`, \[`i`, `s`) denotes a
|
| 559 |
+
valid range.
|
| 560 |
+
|
| 561 |
+
A *counted range* `i`+\[0, `n`) is empty if `n == 0`; otherwise,
|
| 562 |
+
`i`+\[0, `n`) refers to the `n` elements in the data structure starting
|
| 563 |
+
with the element pointed to by `i` and up to but not including the
|
| 564 |
+
element, if any, pointed to by the result of `n` applications of `++i`.
|
| 565 |
+
A counted range `i`+\[0, `n`) is valid if and only if `n == 0`; or `n`
|
| 566 |
+
is positive, `i` is dereferenceable, and `++i`+\[0, `-``-``n`) is valid.
|
| 567 |
+
|
| 568 |
+
The result of the application of library functions to invalid ranges is
|
| 569 |
+
undefined.
|
| 570 |
|
| 571 |
All the categories of iterators require only those functions that are
|
| 572 |
realizable for a given category in constant time (amortized). Therefore,
|
| 573 |
+
requirement tables and concept definitions for the iterators do not
|
| 574 |
+
specify complexity.
|
| 575 |
|
| 576 |
+
Destruction of a non-forward iterator may invalidate pointers and
|
| 577 |
+
references previously obtained from that iterator.
|
| 578 |
|
| 579 |
+
An *invalid iterator* is an iterator that may be singular.[^2]
|
| 580 |
+
|
| 581 |
+
Iterators are called *constexpr iterators* if all operations provided to
|
| 582 |
+
meet iterator category requirements are constexpr functions.
|
| 583 |
+
|
| 584 |
+
[*Note 3*: For example, the types “pointer to `int`” and
|
| 585 |
+
`reverse_iterator<int*>` are constexpr iterators. — *end note*]
|
| 586 |
+
|
| 587 |
+
### Associated types <a id="iterator.assoc.types">[[iterator.assoc.types]]</a>
|
| 588 |
+
|
| 589 |
+
#### Incrementable traits <a id="incrementable.traits">[[incrementable.traits]]</a>
|
| 590 |
+
|
| 591 |
+
To implement algorithms only in terms of incrementable types, it is
|
| 592 |
+
often necessary to determine the difference type that corresponds to a
|
| 593 |
+
particular incrementable type. Accordingly, it is required that if `WI`
|
| 594 |
+
is the name of a type that models the `weakly_incrementable` concept
|
| 595 |
+
[[iterator.concept.winc]], the type
|
| 596 |
+
|
| 597 |
+
``` cpp
|
| 598 |
+
iter_difference_t<WI>
|
| 599 |
+
```
|
| 600 |
+
|
| 601 |
+
be defined as the incrementable type’s difference type.
|
| 602 |
+
|
| 603 |
+
``` cpp
|
| 604 |
+
namespace std {
|
| 605 |
+
template<class> struct incrementable_traits { };
|
| 606 |
+
|
| 607 |
+
template<class T>
|
| 608 |
+
requires is_object_v<T>
|
| 609 |
+
struct incrementable_traits<T*> {
|
| 610 |
+
using difference_type = ptrdiff_t;
|
| 611 |
+
};
|
| 612 |
+
|
| 613 |
+
template<class I>
|
| 614 |
+
struct incrementable_traits<const I>
|
| 615 |
+
: incrementable_traits<I> { };
|
| 616 |
+
|
| 617 |
+
template<class T>
|
| 618 |
+
requires requires { typename T::difference_type; }
|
| 619 |
+
struct incrementable_traits<T> {
|
| 620 |
+
using difference_type = typename T::difference_type;
|
| 621 |
+
};
|
| 622 |
+
|
| 623 |
+
template<class T>
|
| 624 |
+
requires (!requires { typename T::difference_type; } &&
|
| 625 |
+
requires(const T& a, const T& b) { { a - b } -> integral; })
|
| 626 |
+
struct incrementable_traits<T> {
|
| 627 |
+
using difference_type = make_signed_t<decltype(declval<T>() - declval<T>())>;
|
| 628 |
+
};
|
| 629 |
+
|
| 630 |
+
template<class T>
|
| 631 |
+
using iter_difference_t = see below;
|
| 632 |
+
}
|
| 633 |
+
```
|
| 634 |
+
|
| 635 |
+
Let R_`I` be `remove_cvref_t<I>`. The type `iter_difference_t<I>`
|
| 636 |
+
denotes
|
| 637 |
+
|
| 638 |
+
- `incrementable_traits<R_I>::difference_type` if `iterator_traits<R_I>`
|
| 639 |
+
names a specialization generated from the primary template, and
|
| 640 |
+
- `iterator_traits<R_I>::difference_type` otherwise.
|
| 641 |
+
|
| 642 |
+
Users may specialize `incrementable_traits` on program-defined types.
|
| 643 |
+
|
| 644 |
+
#### Indirectly readable traits <a id="readable.traits">[[readable.traits]]</a>
|
| 645 |
+
|
| 646 |
+
To implement algorithms only in terms of indirectly readable types, it
|
| 647 |
+
is often necessary to determine the value type that corresponds to a
|
| 648 |
+
particular indirectly readable type. Accordingly, it is required that if
|
| 649 |
+
`R` is the name of a type that models the `indirectly_readable` concept
|
| 650 |
+
[[iterator.concept.readable]], the type
|
| 651 |
+
|
| 652 |
+
``` cpp
|
| 653 |
+
iter_value_t<R>
|
| 654 |
+
```
|
| 655 |
+
|
| 656 |
+
be defined as the indirectly readable type’s value type.
|
| 657 |
+
|
| 658 |
+
``` cpp
|
| 659 |
+
template<class> struct cond-value-type { }; // exposition only
|
| 660 |
+
template<class T>
|
| 661 |
+
requires is_object_v<T>
|
| 662 |
+
struct cond-value-type<T> {
|
| 663 |
+
using value_type = remove_cv_t<T>;
|
| 664 |
+
};
|
| 665 |
+
|
| 666 |
+
template<class> struct indirectly_readable_traits { };
|
| 667 |
+
|
| 668 |
+
template<class T>
|
| 669 |
+
struct indirectly_readable_traits<T*>
|
| 670 |
+
: cond-value-type<T> { };
|
| 671 |
+
|
| 672 |
+
template<class I>
|
| 673 |
+
requires is_array_v<I>
|
| 674 |
+
struct indirectly_readable_traits<I> {
|
| 675 |
+
using value_type = remove_cv_t<remove_extent_t<I>>;
|
| 676 |
+
};
|
| 677 |
+
|
| 678 |
+
template<class I>
|
| 679 |
+
struct indirectly_readable_traits<const I>
|
| 680 |
+
: indirectly_readable_traits<I> { };
|
| 681 |
+
|
| 682 |
+
template<class T>
|
| 683 |
+
requires requires { typename T::value_type; }
|
| 684 |
+
struct indirectly_readable_traits<T>
|
| 685 |
+
: cond-value-type<typename T::value_type> { };
|
| 686 |
+
|
| 687 |
+
template<class T>
|
| 688 |
+
requires requires { typename T::element_type; }
|
| 689 |
+
struct indirectly_readable_traits<T>
|
| 690 |
+
: cond-value-type<typename T::element_type> { };
|
| 691 |
+
|
| 692 |
+
template<class T> using iter_value_t = see below;
|
| 693 |
+
```
|
| 694 |
+
|
| 695 |
+
Let R_`I` be `remove_cvref_t<I>`. The type `iter_value_t<I>` denotes
|
| 696 |
+
|
| 697 |
+
- `indirectly_readable_traits<R_I>::value_type` if
|
| 698 |
+
`iterator_traits<R_I>` names a specialization generated from the
|
| 699 |
+
primary template, and
|
| 700 |
+
- `iterator_traits<R_I>::value_type` otherwise.
|
| 701 |
+
|
| 702 |
+
Class template `indirectly_readable_traits` may be specialized on
|
| 703 |
+
program-defined types.
|
| 704 |
+
|
| 705 |
+
[*Note 1*: Some legacy output iterators define a nested type named
|
| 706 |
+
`value_type` that is an alias for `void`. These types are not
|
| 707 |
+
`indirectly_readable` and have no associated value types. — *end note*]
|
| 708 |
+
|
| 709 |
+
[*Note 2*: Smart pointers like `shared_ptr<int>` are
|
| 710 |
+
`indirectly_readable` and have an associated value type, but a smart
|
| 711 |
+
pointer like `shared_ptr<void>` is not `indirectly_readable` and has no
|
| 712 |
+
associated value type. — *end note*]
|
| 713 |
+
|
| 714 |
+
#### Iterator traits <a id="iterator.traits">[[iterator.traits]]</a>
|
| 715 |
+
|
| 716 |
+
To implement algorithms only in terms of iterators, it is sometimes
|
| 717 |
+
necessary to determine the iterator category that corresponds to a
|
| 718 |
+
particular iterator type. Accordingly, it is required that if `I` is the
|
| 719 |
+
type of an iterator, the type
|
| 720 |
+
|
| 721 |
+
``` cpp
|
| 722 |
+
iterator_traits<I>::iterator_category
|
| 723 |
+
```
|
| 724 |
+
|
| 725 |
+
be defined as the iterator’s iterator category. In addition, the types
|
| 726 |
+
|
| 727 |
+
``` cpp
|
| 728 |
+
iterator_traits<I>::pointer
|
| 729 |
+
iterator_traits<I>::reference
|
| 730 |
+
```
|
| 731 |
+
|
| 732 |
+
shall be defined as the iterator’s pointer and reference types; that is,
|
| 733 |
+
for an iterator object `a` of class type, the same type as
|
| 734 |
+
`decltype(a.operator->())` and `decltype(*a)`, respectively. The type
|
| 735 |
+
`iterator_traits<I>::pointer` shall be `void` for an iterator of class
|
| 736 |
+
type `I` that does not support `operator->`. Additionally, in the case
|
| 737 |
+
of an output iterator, the types
|
| 738 |
+
|
| 739 |
+
``` cpp
|
| 740 |
+
iterator_traits<I>::value_type
|
| 741 |
+
iterator_traits<I>::difference_type
|
| 742 |
+
iterator_traits<I>::reference
|
| 743 |
+
```
|
| 744 |
+
|
| 745 |
+
may be defined as `void`.
|
| 746 |
+
|
| 747 |
+
The definitions in this subclause make use of the following
|
| 748 |
+
exposition-only concepts:
|
| 749 |
+
|
| 750 |
+
``` cpp
|
| 751 |
+
template<class I>
|
| 752 |
+
concept cpp17-iterator =
|
| 753 |
+
copyable<I> && requires(I i) {
|
| 754 |
+
{ *i } -> can-reference;
|
| 755 |
+
{ ++i } -> same_as<I&>;
|
| 756 |
+
{ *i++ } -> can-reference;
|
| 757 |
+
};
|
| 758 |
+
|
| 759 |
+
template<class I>
|
| 760 |
+
concept cpp17-input-iterator =
|
| 761 |
+
cpp17-iterator<I> && equality_comparable<I> && requires(I i) {
|
| 762 |
+
typename incrementable_traits<I>::difference_type;
|
| 763 |
+
typename indirectly_readable_traits<I>::value_type;
|
| 764 |
+
typename common_reference_t<iter_reference_t<I>&&,
|
| 765 |
+
typename indirectly_readable_traits<I>::value_type&>;
|
| 766 |
+
typename common_reference_t<decltype(*i++)&&,
|
| 767 |
+
typename indirectly_readable_traits<I>::value_type&>;
|
| 768 |
+
requires signed_integral<typename incrementable_traits<I>::difference_type>;
|
| 769 |
+
};
|
| 770 |
+
|
| 771 |
+
template<class I>
|
| 772 |
+
concept cpp17-forward-iterator =
|
| 773 |
+
cpp17-input-iterator<I> && constructible_from<I> &&
|
| 774 |
+
is_lvalue_reference_v<iter_reference_t<I>> &&
|
| 775 |
+
same_as<remove_cvref_t<iter_reference_t<I>>,
|
| 776 |
+
typename indirectly_readable_traits<I>::value_type> &&
|
| 777 |
+
requires(I i) {
|
| 778 |
+
{ i++ } -> convertible_to<const I&>;
|
| 779 |
+
{ *i++ } -> same_as<iter_reference_t<I>>;
|
| 780 |
+
};
|
| 781 |
+
|
| 782 |
+
template<class I>
|
| 783 |
+
concept cpp17-bidirectional-iterator =
|
| 784 |
+
cpp17-forward-iterator<I> && requires(I i) {
|
| 785 |
+
{ --i } -> same_as<I&>;
|
| 786 |
+
{ i-- } -> convertible_to<const I&>;
|
| 787 |
+
{ *i-- } -> same_as<iter_reference_t<I>>;
|
| 788 |
+
};
|
| 789 |
+
|
| 790 |
+
template<class I>
|
| 791 |
+
concept cpp17-random-access-iterator =
|
| 792 |
+
cpp17-bidirectional-iterator<I> && totally_ordered<I> &&
|
| 793 |
+
requires(I i, typename incrementable_traits<I>::difference_type n) {
|
| 794 |
+
{ i += n } -> same_as<I&>;
|
| 795 |
+
{ i -= n } -> same_as<I&>;
|
| 796 |
+
{ i + n } -> same_as<I>;
|
| 797 |
+
{ n + i } -> same_as<I>;
|
| 798 |
+
{ i - n } -> same_as<I>;
|
| 799 |
+
{ i - i } -> same_as<decltype(n)>;
|
| 800 |
+
{ i[n] } -> convertible_to<iter_reference_t<I>>;
|
| 801 |
+
};
|
| 802 |
+
```
|
| 803 |
+
|
| 804 |
+
The members of a specialization `iterator_traits<I>` generated from the
|
| 805 |
+
`iterator_traits` primary template are computed as follows:
|
| 806 |
+
|
| 807 |
+
- If `I` has valid [[temp.deduct]] member types `difference_type`,
|
| 808 |
+
`value_type`, `reference`, and `iterator_category`, then
|
| 809 |
+
`iterator_traits<I>` has the following publicly accessible members:
|
| 810 |
+
``` cpp
|
| 811 |
+
using iterator_category = typename I::iterator_category;
|
| 812 |
+
using value_type = typename I::value_type;
|
| 813 |
+
using difference_type = typename I::difference_type;
|
| 814 |
+
using pointer = see below;
|
| 815 |
+
using reference = typename I::reference;
|
| 816 |
+
```
|
| 817 |
+
|
| 818 |
+
If the *qualified-id* `I::pointer` is valid and denotes a type, then
|
| 819 |
+
`iterator_traits<I>::pointer` names that type; otherwise, it names
|
| 820 |
+
`void`.
|
| 821 |
+
- Otherwise, if `I` satisfies the exposition-only concept
|
| 822 |
+
`cpp17-input-iterator`, `iterator_traits<I>` has the following
|
| 823 |
+
publicly accessible members:
|
| 824 |
+
``` cpp
|
| 825 |
+
using iterator_category = see below;
|
| 826 |
+
using value_type = typename indirectly_readable_traits<I>::value_type;
|
| 827 |
+
using difference_type = typename incrementable_traits<I>::difference_type;
|
| 828 |
+
using pointer = see below;
|
| 829 |
+
using reference = see below;
|
| 830 |
+
```
|
| 831 |
+
|
| 832 |
+
- If the *qualified-id* `I::pointer` is valid and denotes a type,
|
| 833 |
+
`pointer` names that type. Otherwise, if
|
| 834 |
+
`decltype({}declval<I&>().operator->())` is well-formed, then
|
| 835 |
+
`pointer` names that type. Otherwise, `pointer` names `void`.
|
| 836 |
+
- If the *qualified-id* `I::reference` is valid and denotes a type,
|
| 837 |
+
`reference` names that type. Otherwise, `reference` names
|
| 838 |
+
`iter_reference_t<I>`.
|
| 839 |
+
- If the *qualified-id* `I::iterator_category` is valid and denotes a
|
| 840 |
+
type, `iterator_category` names that type. Otherwise,
|
| 841 |
+
`iterator_category` names:
|
| 842 |
+
- `random_access_iterator_tag` if `I` satisfies
|
| 843 |
+
`cpp17-random-access-iterator`, or otherwise
|
| 844 |
+
- `bidirectional_iterator_tag` if `I` satisfies
|
| 845 |
+
`cpp17-bidirectional-iterator`, or otherwise
|
| 846 |
+
- `forward_iterator_tag` if `I` satisfies `cpp17-forward-iterator`,
|
| 847 |
+
or otherwise
|
| 848 |
+
- `input_iterator_tag`.
|
| 849 |
+
- Otherwise, if `I` satisfies the exposition-only concept
|
| 850 |
+
`cpp17-iterator`, then `iterator_traits<I>` has the following publicly
|
| 851 |
+
accessible members:
|
| 852 |
+
``` cpp
|
| 853 |
+
using iterator_category = output_iterator_tag;
|
| 854 |
+
using value_type = void;
|
| 855 |
+
using difference_type = see below;
|
| 856 |
+
using pointer = void;
|
| 857 |
+
using reference = void;
|
| 858 |
+
```
|
| 859 |
+
|
| 860 |
+
If the *qualified-id* `incrementable_traits<I>::difference_type` is
|
| 861 |
+
valid and denotes a type, then `difference_type` names that type;
|
| 862 |
+
otherwise, it names `void`.
|
| 863 |
+
- Otherwise, `iterator_traits<I>` has no members by any of the above
|
| 864 |
+
names.
|
| 865 |
+
|
| 866 |
+
Explicit or partial specializations of `iterator_traits` may have a
|
| 867 |
+
member type `iterator_concept` that is used to indicate conformance to
|
| 868 |
+
the iterator concepts [[iterator.concepts]].
|
| 869 |
+
|
| 870 |
+
`iterator_traits` is specialized for pointers as
|
| 871 |
+
|
| 872 |
+
``` cpp
|
| 873 |
+
namespace std {
|
| 874 |
+
template<class T>
|
| 875 |
+
requires is_object_v<T>
|
| 876 |
+
struct iterator_traits<T*> {
|
| 877 |
+
using iterator_concept = contiguous_iterator_tag;
|
| 878 |
+
using iterator_category = random_access_iterator_tag;
|
| 879 |
+
using value_type = remove_cv_t<T>;
|
| 880 |
+
using difference_type = ptrdiff_t;
|
| 881 |
+
using pointer = T*;
|
| 882 |
+
using reference = T&;
|
| 883 |
+
};
|
| 884 |
+
}
|
| 885 |
+
```
|
| 886 |
+
|
| 887 |
+
[*Example 1*:
|
| 888 |
+
|
| 889 |
+
To implement a generic `reverse` function, a C++ program can do the
|
| 890 |
+
following:
|
| 891 |
+
|
| 892 |
+
``` cpp
|
| 893 |
+
template<class BI>
|
| 894 |
+
void reverse(BI first, BI last) {
|
| 895 |
+
typename iterator_traits<BI>::difference_type n =
|
| 896 |
+
distance(first, last);
|
| 897 |
+
--n;
|
| 898 |
+
while(n > 0) {
|
| 899 |
+
typename iterator_traits<BI>::value_type
|
| 900 |
+
tmp = *first;
|
| 901 |
+
*first++ = *--last;
|
| 902 |
+
*last = tmp;
|
| 903 |
+
n -= 2;
|
| 904 |
+
}
|
| 905 |
+
}
|
| 906 |
+
```
|
| 907 |
+
|
| 908 |
+
— *end example*]
|
| 909 |
+
|
| 910 |
+
### Customization points <a id="iterator.cust">[[iterator.cust]]</a>
|
| 911 |
+
|
| 912 |
+
#### `ranges::iter_move` <a id="iterator.cust.move">[[iterator.cust.move]]</a>
|
| 913 |
+
|
| 914 |
+
The name `ranges::iter_move` denotes a customization point object
|
| 915 |
+
[[customization.point.object]]. The expression `ranges::iter_move(E)`
|
| 916 |
+
for a subexpression `E` is expression-equivalent to:
|
| 917 |
+
|
| 918 |
+
- `iter_move(E)`, if `E` has class or enumeration type and
|
| 919 |
+
`iter_move(E)` is a well-formed expression when treated as an
|
| 920 |
+
unevaluated operand, with overload resolution performed in a context
|
| 921 |
+
that does not include a declaration of `ranges::iter_move` but does
|
| 922 |
+
include the declaration
|
| 923 |
+
``` cpp
|
| 924 |
+
void iter_move();
|
| 925 |
+
```
|
| 926 |
+
- Otherwise, if the expression `*E` is well-formed:
|
| 927 |
+
- if `*E` is an lvalue, `std::move(*E)`;
|
| 928 |
+
- otherwise, `*E`.
|
| 929 |
+
- Otherwise, `ranges::iter_move(E)` is ill-formed. \[*Note 1*: This case
|
| 930 |
+
can result in substitution failure when `ranges::iter_move(E)` appears
|
| 931 |
+
in the immediate context of a template instantiation. — *end note*]
|
| 932 |
+
|
| 933 |
+
If `ranges::iter_move(E)` is not equal to `*E`, the program is
|
| 934 |
+
ill-formed, no diagnostic required.
|
| 935 |
+
|
| 936 |
+
#### `ranges::iter_swap` <a id="iterator.cust.swap">[[iterator.cust.swap]]</a>
|
| 937 |
+
|
| 938 |
+
The name `ranges::iter_swap` denotes a customization point object
|
| 939 |
+
[[customization.point.object]] that exchanges the values
|
| 940 |
+
[[concept.swappable]] denoted by its arguments.
|
| 941 |
+
|
| 942 |
+
Let *`iter-exchange-move`* be the exposition-only function:
|
| 943 |
+
|
| 944 |
+
``` cpp
|
| 945 |
+
template<class X, class Y>
|
| 946 |
+
constexpr iter_value_t<X> iter-exchange-move(X&& x, Y&& y)
|
| 947 |
+
noexcept(noexcept(iter_value_t<X>(iter_move(x))) &&
|
| 948 |
+
noexcept(*x = iter_move(y)));
|
| 949 |
+
```
|
| 950 |
+
|
| 951 |
+
*Effects:* Equivalent to:
|
| 952 |
+
|
| 953 |
+
``` cpp
|
| 954 |
+
iter_value_t<X> old_value(iter_move(x));
|
| 955 |
+
*x = iter_move(y);
|
| 956 |
+
return old_value;
|
| 957 |
+
```
|
| 958 |
+
|
| 959 |
+
The expression `ranges::iter_swap(E1, E2)` for subexpressions `E1` and
|
| 960 |
+
`E2` is expression-equivalent to:
|
| 961 |
+
|
| 962 |
+
- `(void)iter_swap(E1, E2)`, if either `E1` or `E2` has class or
|
| 963 |
+
enumeration type and `iter_swap(E1, E2)` is a well-formed expression
|
| 964 |
+
with overload resolution performed in a context that includes the
|
| 965 |
+
declaration
|
| 966 |
+
``` cpp
|
| 967 |
+
template<class I1, class I2>
|
| 968 |
+
void iter_swap(I1, I2) = delete;
|
| 969 |
+
```
|
| 970 |
+
|
| 971 |
+
and does not include a declaration of `ranges::iter_swap`. If the
|
| 972 |
+
function selected by overload resolution does not exchange the values
|
| 973 |
+
denoted by `E1` and `E2`, the program is ill-formed, no diagnostic
|
| 974 |
+
required.
|
| 975 |
+
- Otherwise, if the types of `E1` and `E2` each model
|
| 976 |
+
`indirectly_readable`, and if the reference types of `E1` and `E2`
|
| 977 |
+
model `swappable_with` [[concept.swappable]], then
|
| 978 |
+
`ranges::swap(*E1, *E2)`.
|
| 979 |
+
- Otherwise, if the types `T1` and `T2` of `E1` and `E2` model
|
| 980 |
+
`indirectly_movable_storable<T1, T2>` and
|
| 981 |
+
`indirectly_movable_storable<T2, T1>`, then
|
| 982 |
+
`(void)(*E1 = iter-exchange-move(E2, E1))`, except that `E1` is
|
| 983 |
+
evaluated only once.
|
| 984 |
+
- Otherwise, `ranges::iter_swap(E1, E2)` is ill-formed. \[*Note 1*: This
|
| 985 |
+
case can result in substitution failure when
|
| 986 |
+
`ranges::iter_swap(E1, E2)` appears in the immediate context of a
|
| 987 |
+
template instantiation. — *end note*]
|
| 988 |
+
|
| 989 |
+
### Iterator concepts <a id="iterator.concepts">[[iterator.concepts]]</a>
|
| 990 |
+
|
| 991 |
+
#### General <a id="iterator.concepts.general">[[iterator.concepts.general]]</a>
|
| 992 |
+
|
| 993 |
+
For a type `I`, let `ITER_TRAITS(I)` denote the type `I` if
|
| 994 |
+
`iterator_traits<I>` names a specialization generated from the primary
|
| 995 |
+
template. Otherwise, `ITER_TRAITS(I)` denotes `iterator_traits<I>`.
|
| 996 |
+
|
| 997 |
+
- If the *qualified-id* `ITER_TRAITS(I)::iterator_concept` is valid and
|
| 998 |
+
names a type, then `ITER_CONCEPT(I)` denotes that type.
|
| 999 |
+
- Otherwise, if the *qualified-id* `ITER_TRAITS(I){}::iterator_category`
|
| 1000 |
+
is valid and names a type, then `ITER_CONCEPT(I)` denotes that type.
|
| 1001 |
+
- Otherwise, if `iterator_traits<I>` names a specialization generated
|
| 1002 |
+
from the primary template, then `ITER_CONCEPT(I)` denotes
|
| 1003 |
+
`random_access_iterator_tag`.
|
| 1004 |
+
- Otherwise, `ITER_CONCEPT(I)` does not denote a type.
|
| 1005 |
+
|
| 1006 |
+
[*Note 1*: `ITER_TRAITS` enables independent syntactic determination of
|
| 1007 |
+
an iterator’s category and concept. — *end note*]
|
| 1008 |
+
|
| 1009 |
+
[*Example 1*:
|
| 1010 |
+
|
| 1011 |
+
``` cpp
|
| 1012 |
+
struct I {
|
| 1013 |
+
using value_type = int;
|
| 1014 |
+
using difference_type = int;
|
| 1015 |
+
|
| 1016 |
+
int operator*() const;
|
| 1017 |
+
I& operator++();
|
| 1018 |
+
I operator++(int);
|
| 1019 |
+
I& operator--();
|
| 1020 |
+
I operator--(int);
|
| 1021 |
+
|
| 1022 |
+
bool operator==(I) const;
|
| 1023 |
+
bool operator!=(I) const;
|
| 1024 |
+
};
|
| 1025 |
+
```
|
| 1026 |
+
|
| 1027 |
+
`iterator_traits<I>::iterator_category` denotes `input_iterator_tag`,
|
| 1028 |
+
and `ITER_CONCEPT(I)` denotes `random_access_iterator_tag`.
|
| 1029 |
+
|
| 1030 |
+
— *end example*]
|
| 1031 |
+
|
| 1032 |
+
#### Concept <a id="iterator.concept.readable">[[iterator.concept.readable]]</a>
|
| 1033 |
+
|
| 1034 |
+
Types that are indirectly readable by applying `operator*` model the
|
| 1035 |
+
`indirectly_readable` concept, including pointers, smart pointers, and
|
| 1036 |
+
iterators.
|
| 1037 |
+
|
| 1038 |
+
``` cpp
|
| 1039 |
+
template<class In>
|
| 1040 |
+
concept indirectly-readable-impl =
|
| 1041 |
+
requires(const In in) {
|
| 1042 |
+
typename iter_value_t<In>;
|
| 1043 |
+
typename iter_reference_t<In>;
|
| 1044 |
+
typename iter_rvalue_reference_t<In>;
|
| 1045 |
+
{ *in } -> same_as<iter_reference_t<In>>;
|
| 1046 |
+
{ ranges::iter_move(in) } -> same_as<iter_rvalue_reference_t<In>>;
|
| 1047 |
+
} &&
|
| 1048 |
+
common_reference_with<iter_reference_t<In>&&, iter_value_t<In>&> &&
|
| 1049 |
+
common_reference_with<iter_reference_t<In>&&, iter_rvalue_reference_t<In>&&> &&
|
| 1050 |
+
common_reference_with<iter_rvalue_reference_t<In>&&, const iter_value_t<In>&>;
|
| 1051 |
+
```
|
| 1052 |
+
|
| 1053 |
+
``` cpp
|
| 1054 |
+
template<class In>
|
| 1055 |
+
concept indirectly_readable =
|
| 1056 |
+
indirectly-readable-impl<remove_cvref_t<In>>;
|
| 1057 |
+
```
|
| 1058 |
+
|
| 1059 |
+
Given a value `i` of type `I`, `I` models `indirectly_readable` only if
|
| 1060 |
+
the expression `*i` is equality-preserving.
|
| 1061 |
+
|
| 1062 |
+
[*Note 1*: The expression `*i` is indirectly required to be valid via
|
| 1063 |
+
the exposition-only `dereferenceable` concept
|
| 1064 |
+
[[iterator.synopsis]]. — *end note*]
|
| 1065 |
+
|
| 1066 |
+
#### Concept <a id="iterator.concept.writable">[[iterator.concept.writable]]</a>
|
| 1067 |
+
|
| 1068 |
+
The `indirectly_writable` concept specifies the requirements for writing
|
| 1069 |
+
a value into an iterator’s referenced object.
|
| 1070 |
+
|
| 1071 |
+
``` cpp
|
| 1072 |
+
template<class Out, class T>
|
| 1073 |
+
concept indirectly_writable =
|
| 1074 |
+
requires(Out&& o, T&& t) {
|
| 1075 |
+
*o = std::forward<T>(t); // not required to be equality-preserving
|
| 1076 |
+
*std::forward<Out>(o) = std::forward<T>(t); // not required to be equality-preserving
|
| 1077 |
+
const_cast<const iter_reference_t<Out>&&>(*o) =
|
| 1078 |
+
std::forward<T>(t); // not required to be equality-preserving
|
| 1079 |
+
const_cast<const iter_reference_t<Out>&&>(*std::forward<Out>(o)) =
|
| 1080 |
+
std::forward<T>(t); // not required to be equality-preserving
|
| 1081 |
+
};
|
| 1082 |
+
```
|
| 1083 |
+
|
| 1084 |
+
Let `E` be an expression such that `decltype((E))` is `T`, and let `o`
|
| 1085 |
+
be a dereferenceable object of type `Out`. `Out` and `T` model
|
| 1086 |
+
`indirectly_writable<Out, T>` only if
|
| 1087 |
+
|
| 1088 |
+
- If `Out` and `T` model
|
| 1089 |
+
`indirectly_readable<Out> && same_as<iter_value_t<Out>, decay_t<T>{>}`,
|
| 1090 |
+
then `*o` after any above assignment is equal to the value of `E`
|
| 1091 |
+
before the assignment.
|
| 1092 |
+
|
| 1093 |
+
After evaluating any above assignment expression, `o` is not required to
|
| 1094 |
+
be dereferenceable.
|
| 1095 |
+
|
| 1096 |
+
If `E` is an xvalue [[basic.lval]], the resulting state of the object it
|
| 1097 |
+
denotes is valid but unspecified [[lib.types.movedfrom]].
|
| 1098 |
+
|
| 1099 |
+
[*Note 1*: The only valid use of an `operator*` is on the left side of
|
| 1100 |
+
the assignment statement. Assignment through the same value of the
|
| 1101 |
+
indirectly writable type happens only once. — *end note*]
|
| 1102 |
+
|
| 1103 |
+
[*Note 2*: `indirectly_writable` has the awkward `const_cast`
|
| 1104 |
+
expressions to reject iterators with prvalue non-proxy reference types
|
| 1105 |
+
that permit rvalue assignment but do not also permit `const` rvalue
|
| 1106 |
+
assignment. Consequently, an iterator type `I` that returns
|
| 1107 |
+
`std::string` by value does not model
|
| 1108 |
+
`indirectly_writable<I, std::string>`. — *end note*]
|
| 1109 |
+
|
| 1110 |
+
#### Concept <a id="iterator.concept.winc">[[iterator.concept.winc]]</a>
|
| 1111 |
+
|
| 1112 |
+
The `weakly_incrementable` concept specifies the requirements on types
|
| 1113 |
+
that can be incremented with the pre- and post-increment operators. The
|
| 1114 |
+
increment operations are not required to be equality-preserving, nor is
|
| 1115 |
+
the type required to be `equality_comparable`.
|
| 1116 |
+
|
| 1117 |
+
``` cpp
|
| 1118 |
+
template<class T>
|
| 1119 |
+
inline constexpr bool is-integer-like = see below; // exposition only
|
| 1120 |
+
|
| 1121 |
+
template<class T>
|
| 1122 |
+
inline constexpr bool is-signed-integer-like = see below; // exposition only
|
| 1123 |
+
|
| 1124 |
+
template<class I>
|
| 1125 |
+
concept weakly_incrementable =
|
| 1126 |
+
default_initializable<I> && movable<I> &&
|
| 1127 |
+
requires(I i) {
|
| 1128 |
+
typename iter_difference_t<I>;
|
| 1129 |
+
requires is-signed-integer-like<iter_difference_t<I>>;
|
| 1130 |
+
{ ++i } -> same_as<I&>; // not required to be equality-preserving
|
| 1131 |
+
i++; // not required to be equality-preserving
|
| 1132 |
+
};
|
| 1133 |
+
```
|
| 1134 |
+
|
| 1135 |
+
A type `I` is an *integer-class type* if it is in a set of
|
| 1136 |
+
implementation-defined class types that behave as integer types do, as
|
| 1137 |
+
defined in below.
|
| 1138 |
+
|
| 1139 |
+
The range of representable values of an integer-class type is the
|
| 1140 |
+
continuous set of values over which it is defined. The values 0 and 1
|
| 1141 |
+
are part of the range of every integer-class type. If any negative
|
| 1142 |
+
numbers are part of the range, the type is a
|
| 1143 |
+
*signed-integer-class type*; otherwise, it is an
|
| 1144 |
+
*unsigned-integer-class type*.
|
| 1145 |
+
|
| 1146 |
+
For every integer-class type `I`, let `B(I)` be a hypothetical extended
|
| 1147 |
+
integer type of the same signedness with the smallest width
|
| 1148 |
+
[[basic.fundamental]] capable of representing the same range of values.
|
| 1149 |
+
The width of `I` is equal to the width of `B(I)`.
|
| 1150 |
+
|
| 1151 |
+
Let `a` and `b` be objects of integer-class type `I`, let `x` and `y` be
|
| 1152 |
+
objects of type `B(I)` as described above that represent the same values
|
| 1153 |
+
as `a` and `b` respectively, and let `c` be an lvalue of any integral
|
| 1154 |
+
type.
|
| 1155 |
+
|
| 1156 |
+
- For every unary operator `@` for which the expression `@x` is
|
| 1157 |
+
well-formed, `@a` shall also be well-formed and have the same value,
|
| 1158 |
+
effects, and value category as `@x` provided that value is
|
| 1159 |
+
representable by `I`. If `@x` has type `bool`, so too does `@a`; if
|
| 1160 |
+
`@x` has type `B(I)`, then `@a` has type `I`.
|
| 1161 |
+
- For every assignment operator `@=` for which `c @= x` is well-formed,
|
| 1162 |
+
`c @= a` shall also be well-formed and shall have the same value and
|
| 1163 |
+
effects as `c @= x`. The expression `c @= a` shall be an lvalue
|
| 1164 |
+
referring to `c`.
|
| 1165 |
+
- For every binary operator `@` for which `x @ y` is well-formed,
|
| 1166 |
+
`a @ b` shall also be well-formed and shall have the same value,
|
| 1167 |
+
effects, and value category as `x @ y` provided that value is
|
| 1168 |
+
representable by `I`. If `x @ y` has type `bool`, so too does `a @ b`;
|
| 1169 |
+
if `x @ y` has type `B(I)`, then `a @ b` has type `I`.
|
| 1170 |
+
|
| 1171 |
+
Expressions of integer-class type are explicitly convertible to any
|
| 1172 |
+
integral type. Expressions of integral type are both implicitly and
|
| 1173 |
+
explicitly convertible to any integer-class type. Conversions between
|
| 1174 |
+
integral and integer-class types do not exit via an exception.
|
| 1175 |
+
|
| 1176 |
+
An expression `E` of integer-class type `I` is contextually convertible
|
| 1177 |
+
to `bool` as if by `bool(E != I(0))`.
|
| 1178 |
+
|
| 1179 |
+
All integer-class types model `regular` [[concepts.object]] and
|
| 1180 |
+
`totally_ordered` [[concept.totallyordered]].
|
| 1181 |
+
|
| 1182 |
+
A value-initialized object of integer-class type has value 0.
|
| 1183 |
+
|
| 1184 |
+
For every (possibly cv-qualified) integer-class type `I`,
|
| 1185 |
+
`numeric_limits<I>` is specialized such that:
|
| 1186 |
+
|
| 1187 |
+
- `numeric_limits<I>::is_specialized` is `true`,
|
| 1188 |
+
- `numeric_limits<I>::is_signed` is `true` if and only if `I` is a
|
| 1189 |
+
signed-integer-class type,
|
| 1190 |
+
- `numeric_limits<I>::is_integer` is `true`,
|
| 1191 |
+
- `numeric_limits<I>::is_exact` is `true`,
|
| 1192 |
+
- `numeric_limits<I>::digits` is equal to the width of the integer-class
|
| 1193 |
+
type,
|
| 1194 |
+
- `numeric_limits<I>::digits10` is equal to
|
| 1195 |
+
`static_cast<int>(digits * log10(2))`, and
|
| 1196 |
+
- `numeric_limits<I>::min()` and `numeric_limits<I>::max()` return the
|
| 1197 |
+
lowest and highest representable values of `I`, respectively, and
|
| 1198 |
+
`numeric_limits<I>::lowest()` returns `numeric_limits<I>::{}min()`.
|
| 1199 |
+
|
| 1200 |
+
A type `I` is *integer-like* if it models `integral<I>` or if it is an
|
| 1201 |
+
integer-class type. A type `I` is *signed-integer-like* if it models
|
| 1202 |
+
`signed_integral<I>` or if it is a signed-integer-class type. A type `I`
|
| 1203 |
+
is *unsigned-integer-like* if it models `unsigned_integral<I>` or if it
|
| 1204 |
+
is an unsigned-integer-class type.
|
| 1205 |
+
|
| 1206 |
+
`is-integer-like<I>` is `true` if and only if `I` is an integer-like
|
| 1207 |
+
type. `is-signed-integer-like<I>` is `true` if and only if I is a
|
| 1208 |
+
signed-integer-like type.
|
| 1209 |
+
|
| 1210 |
+
Let `i` be an object of type `I`. When `i` is in the domain of both pre-
|
| 1211 |
+
and post-increment, `i` is said to be *incrementable*. `I` models
|
| 1212 |
+
`weakly_incrementable<I>` only if
|
| 1213 |
+
|
| 1214 |
+
- The expressions `++i` and `i++` have the same domain.
|
| 1215 |
+
- If `i` is incrementable, then both `++i` and `i++` advance `i` to the
|
| 1216 |
+
next element.
|
| 1217 |
+
- If `i` is incrementable, then `addressof(++i)` is equal to
|
| 1218 |
+
`addressof(i)`.
|
| 1219 |
+
|
| 1220 |
+
[*Note 1*: For `weakly_incrementable` types, `a` equals `b` does not
|
| 1221 |
+
imply that `++a` equals `++b`. (Equality does not guarantee the
|
| 1222 |
+
substitution property or referential transparency.) Algorithms on weakly
|
| 1223 |
+
incrementable types should never attempt to pass through the same
|
| 1224 |
+
incrementable value twice. They should be single-pass algorithms. These
|
| 1225 |
+
algorithms can be used with istreams as the source of the input data
|
| 1226 |
+
through the `istream_iterator` class template. — *end note*]
|
| 1227 |
+
|
| 1228 |
+
#### Concept <a id="iterator.concept.inc">[[iterator.concept.inc]]</a>
|
| 1229 |
+
|
| 1230 |
+
The `incrementable` concept specifies requirements on types that can be
|
| 1231 |
+
incremented with the pre- and post-increment operators. The increment
|
| 1232 |
+
operations are required to be equality-preserving, and the type is
|
| 1233 |
+
required to be `equality_comparable`.
|
| 1234 |
+
|
| 1235 |
+
[*Note 1*: This supersedes the annotations on the increment expressions
|
| 1236 |
+
in the definition of `weakly_incrementable`. — *end note*]
|
| 1237 |
+
|
| 1238 |
+
``` cpp
|
| 1239 |
+
template<class I>
|
| 1240 |
+
concept incrementable =
|
| 1241 |
+
regular<I> &&
|
| 1242 |
+
weakly_incrementable<I> &&
|
| 1243 |
+
requires(I i) {
|
| 1244 |
+
{ i++ } -> same_as<I>;
|
| 1245 |
+
};
|
| 1246 |
+
```
|
| 1247 |
+
|
| 1248 |
+
Let `a` and `b` be incrementable objects of type `I`. `I` models
|
| 1249 |
+
`incrementable` only if
|
| 1250 |
+
|
| 1251 |
+
- If `bool(a == b)` then `bool(a++ == b)`.
|
| 1252 |
+
- If `bool(a == b)` then `bool(((void)a++, a) == ++b)`.
|
| 1253 |
+
|
| 1254 |
+
[*Note 2*: The requirement that `a` equals `b` implies `++a` equals
|
| 1255 |
+
`++b` (which is not true for weakly incrementable types) allows the use
|
| 1256 |
+
of multi-pass one-directional algorithms with types that model
|
| 1257 |
+
`incrementable`. — *end note*]
|
| 1258 |
+
|
| 1259 |
+
#### Concept <a id="iterator.concept.iterator">[[iterator.concept.iterator]]</a>
|
| 1260 |
+
|
| 1261 |
+
The `input_or_output_iterator` concept forms the basis of the iterator
|
| 1262 |
+
concept taxonomy; every iterator models `input_or_output_iterator`. This
|
| 1263 |
+
concept specifies operations for dereferencing and incrementing an
|
| 1264 |
+
iterator. Most algorithms will require additional operations to compare
|
| 1265 |
+
iterators with sentinels [[iterator.concept.sentinel]], to read
|
| 1266 |
+
[[iterator.concept.input]] or write [[iterator.concept.output]] values,
|
| 1267 |
+
or to provide a richer set of iterator movements (
|
| 1268 |
+
[[iterator.concept.forward]], [[iterator.concept.bidir]],
|
| 1269 |
+
[[iterator.concept.random.access]]).
|
| 1270 |
+
|
| 1271 |
+
``` cpp
|
| 1272 |
+
template<class I>
|
| 1273 |
+
concept input_or_output_iterator =
|
| 1274 |
+
requires(I i) {
|
| 1275 |
+
{ *i } -> can-reference;
|
| 1276 |
+
} &&
|
| 1277 |
+
weakly_incrementable<I>;
|
| 1278 |
+
```
|
| 1279 |
+
|
| 1280 |
+
[*Note 1*: Unlike the *Cpp17Iterator* requirements, the
|
| 1281 |
+
`input_or_output_iterator` concept does not require
|
| 1282 |
+
copyability. — *end note*]
|
| 1283 |
+
|
| 1284 |
+
#### Concept <a id="iterator.concept.sentinel">[[iterator.concept.sentinel]]</a>
|
| 1285 |
+
|
| 1286 |
+
The `sentinel_for` concept specifies the relationship between an
|
| 1287 |
+
`input_or_output_iterator` type and a `semiregular` type whose values
|
| 1288 |
+
denote a range.
|
| 1289 |
+
|
| 1290 |
+
``` cpp
|
| 1291 |
+
template<class S, class I>
|
| 1292 |
+
concept sentinel_for =
|
| 1293 |
+
semiregular<S> &&
|
| 1294 |
+
input_or_output_iterator<I> &&
|
| 1295 |
+
weakly-equality-comparable-with<S, I>; // See [concept.equalitycomparable]
|
| 1296 |
+
```
|
| 1297 |
+
|
| 1298 |
+
Let `s` and `i` be values of type `S` and `I` such that \[`i`, `s`)
|
| 1299 |
+
denotes a range. Types `S` and `I` model `sentinel_for<S, I>` only if
|
| 1300 |
+
|
| 1301 |
+
- `i == s` is well-defined.
|
| 1302 |
+
- If `bool(i != s)` then `i` is dereferenceable and \[`++i`, `s`)
|
| 1303 |
+
denotes a range.
|
| 1304 |
+
|
| 1305 |
+
The domain of `==` is not static. Given an iterator `i` and sentinel `s`
|
| 1306 |
+
such that \[`i`, `s`) denotes a range and `i != s`, `i` and `s` are not
|
| 1307 |
+
required to continue to denote a range after incrementing any other
|
| 1308 |
+
iterator equal to `i`. Consequently, `i == s` is no longer required to
|
| 1309 |
+
be well-defined.
|
| 1310 |
+
|
| 1311 |
+
#### Concept <a id="iterator.concept.sizedsentinel">[[iterator.concept.sizedsentinel]]</a>
|
| 1312 |
+
|
| 1313 |
+
The `sized_sentinel_for` concept specifies requirements on an
|
| 1314 |
+
`input_or_output_iterator` type `I` and a corresponding
|
| 1315 |
+
`sentinel_for<I>` that allow the use of the `-` operator to compute the
|
| 1316 |
+
distance between them in constant time.
|
| 1317 |
+
|
| 1318 |
+
``` cpp
|
| 1319 |
+
template<class S, class I>
|
| 1320 |
+
concept sized_sentinel_for =
|
| 1321 |
+
sentinel_for<S, I> &&
|
| 1322 |
+
!disable_sized_sentinel_for<remove_cv_t<S>, remove_cv_t<I>> &&
|
| 1323 |
+
requires(const I& i, const S& s) {
|
| 1324 |
+
{ s - i } -> same_as<iter_difference_t<I>>;
|
| 1325 |
+
{ i - s } -> same_as<iter_difference_t<I>>;
|
| 1326 |
+
};
|
| 1327 |
+
```
|
| 1328 |
+
|
| 1329 |
+
Let `i` be an iterator of type `I`, and `s` a sentinel of type `S` such
|
| 1330 |
+
that \[`i`, `s`) denotes a range. Let N be the smallest number of
|
| 1331 |
+
applications of `++i` necessary to make `bool(i == s)` be `true`. `S`
|
| 1332 |
+
and `I` model `sized_sentinel_for<S, I>` only if
|
| 1333 |
+
|
| 1334 |
+
- If N is representable by `iter_difference_t<I>`, then `s - i` is
|
| 1335 |
+
well-defined and equals N.
|
| 1336 |
+
- If -N is representable by `iter_difference_t<I>`, then `i - s` is
|
| 1337 |
+
well-defined and equals -N.
|
| 1338 |
+
|
| 1339 |
+
``` cpp
|
| 1340 |
+
template<class S, class I>
|
| 1341 |
+
inline constexpr bool disable_sized_sentinel_for = false;
|
| 1342 |
+
```
|
| 1343 |
+
|
| 1344 |
+
*Remarks:* Pursuant to [[namespace.std]], users may specialize
|
| 1345 |
+
`disable_sized_sentinel_for` for cv-unqualified non-array object types
|
| 1346 |
+
`S` and `I` if `S` and/or `I` is a program-defined type. Such
|
| 1347 |
+
specializations shall be usable in constant expressions [[expr.const]]
|
| 1348 |
+
and have type `const bool`.
|
| 1349 |
+
|
| 1350 |
+
[*Note 1*: `disable_sized_sentinel_for` allows use of sentinels and
|
| 1351 |
+
iterators with the library that satisfy but do not in fact model
|
| 1352 |
+
`sized_sentinel_for`. — *end note*]
|
| 1353 |
+
|
| 1354 |
+
[*Example 1*: The `sized_sentinel_for` concept is modeled by pairs of
|
| 1355 |
+
`random_access_iterator`s [[iterator.concept.random.access]] and by
|
| 1356 |
+
counted iterators and their
|
| 1357 |
+
sentinels [[counted.iterator]]. — *end example*]
|
| 1358 |
+
|
| 1359 |
+
#### Concept <a id="iterator.concept.input">[[iterator.concept.input]]</a>
|
| 1360 |
+
|
| 1361 |
+
The `input_iterator` concept defines requirements for a type whose
|
| 1362 |
+
referenced values can be read (from the requirement for
|
| 1363 |
+
`indirectly_readable` [[iterator.concept.readable]]) and which can be
|
| 1364 |
+
both pre- and post-incremented.
|
| 1365 |
+
|
| 1366 |
+
[*Note 1*: Unlike the *Cpp17InputIterator* requirements
|
| 1367 |
+
[[input.iterators]], the `input_iterator` concept does not need equality
|
| 1368 |
+
comparison since iterators are typically compared to
|
| 1369 |
+
sentinels. — *end note*]
|
| 1370 |
+
|
| 1371 |
+
``` cpp
|
| 1372 |
+
template<class I>
|
| 1373 |
+
concept input_iterator =
|
| 1374 |
+
input_or_output_iterator<I> &&
|
| 1375 |
+
indirectly_readable<I> &&
|
| 1376 |
+
requires { typename ITER_CONCEPT(I); } &&
|
| 1377 |
+
derived_from<ITER_CONCEPT(I), input_iterator_tag>;
|
| 1378 |
+
```
|
| 1379 |
+
|
| 1380 |
+
#### Concept <a id="iterator.concept.output">[[iterator.concept.output]]</a>
|
| 1381 |
+
|
| 1382 |
+
The `output_iterator` concept defines requirements for a type that can
|
| 1383 |
+
be used to write values (from the requirement for `indirectly_writable`
|
| 1384 |
+
[[iterator.concept.writable]]) and which can be both pre- and
|
| 1385 |
+
post-incremented.
|
| 1386 |
+
|
| 1387 |
+
[*Note 1*: Output iterators are not required to model
|
| 1388 |
+
`equality_comparable`. — *end note*]
|
| 1389 |
+
|
| 1390 |
+
``` cpp
|
| 1391 |
+
template<class I, class T>
|
| 1392 |
+
concept output_iterator =
|
| 1393 |
+
input_or_output_iterator<I> &&
|
| 1394 |
+
indirectly_writable<I, T> &&
|
| 1395 |
+
requires(I i, T&& t) {
|
| 1396 |
+
*i++ = std::forward<T>(t); // not required to be equality-preserving
|
| 1397 |
+
};
|
| 1398 |
+
```
|
| 1399 |
+
|
| 1400 |
+
Let `E` be an expression such that `decltype((E))` is `T`, and let `i`
|
| 1401 |
+
be a dereferenceable object of type `I`. `I` and `T` model
|
| 1402 |
+
`output_iterator<I, T>` only if `*i++ = E;` has effects equivalent to:
|
| 1403 |
+
|
| 1404 |
+
``` cpp
|
| 1405 |
+
*i = E;
|
| 1406 |
+
++i;
|
| 1407 |
+
```
|
| 1408 |
+
|
| 1409 |
+
[*Note 2*: Algorithms on output iterators should never attempt to pass
|
| 1410 |
+
through the same iterator twice. They should be single-pass
|
| 1411 |
+
algorithms. — *end note*]
|
| 1412 |
+
|
| 1413 |
+
#### Concept <a id="iterator.concept.forward">[[iterator.concept.forward]]</a>
|
| 1414 |
+
|
| 1415 |
+
The `forward_iterator` concept adds copyability, equality comparison,
|
| 1416 |
+
and the multi-pass guarantee, specified below.
|
| 1417 |
+
|
| 1418 |
+
``` cpp
|
| 1419 |
+
template<class I>
|
| 1420 |
+
concept forward_iterator =
|
| 1421 |
+
input_iterator<I> &&
|
| 1422 |
+
derived_from<ITER_CONCEPT(I), forward_iterator_tag> &&
|
| 1423 |
+
incrementable<I> &&
|
| 1424 |
+
sentinel_for<I, I>;
|
| 1425 |
+
```
|
| 1426 |
+
|
| 1427 |
+
The domain of `==` for forward iterators is that of iterators over the
|
| 1428 |
+
same underlying sequence. However, value-initialized iterators of the
|
| 1429 |
+
same type may be compared and shall compare equal to other
|
| 1430 |
+
value-initialized iterators of the same type.
|
| 1431 |
+
|
| 1432 |
+
[*Note 1*: Value-initialized iterators behave as if they refer past the
|
| 1433 |
+
end of the same empty sequence. — *end note*]
|
| 1434 |
+
|
| 1435 |
+
Pointers and references obtained from a forward iterator into a range
|
| 1436 |
+
\[`i`, `s`) shall remain valid while \[`i`, `s`) continues to denote a
|
| 1437 |
+
range.
|
| 1438 |
+
|
| 1439 |
+
Two dereferenceable iterators `a` and `b` of type `X` offer the
|
| 1440 |
+
*multi-pass guarantee* if:
|
| 1441 |
+
|
| 1442 |
+
- `a == b` implies `++a == ++b` and
|
| 1443 |
+
- The expression `((void)[](X x){++x;}(a), *a)` is equivalent to the
|
| 1444 |
+
expression `*a`.
|
| 1445 |
+
|
| 1446 |
+
[*Note 2*: The requirement that `a == b` implies `++a == ++b` and the
|
| 1447 |
+
removal of the restrictions on the number of assignments through a
|
| 1448 |
+
mutable iterator (which applies to output iterators) allow the use of
|
| 1449 |
+
multi-pass one-directional algorithms with forward
|
| 1450 |
+
iterators. — *end note*]
|
| 1451 |
+
|
| 1452 |
+
#### Concept <a id="iterator.concept.bidir">[[iterator.concept.bidir]]</a>
|
| 1453 |
+
|
| 1454 |
+
The `bidirectional_iterator` concept adds the ability to move an
|
| 1455 |
+
iterator backward as well as forward.
|
| 1456 |
+
|
| 1457 |
+
``` cpp
|
| 1458 |
+
template<class I>
|
| 1459 |
+
concept bidirectional_iterator =
|
| 1460 |
+
forward_iterator<I> &&
|
| 1461 |
+
derived_from<ITER_CONCEPT(I), bidirectional_iterator_tag> &&
|
| 1462 |
+
requires(I i) {
|
| 1463 |
+
{ --i } -> same_as<I&>;
|
| 1464 |
+
{ i-- } -> same_as<I>;
|
| 1465 |
+
};
|
| 1466 |
+
```
|
| 1467 |
+
|
| 1468 |
+
A bidirectional iterator `r` is decrementable if and only if there
|
| 1469 |
+
exists some `q` such that `++q == r`. Decrementable iterators `r` shall
|
| 1470 |
+
be in the domain of the expressions `--r` and `r--`.
|
| 1471 |
+
|
| 1472 |
+
Let `a` and `b` be equal objects of type `I`. `I` models
|
| 1473 |
+
`bidirectional_iterator` only if:
|
| 1474 |
+
|
| 1475 |
+
- If `a` and `b` are decrementable, then all of the following are
|
| 1476 |
+
`true`:
|
| 1477 |
+
- `addressof(--a) == addressof(a)`
|
| 1478 |
+
- `bool(a-- == b)`
|
| 1479 |
+
- after evaluating both `a--` and `--b`, `bool(a == b)` is still
|
| 1480 |
+
`true`
|
| 1481 |
+
- `bool(++(--a) == b)`
|
| 1482 |
+
- If `a` and `b` are incrementable, then `bool(--(++a) == b)`.
|
| 1483 |
+
|
| 1484 |
+
#### Concept <a id="iterator.concept.random.access">[[iterator.concept.random.access]]</a>
|
| 1485 |
+
|
| 1486 |
+
The `random_access_iterator` concept adds support for constant-time
|
| 1487 |
+
advancement with `+=`, `+`, `-=`, and `-`, as well as the computation of
|
| 1488 |
+
distance in constant time with `-`. Random access iterators also support
|
| 1489 |
+
array notation via subscripting.
|
| 1490 |
+
|
| 1491 |
+
``` cpp
|
| 1492 |
+
template<class I>
|
| 1493 |
+
concept random_access_iterator =
|
| 1494 |
+
bidirectional_iterator<I> &&
|
| 1495 |
+
derived_from<ITER_CONCEPT(I), random_access_iterator_tag> &&
|
| 1496 |
+
totally_ordered<I> &&
|
| 1497 |
+
sized_sentinel_for<I, I> &&
|
| 1498 |
+
requires(I i, const I j, const iter_difference_t<I> n) {
|
| 1499 |
+
{ i += n } -> same_as<I&>;
|
| 1500 |
+
{ j + n } -> same_as<I>;
|
| 1501 |
+
{ n + j } -> same_as<I>;
|
| 1502 |
+
{ i -= n } -> same_as<I&>;
|
| 1503 |
+
{ j - n } -> same_as<I>;
|
| 1504 |
+
{ j[n] } -> same_as<iter_reference_t<I>>;
|
| 1505 |
+
};
|
| 1506 |
+
```
|
| 1507 |
+
|
| 1508 |
+
Let `a` and `b` be valid iterators of type `I` such that `b` is
|
| 1509 |
+
reachable from `a` after `n` applications of `++a`, let `D` be
|
| 1510 |
+
`iter_difference_t<I>`, and let `n` denote a value of type `D`. `I`
|
| 1511 |
+
models `random_access_iterator` only if
|
| 1512 |
+
|
| 1513 |
+
- `(a += n)` is equal to `b`.
|
| 1514 |
+
- `addressof(a += n)` is equal to `addressof(a)`.
|
| 1515 |
+
- `(a + n)` is equal to `(a += n)`.
|
| 1516 |
+
- For any two positive values `x` and `y` of type `D`, if
|
| 1517 |
+
`(a + D(x + y))` is valid, then `(a + D(x + y))` is equal to
|
| 1518 |
+
`((a + x) + y)`.
|
| 1519 |
+
- `(a + D(0))` is equal to `a`.
|
| 1520 |
+
- If `(a + D(n - 1))` is valid, then `(a + n)` is equal to
|
| 1521 |
+
`[](I c){ return ++c; }(a + D(n - 1))`.
|
| 1522 |
+
- `(b += D(-n))` is equal to `a`.
|
| 1523 |
+
- `(b -= n)` is equal to `a`.
|
| 1524 |
+
- `addressof(b -= n)` is equal to `addressof(b)`.
|
| 1525 |
+
- `(b - n)` is equal to `(b -= n)`.
|
| 1526 |
+
- If `b` is dereferenceable, then `a[n]` is valid and is equal to `*b`.
|
| 1527 |
+
- `bool(a <= b)` is `true`.
|
| 1528 |
+
|
| 1529 |
+
#### Concept <a id="iterator.concept.contiguous">[[iterator.concept.contiguous]]</a>
|
| 1530 |
+
|
| 1531 |
+
The `contiguous_iterator` concept provides a guarantee that the denoted
|
| 1532 |
+
elements are stored contiguously in memory.
|
| 1533 |
+
|
| 1534 |
+
``` cpp
|
| 1535 |
+
template<class I>
|
| 1536 |
+
concept contiguous_iterator =
|
| 1537 |
+
random_access_iterator<I> &&
|
| 1538 |
+
derived_from<ITER_CONCEPT(I), contiguous_iterator_tag> &&
|
| 1539 |
+
is_lvalue_reference_v<iter_reference_t<I>> &&
|
| 1540 |
+
same_as<iter_value_t<I>, remove_cvref_t<iter_reference_t<I>>> &&
|
| 1541 |
+
requires(const I& i) {
|
| 1542 |
+
{ to_address(i) } -> same_as<add_pointer_t<iter_reference_t<I>>>;
|
| 1543 |
+
};
|
| 1544 |
+
```
|
| 1545 |
+
|
| 1546 |
+
Let `a` and `b` be dereferenceable iterators and `c` be a
|
| 1547 |
+
non-dereferenceable iterator of type `I` such that `b` is reachable from
|
| 1548 |
+
`a` and `c` is reachable from `b`, and let `D` be
|
| 1549 |
+
`iter_difference_t<I>`. The type `I` models `contiguous_iterator` only
|
| 1550 |
+
if
|
| 1551 |
+
|
| 1552 |
+
- `to_address(a) == addressof(*a)`,
|
| 1553 |
+
- `to_address(b) == to_address(a) + D(b - a)`, and
|
| 1554 |
+
- `to_address(c) == to_address(a) + D(c - a)`.
|
| 1555 |
+
|
| 1556 |
+
### C++17 iterator requirements <a id="iterator.cpp17">[[iterator.cpp17]]</a>
|
| 1557 |
|
| 1558 |
In the following sections, `a` and `b` denote values of type `X` or
|
| 1559 |
`const X`, `difference_type` and `reference` refer to the types
|
| 1560 |
`iterator_traits<X>::difference_type` and
|
| 1561 |
`iterator_traits<X>::reference`, respectively, `n` denotes a value of
|
| 1562 |
`difference_type`, `u`, `tmp`, and `m` denote identifiers, `r` denotes a
|
| 1563 |
value of `X&`, `t` denotes a value of value type `T`, `o` denotes a
|
| 1564 |
value of some type that is writable to the output iterator.
|
| 1565 |
|
| 1566 |
+
[*Note 1*: For an iterator type `X` there must be an instantiation of
|
| 1567 |
+
`iterator_traits<X>` [[iterator.traits]]. — *end note*]
|
| 1568 |
|
| 1569 |
+
#### *Cpp17Iterator* <a id="iterator.iterators">[[iterator.iterators]]</a>
|
| 1570 |
|
| 1571 |
+
The *Cpp17Iterator* requirements form the basis of the iterator
|
| 1572 |
+
taxonomy; every iterator meets the *Cpp17Iterator* requirements. This
|
| 1573 |
+
set of requirements specifies operations for dereferencing and
|
| 1574 |
+
incrementing an iterator. Most algorithms will require additional
|
| 1575 |
+
operations to read [[input.iterators]] or write [[output.iterators]]
|
| 1576 |
+
values, or to provide a richer set of iterator movements (
|
| 1577 |
+
[[forward.iterators]], [[bidirectional.iterators]],
|
| 1578 |
+
[[random.access.iterators]]).
|
| 1579 |
|
| 1580 |
+
A type `X` meets the *Cpp17Iterator* requirements if:
|
| 1581 |
|
| 1582 |
+
- `X` meets the *Cpp17CopyConstructible*, *Cpp17CopyAssignable*, and
|
| 1583 |
+
*Cpp17Destructible* requirements [[utility.arg.requirements]] and
|
| 1584 |
+
lvalues of type `X` are swappable [[swappable.requirements]], and
|
| 1585 |
+
- `iterator_traits<X>::difference_type` is a signed integer type or
|
| 1586 |
+
`void`, and
|
| 1587 |
+
- the expressions in [[iterator]] are valid and have the indicated
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1588 |
semantics.
|
| 1589 |
|
| 1590 |
+
#### Input iterators <a id="input.iterators">[[input.iterators]]</a>
|
| 1591 |
+
|
| 1592 |
+
A class or pointer type `X` meets the requirements of an input iterator
|
| 1593 |
+
for the value type `T` if `X` meets the *Cpp17Iterator*
|
| 1594 |
+
[[iterator.iterators]] and *Cpp17EqualityComparable* (
|
| 1595 |
+
[[cpp17.equalitycomparable]]) requirements and the expressions in
|
| 1596 |
+
[[inputiterator]] are valid and have the indicated semantics.
|
| 1597 |
+
|
| 1598 |
+
In [[inputiterator]], the term *the domain of `==`* is used in the
|
| 1599 |
+
ordinary mathematical sense to denote the set of values over which `==`
|
| 1600 |
+
is (required to be) defined. This set can change over time. Each
|
| 1601 |
+
algorithm places additional requirements on the domain of `==` for the
|
| 1602 |
+
iterator values it uses. These requirements can be inferred from the
|
| 1603 |
+
uses that algorithm makes of `==` and `!=`.
|
| 1604 |
|
| 1605 |
[*Example 1*: The call `find(a,b,x)` is defined only if the value of
|
| 1606 |
`a` has the property *p* defined as follows: `b` has property *p* and a
|
| 1607 |
value `i` has property *p* if (`*i==x`) or if (`*i!=x` and `++i` has
|
| 1608 |
property *p*). — *end example*]
|
| 1609 |
|
| 1610 |
[*Note 1*: For input iterators, `a == b` does not imply `++a == ++b`.
|
| 1611 |
(Equality does not guarantee the substitution property or referential
|
| 1612 |
transparency.) Algorithms on input iterators should never attempt to
|
| 1613 |
pass through the same iterator twice. They should be *single pass*
|
| 1614 |
+
algorithms. Value type `T` is not required to be a *Cpp17CopyAssignable*
|
| 1615 |
+
type ([[cpp17.copyassignable]]). These algorithms can be used with
|
| 1616 |
istreams as the source of the input data through the `istream_iterator`
|
| 1617 |
class template. — *end note*]
|
| 1618 |
|
| 1619 |
+
#### Output iterators <a id="output.iterators">[[output.iterators]]</a>
|
| 1620 |
|
| 1621 |
+
A class or pointer type `X` meets the requirements of an output iterator
|
| 1622 |
+
if `X` meets the *Cpp17Iterator* requirements [[iterator.iterators]] and
|
| 1623 |
+
the expressions in [[outputiterator]] are valid and have the indicated
|
|
|
|
| 1624 |
semantics.
|
| 1625 |
|
| 1626 |
[*Note 1*: The only valid use of an `operator*` is on the left side of
|
| 1627 |
+
the assignment statement. Assignment through the same value of the
|
| 1628 |
+
iterator happens only once. Algorithms on output iterators should never
|
| 1629 |
+
attempt to pass through the same iterator twice. They should be
|
| 1630 |
+
single-pass algorithms. Equality and inequality might not be
|
| 1631 |
+
defined. — *end note*]
|
|
|
|
|
|
|
| 1632 |
|
| 1633 |
+
#### Forward iterators <a id="forward.iterators">[[forward.iterators]]</a>
|
| 1634 |
|
| 1635 |
+
A class or pointer type `X` meets the requirements of a forward iterator
|
| 1636 |
+
if
|
| 1637 |
|
| 1638 |
+
- `X` meets the *Cpp17InputIterator* requirements [[input.iterators]],
|
| 1639 |
+
- `X` meets the *Cpp17DefaultConstructible* requirements
|
| 1640 |
+
[[utility.arg.requirements]],
|
|
|
|
| 1641 |
- if `X` is a mutable iterator, `reference` is a reference to `T`; if
|
| 1642 |
`X` is a constant iterator, `reference` is a reference to `const T`,
|
| 1643 |
+
- the expressions in [[forwarditerator]] are valid and have the
|
| 1644 |
+
indicated semantics, and
|
| 1645 |
- objects of type `X` offer the multi-pass guarantee, described below.
|
| 1646 |
|
| 1647 |
The domain of `==` for forward iterators is that of iterators over the
|
| 1648 |
same underlying sequence. However, value-initialized iterators may be
|
| 1649 |
compared and shall compare equal to other value-initialized iterators of
|
|
|
|
| 1669 |
dereferenceable or else neither is dereferenceable.
|
| 1670 |
|
| 1671 |
If `a` and `b` are both dereferenceable, then `a == b` if and only if
|
| 1672 |
`*a` and `*b` are bound to the same object.
|
| 1673 |
|
| 1674 |
+
#### Bidirectional iterators <a id="bidirectional.iterators">[[bidirectional.iterators]]</a>
|
| 1675 |
|
| 1676 |
+
A class or pointer type `X` meets the requirements of a bidirectional
|
| 1677 |
+
iterator if, in addition to meeting the *Cpp17ForwardIterator*
|
| 1678 |
+
requirements, the following expressions are valid as shown in
|
| 1679 |
+
[[bidirectionaliterator]].
|
| 1680 |
|
| 1681 |
[*Note 1*: Bidirectional iterators allow algorithms to move iterators
|
| 1682 |
backward as well as forward. — *end note*]
|
| 1683 |
|
| 1684 |
+
#### Random access iterators <a id="random.access.iterators">[[random.access.iterators]]</a>
|
| 1685 |
|
| 1686 |
+
A class or pointer type `X` meets the requirements of a random access
|
| 1687 |
+
iterator if, in addition to meeting the *Cpp17BidirectionalIterator*
|
| 1688 |
+
requirements, the following expressions are valid as shown in
|
| 1689 |
+
[[randomaccessiterator]].
|
| 1690 |
|
| 1691 |
+
### Indirect callable requirements <a id="indirectcallable">[[indirectcallable]]</a>
|
| 1692 |
+
|
| 1693 |
+
#### General <a id="indirectcallable.general">[[indirectcallable.general]]</a>
|
| 1694 |
+
|
| 1695 |
+
There are several concepts that group requirements of algorithms that
|
| 1696 |
+
take callable objects ([[func.def]]) as arguments.
|
| 1697 |
+
|
| 1698 |
+
#### Indirect callables <a id="indirectcallable.indirectinvocable">[[indirectcallable.indirectinvocable]]</a>
|
| 1699 |
+
|
| 1700 |
+
The indirect callable concepts are used to constrain those algorithms
|
| 1701 |
+
that accept callable objects ([[func.def]]) as arguments.
|
| 1702 |
+
|
| 1703 |
+
``` cpp
|
| 1704 |
+
namespace std {
|
| 1705 |
+
template<class F, class I>
|
| 1706 |
+
concept indirectly_unary_invocable =
|
| 1707 |
+
indirectly_readable<I> &&
|
| 1708 |
+
copy_constructible<F> &&
|
| 1709 |
+
invocable<F&, iter_value_t<I>&> &&
|
| 1710 |
+
invocable<F&, iter_reference_t<I>> &&
|
| 1711 |
+
invocable<F&, iter_common_reference_t<I>> &&
|
| 1712 |
+
common_reference_with<
|
| 1713 |
+
invoke_result_t<F&, iter_value_t<I>&>,
|
| 1714 |
+
invoke_result_t<F&, iter_reference_t<I>>>;
|
| 1715 |
+
|
| 1716 |
+
template<class F, class I>
|
| 1717 |
+
concept indirectly_regular_unary_invocable =
|
| 1718 |
+
indirectly_readable<I> &&
|
| 1719 |
+
copy_constructible<F> &&
|
| 1720 |
+
regular_invocable<F&, iter_value_t<I>&> &&
|
| 1721 |
+
regular_invocable<F&, iter_reference_t<I>> &&
|
| 1722 |
+
regular_invocable<F&, iter_common_reference_t<I>> &&
|
| 1723 |
+
common_reference_with<
|
| 1724 |
+
invoke_result_t<F&, iter_value_t<I>&>,
|
| 1725 |
+
invoke_result_t<F&, iter_reference_t<I>>>;
|
| 1726 |
+
|
| 1727 |
+
template<class F, class I>
|
| 1728 |
+
concept indirect_unary_predicate =
|
| 1729 |
+
indirectly_readable<I> &&
|
| 1730 |
+
copy_constructible<F> &&
|
| 1731 |
+
predicate<F&, iter_value_t<I>&> &&
|
| 1732 |
+
predicate<F&, iter_reference_t<I>> &&
|
| 1733 |
+
predicate<F&, iter_common_reference_t<I>>;
|
| 1734 |
+
|
| 1735 |
+
template<class F, class I1, class I2>
|
| 1736 |
+
concept indirect_binary_predicate =
|
| 1737 |
+
indirectly_readable<I1> && indirectly_readable<I2> &&
|
| 1738 |
+
copy_constructible<F> &&
|
| 1739 |
+
predicate<F&, iter_value_t<I1>&, iter_value_t<I2>&> &&
|
| 1740 |
+
predicate<F&, iter_value_t<I1>&, iter_reference_t<I2>> &&
|
| 1741 |
+
predicate<F&, iter_reference_t<I1>, iter_value_t<I2>&> &&
|
| 1742 |
+
predicate<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
|
| 1743 |
+
predicate<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>;
|
| 1744 |
+
|
| 1745 |
+
template<class F, class I1, class I2 = I1>
|
| 1746 |
+
concept indirect_equivalence_relation =
|
| 1747 |
+
indirectly_readable<I1> && indirectly_readable<I2> &&
|
| 1748 |
+
copy_constructible<F> &&
|
| 1749 |
+
equivalence_relation<F&, iter_value_t<I1>&, iter_value_t<I2>&> &&
|
| 1750 |
+
equivalence_relation<F&, iter_value_t<I1>&, iter_reference_t<I2>> &&
|
| 1751 |
+
equivalence_relation<F&, iter_reference_t<I1>, iter_value_t<I2>&> &&
|
| 1752 |
+
equivalence_relation<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
|
| 1753 |
+
equivalence_relation<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>;
|
| 1754 |
+
|
| 1755 |
+
template<class F, class I1, class I2 = I1>
|
| 1756 |
+
concept indirect_strict_weak_order =
|
| 1757 |
+
indirectly_readable<I1> && indirectly_readable<I2> &&
|
| 1758 |
+
copy_constructible<F> &&
|
| 1759 |
+
strict_weak_order<F&, iter_value_t<I1>&, iter_value_t<I2>&> &&
|
| 1760 |
+
strict_weak_order<F&, iter_value_t<I1>&, iter_reference_t<I2>> &&
|
| 1761 |
+
strict_weak_order<F&, iter_reference_t<I1>, iter_value_t<I2>&> &&
|
| 1762 |
+
strict_weak_order<F&, iter_reference_t<I1>, iter_reference_t<I2>> &&
|
| 1763 |
+
strict_weak_order<F&, iter_common_reference_t<I1>, iter_common_reference_t<I2>>;
|
| 1764 |
+
}
|
| 1765 |
+
```
|
| 1766 |
+
|
| 1767 |
+
#### Class template `projected` <a id="projected">[[projected]]</a>
|
| 1768 |
+
|
| 1769 |
+
Class template `projected` is used to constrain algorithms that accept
|
| 1770 |
+
callable objects and projections [[defns.projection]]. It combines a
|
| 1771 |
+
`indirectly_readable` type `I` and a callable object type `Proj` into a
|
| 1772 |
+
new `indirectly_readable` type whose `reference` type is the result of
|
| 1773 |
+
applying `Proj` to the `iter_reference_t` of `I`.
|
| 1774 |
|
| 1775 |
``` cpp
|
| 1776 |
namespace std {
|
| 1777 |
+
template<indirectly_readable I, indirectly_regular_unary_invocable<I> Proj>
|
| 1778 |
+
struct projected {
|
| 1779 |
+
using value_type = remove_cvref_t<indirect_result_t<Proj&, I>>;
|
| 1780 |
+
indirect_result_t<Proj&, I> operator*() const; // not defined
|
| 1781 |
+
};
|
| 1782 |
+
|
| 1783 |
+
template<weakly_incrementable I, class Proj>
|
| 1784 |
+
struct incrementable_traits<projected<I, Proj>> {
|
| 1785 |
+
using difference_type = iter_difference_t<I>;
|
| 1786 |
+
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1787 |
}
|
| 1788 |
```
|
| 1789 |
|
| 1790 |
+
### Common algorithm requirements <a id="alg.req">[[alg.req]]</a>
|
| 1791 |
+
|
| 1792 |
+
#### General <a id="alg.req.general">[[alg.req.general]]</a>
|
| 1793 |
+
|
| 1794 |
+
There are several additional iterator concepts that are commonly applied
|
| 1795 |
+
to families of algorithms. These group together iterator requirements of
|
| 1796 |
+
algorithm families. There are three relational concepts that specify how
|
| 1797 |
+
element values are transferred between `indirectly_readable` and
|
| 1798 |
+
`indirectly_writable` types: `indirectly_movable`,
|
| 1799 |
+
`indirectly_copyable`, and `indirectly_swappable`. There are three
|
| 1800 |
+
relational concepts for rearrangements: `permutable`, `mergeable`, and
|
| 1801 |
+
`sortable`. There is one relational concept for comparing values from
|
| 1802 |
+
different sequences: `indirectly_comparable`.
|
| 1803 |
+
|
| 1804 |
+
[*Note 1*: The `ranges::less` function object type used in the concepts
|
| 1805 |
+
below imposes constraints on the concepts’ arguments in addition to
|
| 1806 |
+
those that appear in the concepts’ bodies [[range.cmp]]. — *end note*]
|
| 1807 |
+
|
| 1808 |
+
#### Concept <a id="alg.req.ind.move">[[alg.req.ind.move]]</a>
|
| 1809 |
+
|
| 1810 |
+
The `indirectly_movable` concept specifies the relationship between a
|
| 1811 |
+
`indirectly_readable` type and a `indirectly_writable` type between
|
| 1812 |
+
which values may be moved.
|
| 1813 |
+
|
| 1814 |
+
``` cpp
|
| 1815 |
+
template<class In, class Out>
|
| 1816 |
+
concept indirectly_movable =
|
| 1817 |
+
indirectly_readable<In> &&
|
| 1818 |
+
indirectly_writable<Out, iter_rvalue_reference_t<In>>;
|
| 1819 |
+
```
|
| 1820 |
+
|
| 1821 |
+
The `indirectly_movable_storable` concept augments `indirectly_movable`
|
| 1822 |
+
with additional requirements enabling the transfer to be performed
|
| 1823 |
+
through an intermediate object of the `indirectly_readable` type’s value
|
| 1824 |
+
type.
|
| 1825 |
+
|
| 1826 |
+
``` cpp
|
| 1827 |
+
template<class In, class Out>
|
| 1828 |
+
concept indirectly_movable_storable =
|
| 1829 |
+
indirectly_movable<In, Out> &&
|
| 1830 |
+
indirectly_writable<Out, iter_value_t<In>> &&
|
| 1831 |
+
movable<iter_value_t<In>> &&
|
| 1832 |
+
constructible_from<iter_value_t<In>, iter_rvalue_reference_t<In>> &&
|
| 1833 |
+
assignable_from<iter_value_t<In>&, iter_rvalue_reference_t<In>>;
|
| 1834 |
+
```
|
| 1835 |
+
|
| 1836 |
+
Let `i` be a dereferenceable value of type `In`. `In` and `Out` model
|
| 1837 |
+
`indirectly_movable_storable<In, Out>` only if after the initialization
|
| 1838 |
+
of the object `obj` in
|
| 1839 |
+
|
| 1840 |
+
``` cpp
|
| 1841 |
+
iter_value_t<In> obj(ranges::iter_move(i));
|
| 1842 |
+
```
|
| 1843 |
+
|
| 1844 |
+
`obj` is equal to the value previously denoted by `*i`. If
|
| 1845 |
+
`iter_rvalue_reference_t<In>` is an rvalue reference type, the resulting
|
| 1846 |
+
state of the value denoted by `*i` is valid but unspecified
|
| 1847 |
+
[[lib.types.movedfrom]].
|
| 1848 |
+
|
| 1849 |
+
#### Concept <a id="alg.req.ind.copy">[[alg.req.ind.copy]]</a>
|
| 1850 |
+
|
| 1851 |
+
The `indirectly_copyable` concept specifies the relationship between a
|
| 1852 |
+
`indirectly_readable` type and a `indirectly_writable` type between
|
| 1853 |
+
which values may be copied.
|
| 1854 |
+
|
| 1855 |
+
``` cpp
|
| 1856 |
+
template<class In, class Out>
|
| 1857 |
+
concept indirectly_copyable =
|
| 1858 |
+
indirectly_readable<In> &&
|
| 1859 |
+
indirectly_writable<Out, iter_reference_t<In>>;
|
| 1860 |
+
```
|
| 1861 |
+
|
| 1862 |
+
The `indirectly_copyable_storable` concept augments
|
| 1863 |
+
`indirectly_copyable` with additional requirements enabling the transfer
|
| 1864 |
+
to be performed through an intermediate object of the
|
| 1865 |
+
`indirectly_readable` type’s value type. It also requires the capability
|
| 1866 |
+
to make copies of values.
|
| 1867 |
+
|
| 1868 |
+
``` cpp
|
| 1869 |
+
template<class In, class Out>
|
| 1870 |
+
concept indirectly_copyable_storable =
|
| 1871 |
+
indirectly_copyable<In, Out> &&
|
| 1872 |
+
indirectly_writable<Out, iter_value_t<In>&> &&
|
| 1873 |
+
indirectly_writable<Out, const iter_value_t<In>&> &&
|
| 1874 |
+
indirectly_writable<Out, iter_value_t<In>&&> &&
|
| 1875 |
+
indirectly_writable<Out, const iter_value_t<In>&&> &&
|
| 1876 |
+
copyable<iter_value_t<In>> &&
|
| 1877 |
+
constructible_from<iter_value_t<In>, iter_reference_t<In>> &&
|
| 1878 |
+
assignable_from<iter_value_t<In>&, iter_reference_t<In>>;
|
| 1879 |
+
```
|
| 1880 |
+
|
| 1881 |
+
Let `i` be a dereferenceable value of type `In`. `In` and `Out` model
|
| 1882 |
+
`indirectly_copyable_storable<In, Out>` only if after the initialization
|
| 1883 |
+
of the object `obj` in
|
| 1884 |
+
|
| 1885 |
+
``` cpp
|
| 1886 |
+
iter_value_t<In> obj(*i);
|
| 1887 |
+
```
|
| 1888 |
+
|
| 1889 |
+
`obj` is equal to the value previously denoted by `*i`. If
|
| 1890 |
+
`iter_reference_t<In>` is an rvalue reference type, the resulting state
|
| 1891 |
+
of the value denoted by `*i` is valid but unspecified
|
| 1892 |
+
[[lib.types.movedfrom]].
|
| 1893 |
+
|
| 1894 |
+
#### Concept <a id="alg.req.ind.swap">[[alg.req.ind.swap]]</a>
|
| 1895 |
+
|
| 1896 |
+
The `indirectly_swappable` concept specifies a swappable relationship
|
| 1897 |
+
between the values referenced by two `indirectly_readable` types.
|
| 1898 |
+
|
| 1899 |
+
``` cpp
|
| 1900 |
+
template<class I1, class I2 = I1>
|
| 1901 |
+
concept indirectly_swappable =
|
| 1902 |
+
indirectly_readable<I1> && indirectly_readable<I2> &&
|
| 1903 |
+
requires(const I1 i1, const I2 i2) {
|
| 1904 |
+
ranges::iter_swap(i1, i1);
|
| 1905 |
+
ranges::iter_swap(i2, i2);
|
| 1906 |
+
ranges::iter_swap(i1, i2);
|
| 1907 |
+
ranges::iter_swap(i2, i1);
|
| 1908 |
+
};
|
| 1909 |
+
```
|
| 1910 |
+
|
| 1911 |
+
#### Concept <a id="alg.req.ind.cmp">[[alg.req.ind.cmp]]</a>
|
| 1912 |
+
|
| 1913 |
+
The `indirectly_comparable` concept specifies the common requirements of
|
| 1914 |
+
algorithms that compare values from two different sequences.
|
| 1915 |
+
|
| 1916 |
+
``` cpp
|
| 1917 |
+
template<class I1, class I2, class R, class P1 = identity,
|
| 1918 |
+
class P2 = identity>
|
| 1919 |
+
concept indirectly_comparable =
|
| 1920 |
+
indirect_binary_predicate<R, projected<I1, P1>, projected<I2, P2>>;
|
| 1921 |
+
```
|
| 1922 |
+
|
| 1923 |
+
#### Concept <a id="alg.req.permutable">[[alg.req.permutable]]</a>
|
| 1924 |
+
|
| 1925 |
+
The `permutable` concept specifies the common requirements of algorithms
|
| 1926 |
+
that reorder elements in place by moving or swapping them.
|
| 1927 |
+
|
| 1928 |
+
``` cpp
|
| 1929 |
+
template<class I>
|
| 1930 |
+
concept permutable =
|
| 1931 |
+
forward_iterator<I> &&
|
| 1932 |
+
indirectly_movable_storable<I, I> &&
|
| 1933 |
+
indirectly_swappable<I, I>;
|
| 1934 |
+
```
|
| 1935 |
+
|
| 1936 |
+
#### Concept <a id="alg.req.mergeable">[[alg.req.mergeable]]</a>
|
| 1937 |
+
|
| 1938 |
+
The `mergeable` concept specifies the requirements of algorithms that
|
| 1939 |
+
merge sorted sequences into an output sequence by copying elements.
|
| 1940 |
+
|
| 1941 |
+
``` cpp
|
| 1942 |
+
template<class I1, class I2, class Out, class R = ranges::less,
|
| 1943 |
+
class P1 = identity, class P2 = identity>
|
| 1944 |
+
concept mergeable =
|
| 1945 |
+
input_iterator<I1> &&
|
| 1946 |
+
input_iterator<I2> &&
|
| 1947 |
+
weakly_incrementable<Out> &&
|
| 1948 |
+
indirectly_copyable<I1, Out> &&
|
| 1949 |
+
indirectly_copyable<I2, Out> &&
|
| 1950 |
+
indirect_strict_weak_order<R, projected<I1, P1>, projected<I2, P2>>;
|
| 1951 |
+
```
|
| 1952 |
+
|
| 1953 |
+
#### Concept <a id="alg.req.sortable">[[alg.req.sortable]]</a>
|
| 1954 |
+
|
| 1955 |
+
The `sortable` concept specifies the common requirements of algorithms
|
| 1956 |
+
that permute sequences into ordered sequences (e.g., `sort`).
|
| 1957 |
+
|
| 1958 |
+
``` cpp
|
| 1959 |
+
template<class I, class R = ranges::less, class P = identity>
|
| 1960 |
+
concept sortable =
|
| 1961 |
+
permutable<I> &&
|
| 1962 |
+
indirect_strict_weak_order<R, projected<I, P>>;
|
| 1963 |
+
```
|
| 1964 |
+
|
| 1965 |
## Iterator primitives <a id="iterator.primitives">[[iterator.primitives]]</a>
|
| 1966 |
|
| 1967 |
+
To simplify the use of iterators, the library provides several classes
|
| 1968 |
+
and functions.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1969 |
|
| 1970 |
### Standard iterator tags <a id="std.iterator.tags">[[std.iterator.tags]]</a>
|
| 1971 |
|
| 1972 |
It is often desirable for a function template specialization to find out
|
| 1973 |
what is the most specific category of its iterator argument, so that the
|
| 1974 |
function can select the most efficient algorithm at compile time. To
|
| 1975 |
facilitate this, the library introduces *category tag* classes which are
|
| 1976 |
used as compile time tags for algorithm selection. They are:
|
| 1977 |
+
`output_iterator_tag`, `input_iterator_tag`, `forward_iterator_tag`,
|
| 1978 |
+
`bidirectional_iterator_tag`, `random_access_iterator_tag`, and
|
| 1979 |
+
`contiguous_iterator_tag`. For every iterator of type `I`,
|
| 1980 |
+
`iterator_traits<I>::iterator_category` shall be defined to be a
|
| 1981 |
+
category tag that describes the iterator’s behavior. Additionally,
|
| 1982 |
+
`iterator_traits<I>::iterator_concept` may be used to indicate
|
| 1983 |
+
conformance to the iterator concepts [[iterator.concepts]].
|
| 1984 |
|
| 1985 |
``` cpp
|
| 1986 |
namespace std {
|
|
|
|
| 1987 |
struct output_iterator_tag { };
|
| 1988 |
+
struct input_iterator_tag { };
|
| 1989 |
struct forward_iterator_tag: public input_iterator_tag { };
|
| 1990 |
struct bidirectional_iterator_tag: public forward_iterator_tag { };
|
| 1991 |
struct random_access_iterator_tag: public bidirectional_iterator_tag { };
|
| 1992 |
+
struct contiguous_iterator_tag: public random_access_iterator_tag { };
|
| 1993 |
}
|
| 1994 |
```
|
| 1995 |
|
| 1996 |
[*Example 1*:
|
| 1997 |
|
|
|
|
| 2011 |
|
| 2012 |
— *end example*]
|
| 2013 |
|
| 2014 |
[*Example 2*:
|
| 2015 |
|
| 2016 |
+
If `evolve()` is well-defined for bidirectional iterators, but can be
|
| 2017 |
implemented more efficiently for random access iterators, then the
|
| 2018 |
implementation is as follows:
|
| 2019 |
|
| 2020 |
``` cpp
|
| 2021 |
template<class BidirectionalIterator>
|
|
|
|
| 2051 |
``` cpp
|
| 2052 |
template<class InputIterator, class Distance>
|
| 2053 |
constexpr void advance(InputIterator& i, Distance n);
|
| 2054 |
```
|
| 2055 |
|
| 2056 |
+
*Preconditions:* `n` is negative only for bidirectional iterators.
|
|
|
|
| 2057 |
|
| 2058 |
+
*Effects:* Increments `i` by `n` if `n` is non-negative, and decrements
|
| 2059 |
+
`i` by `-n` otherwise.
|
| 2060 |
|
| 2061 |
``` cpp
|
| 2062 |
template<class InputIterator>
|
| 2063 |
constexpr typename iterator_traits<InputIterator>::difference_type
|
| 2064 |
distance(InputIterator first, InputIterator last);
|
| 2065 |
```
|
| 2066 |
|
| 2067 |
+
*Preconditions:* `last` is reachable from `first`, or `InputIterator`
|
| 2068 |
+
meets the *Cpp17RandomAccessIterator* requirements and `first` is
|
| 2069 |
+
reachable from `last`.
|
| 2070 |
+
|
| 2071 |
+
*Effects:* If `InputIterator` meets the *Cpp17RandomAccessIterator*
|
| 2072 |
+
requirements, returns `(last - first)`; otherwise, returns the number of
|
| 2073 |
increments needed to get from `first` to `last`.
|
| 2074 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2075 |
``` cpp
|
| 2076 |
template<class InputIterator>
|
| 2077 |
constexpr InputIterator next(InputIterator x,
|
| 2078 |
typename iterator_traits<InputIterator>::difference_type n = 1);
|
| 2079 |
```
|
|
|
|
| 2086 |
typename iterator_traits<BidirectionalIterator>::difference_type n = 1);
|
| 2087 |
```
|
| 2088 |
|
| 2089 |
*Effects:* Equivalent to: `advance(x, -n); return x;`
|
| 2090 |
|
| 2091 |
+
### Range iterator operations <a id="range.iter.ops">[[range.iter.ops]]</a>
|
| 2092 |
+
|
| 2093 |
+
The library includes the function templates `ranges::advance`,
|
| 2094 |
+
`ranges::distance`, `ranges::next`, and `ranges::prev` to manipulate
|
| 2095 |
+
iterators. These operations adapt to the set of operators provided by
|
| 2096 |
+
each iterator category to provide the most efficient implementation
|
| 2097 |
+
possible for a concrete iterator type.
|
| 2098 |
+
|
| 2099 |
+
[*Example 1*: `ranges::advance` uses the `+` operator to move a
|
| 2100 |
+
`random_access_iterator` forward `n` steps in constant time. For an
|
| 2101 |
+
iterator type that does not model `random_access_iterator`,
|
| 2102 |
+
`ranges::advance` instead performs `n` individual increments with the
|
| 2103 |
+
`++` operator. — *end example*]
|
| 2104 |
+
|
| 2105 |
+
The function templates defined in this subclause are not found by
|
| 2106 |
+
argument-dependent name lookup [[basic.lookup.argdep]]. When found by
|
| 2107 |
+
unqualified [[basic.lookup.unqual]] name lookup for the
|
| 2108 |
+
*postfix-expression* in a function call [[expr.call]], they inhibit
|
| 2109 |
+
argument-dependent name lookup.
|
| 2110 |
+
|
| 2111 |
+
[*Example 2*:
|
| 2112 |
+
|
| 2113 |
+
``` cpp
|
| 2114 |
+
void foo() {
|
| 2115 |
+
using namespace std::ranges;
|
| 2116 |
+
std::vector<int> vec{1,2,3};
|
| 2117 |
+
distance(begin(vec), end(vec)); // #1
|
| 2118 |
+
}
|
| 2119 |
+
```
|
| 2120 |
+
|
| 2121 |
+
The function call expression at `#1` invokes `std::ranges::distance`,
|
| 2122 |
+
not `std::distance`, despite that (a) the iterator type returned from
|
| 2123 |
+
`begin(vec)` and `end(vec)` may be associated with namespace `std` and
|
| 2124 |
+
(b) `std::distance` is more specialized ([[temp.func.order]]) than
|
| 2125 |
+
`std::ranges::distance` since the former requires its first two
|
| 2126 |
+
parameters to have the same type.
|
| 2127 |
+
|
| 2128 |
+
— *end example*]
|
| 2129 |
+
|
| 2130 |
+
The number and order of deducible template parameters for the function
|
| 2131 |
+
templates defined in this subclause is unspecified, except where
|
| 2132 |
+
explicitly stated otherwise.
|
| 2133 |
+
|
| 2134 |
+
#### `ranges::advance` <a id="range.iter.op.advance">[[range.iter.op.advance]]</a>
|
| 2135 |
+
|
| 2136 |
+
``` cpp
|
| 2137 |
+
template<input_or_output_iterator I>
|
| 2138 |
+
constexpr void ranges::advance(I& i, iter_difference_t<I> n);
|
| 2139 |
+
```
|
| 2140 |
+
|
| 2141 |
+
*Preconditions:* If `I` does not model `bidirectional_iterator`, `n` is
|
| 2142 |
+
not negative.
|
| 2143 |
+
|
| 2144 |
+
*Effects:*
|
| 2145 |
+
|
| 2146 |
+
- If `I` models `random_access_iterator`, equivalent to `i += n`.
|
| 2147 |
+
- Otherwise, if `n` is non-negative, increments `i` by `n`.
|
| 2148 |
+
- Otherwise, decrements `i` by `-n`.
|
| 2149 |
+
|
| 2150 |
+
``` cpp
|
| 2151 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 2152 |
+
constexpr void ranges::advance(I& i, S bound);
|
| 2153 |
+
```
|
| 2154 |
+
|
| 2155 |
+
*Preconditions:* \[`i`, `bound`) denotes a range.
|
| 2156 |
+
|
| 2157 |
+
*Effects:*
|
| 2158 |
+
|
| 2159 |
+
- If `I` and `S` model `assignable_from<I&, S>`, equivalent to
|
| 2160 |
+
`i = std::move(bound)`.
|
| 2161 |
+
- Otherwise, if `S` and `I` model `sized_sentinel_for<S, I>`, equivalent
|
| 2162 |
+
to `ranges::advance(i, bound - i)`.
|
| 2163 |
+
- Otherwise, while `bool(i != bound)` is `true`, increments `i`.
|
| 2164 |
+
|
| 2165 |
+
``` cpp
|
| 2166 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 2167 |
+
constexpr iter_difference_t<I> ranges::advance(I& i, iter_difference_t<I> n, S bound);
|
| 2168 |
+
```
|
| 2169 |
+
|
| 2170 |
+
*Preconditions:* If `n > 0`, \[`i`, `bound`) denotes a range. If
|
| 2171 |
+
`n == 0`, \[`i`, `bound`) or \[`bound`, `i`) denotes a range. If
|
| 2172 |
+
`n < 0`, \[`bound`, `i`) denotes a range, `I` models
|
| 2173 |
+
`bidirectional_iterator`, and `I` and `S` model `same_as<I, S>`.
|
| 2174 |
+
|
| 2175 |
+
*Effects:*
|
| 2176 |
+
|
| 2177 |
+
- If `S` and `I` model `sized_sentinel_for<S, I>`:
|
| 2178 |
+
- If |`n`| ≥ |`bound - i`|, equivalent to `ranges::advance(i, bound)`.
|
| 2179 |
+
- Otherwise, equivalent to `ranges::advance(i, n)`.
|
| 2180 |
+
- Otherwise,
|
| 2181 |
+
- if `n` is non-negative, while `bool(i != bound)` is `true`,
|
| 2182 |
+
increments `i` but at most `n` times.
|
| 2183 |
+
- Otherwise, while `bool(i != bound)` is `true`, decrements `i` but at
|
| 2184 |
+
most `-n` times.
|
| 2185 |
+
|
| 2186 |
+
*Returns:* `n - `M, where M is the difference between the ending and
|
| 2187 |
+
starting positions of `i`.
|
| 2188 |
+
|
| 2189 |
+
#### `ranges::distance` <a id="range.iter.op.distance">[[range.iter.op.distance]]</a>
|
| 2190 |
+
|
| 2191 |
+
``` cpp
|
| 2192 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 2193 |
+
constexpr iter_difference_t<I> ranges::distance(I first, S last);
|
| 2194 |
+
```
|
| 2195 |
+
|
| 2196 |
+
*Preconditions:* \[`first`, `last`) denotes a range, or \[`last`,
|
| 2197 |
+
`first`) denotes a range and `S` and `I` model
|
| 2198 |
+
`same_as<S, I> && sized_sentinel_for<S, I>`.
|
| 2199 |
+
|
| 2200 |
+
*Effects:* If `S` and `I` model `sized_sentinel_for<S, I>`, returns
|
| 2201 |
+
`(last - first)`; otherwise, returns the number of increments needed to
|
| 2202 |
+
get from `first` to `last`.
|
| 2203 |
+
|
| 2204 |
+
``` cpp
|
| 2205 |
+
template<range R>
|
| 2206 |
+
constexpr range_difference_t<R> ranges::distance(R&& r);
|
| 2207 |
+
```
|
| 2208 |
+
|
| 2209 |
+
*Effects:* If `R` models `sized_range`, equivalent to:
|
| 2210 |
+
|
| 2211 |
+
``` cpp
|
| 2212 |
+
return static_cast<range_difference_t<R>>(ranges::size(r)); // [range.prim.size]
|
| 2213 |
+
```
|
| 2214 |
+
|
| 2215 |
+
Otherwise, equivalent to:
|
| 2216 |
+
|
| 2217 |
+
``` cpp
|
| 2218 |
+
return ranges::distance(ranges::begin(r), ranges::end(r)); // [range.access]
|
| 2219 |
+
```
|
| 2220 |
+
|
| 2221 |
+
#### `ranges::next` <a id="range.iter.op.next">[[range.iter.op.next]]</a>
|
| 2222 |
+
|
| 2223 |
+
``` cpp
|
| 2224 |
+
template<input_or_output_iterator I>
|
| 2225 |
+
constexpr I ranges::next(I x);
|
| 2226 |
+
```
|
| 2227 |
+
|
| 2228 |
+
*Effects:* Equivalent to: `++x; return x;`
|
| 2229 |
+
|
| 2230 |
+
``` cpp
|
| 2231 |
+
template<input_or_output_iterator I>
|
| 2232 |
+
constexpr I ranges::next(I x, iter_difference_t<I> n);
|
| 2233 |
+
```
|
| 2234 |
+
|
| 2235 |
+
*Effects:* Equivalent to: `ranges::advance(x, n); return x;`
|
| 2236 |
+
|
| 2237 |
+
``` cpp
|
| 2238 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 2239 |
+
constexpr I ranges::next(I x, S bound);
|
| 2240 |
+
```
|
| 2241 |
+
|
| 2242 |
+
*Effects:* Equivalent to: `ranges::advance(x, bound); return x;`
|
| 2243 |
+
|
| 2244 |
+
``` cpp
|
| 2245 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 2246 |
+
constexpr I ranges::next(I x, iter_difference_t<I> n, S bound);
|
| 2247 |
+
```
|
| 2248 |
+
|
| 2249 |
+
*Effects:* Equivalent to: `ranges::advance(x, n, bound); return x;`
|
| 2250 |
+
|
| 2251 |
+
#### `ranges::prev` <a id="range.iter.op.prev">[[range.iter.op.prev]]</a>
|
| 2252 |
+
|
| 2253 |
+
``` cpp
|
| 2254 |
+
template<bidirectional_iterator I>
|
| 2255 |
+
constexpr I ranges::prev(I x);
|
| 2256 |
+
```
|
| 2257 |
+
|
| 2258 |
+
*Effects:* Equivalent to: `-``-``x; return x;`
|
| 2259 |
+
|
| 2260 |
+
``` cpp
|
| 2261 |
+
template<bidirectional_iterator I>
|
| 2262 |
+
constexpr I ranges::prev(I x, iter_difference_t<I> n);
|
| 2263 |
+
```
|
| 2264 |
+
|
| 2265 |
+
*Effects:* Equivalent to: `ranges::advance(x, -n); return x;`
|
| 2266 |
+
|
| 2267 |
+
``` cpp
|
| 2268 |
+
template<bidirectional_iterator I>
|
| 2269 |
+
constexpr I ranges::prev(I x, iter_difference_t<I> n, I bound);
|
| 2270 |
+
```
|
| 2271 |
+
|
| 2272 |
+
*Effects:* Equivalent to: `ranges::advance(x, -n, bound); return x;`
|
| 2273 |
+
|
| 2274 |
## Iterator adaptors <a id="predef.iterators">[[predef.iterators]]</a>
|
| 2275 |
|
| 2276 |
### Reverse iterators <a id="reverse.iterators">[[reverse.iterators]]</a>
|
| 2277 |
|
| 2278 |
Class template `reverse_iterator` is an iterator adaptor that iterates
|
| 2279 |
from the end of the sequence defined by its underlying iterator to the
|
| 2280 |
+
beginning of that sequence.
|
|
|
|
|
|
|
| 2281 |
|
| 2282 |
#### Class template `reverse_iterator` <a id="reverse.iterator">[[reverse.iterator]]</a>
|
| 2283 |
|
| 2284 |
``` cpp
|
| 2285 |
namespace std {
|
| 2286 |
template<class Iterator>
|
| 2287 |
class reverse_iterator {
|
| 2288 |
public:
|
| 2289 |
using iterator_type = Iterator;
|
| 2290 |
+
using iterator_concept = see below;
|
| 2291 |
+
using iterator_category = see below;
|
| 2292 |
+
using value_type = iter_value_t<Iterator>;
|
| 2293 |
+
using difference_type = iter_difference_t<Iterator>;
|
| 2294 |
using pointer = typename iterator_traits<Iterator>::pointer;
|
| 2295 |
+
using reference = iter_reference_t<Iterator>;
|
| 2296 |
|
| 2297 |
constexpr reverse_iterator();
|
| 2298 |
constexpr explicit reverse_iterator(Iterator x);
|
| 2299 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 2300 |
template<class U> constexpr reverse_iterator& operator=(const reverse_iterator<U>& u);
|
| 2301 |
|
| 2302 |
+
constexpr Iterator base() const;
|
| 2303 |
constexpr reference operator*() const;
|
| 2304 |
+
constexpr pointer operator->() const requires see below;
|
| 2305 |
|
| 2306 |
constexpr reverse_iterator& operator++();
|
| 2307 |
constexpr reverse_iterator operator++(int);
|
| 2308 |
constexpr reverse_iterator& operator--();
|
| 2309 |
constexpr reverse_iterator operator--(int);
|
|
|
|
| 2311 |
constexpr reverse_iterator operator+ (difference_type n) const;
|
| 2312 |
constexpr reverse_iterator& operator+=(difference_type n);
|
| 2313 |
constexpr reverse_iterator operator- (difference_type n) const;
|
| 2314 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 2315 |
constexpr unspecified operator[](difference_type n) const;
|
| 2316 |
+
|
| 2317 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 2318 |
+
iter_move(const reverse_iterator& i) noexcept(see below);
|
| 2319 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 2320 |
+
friend constexpr void
|
| 2321 |
+
iter_swap(const reverse_iterator& x,
|
| 2322 |
+
const reverse_iterator<Iterator2>& y) noexcept(see below);
|
| 2323 |
+
|
| 2324 |
protected:
|
| 2325 |
Iterator current;
|
| 2326 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2327 |
}
|
| 2328 |
```
|
| 2329 |
|
| 2330 |
+
The member *typedef-name* `iterator_concept` denotes
|
| 2331 |
+
|
| 2332 |
+
- `random_access_iterator_tag` if `Iterator` models
|
| 2333 |
+
`random_access_iterator`, and
|
| 2334 |
+
- `bidirectional_iterator_tag` otherwise.
|
| 2335 |
+
|
| 2336 |
+
The member *typedef-name* `iterator_category` denotes
|
| 2337 |
+
|
| 2338 |
+
- `random_access_iterator_tag` if the type
|
| 2339 |
+
`iterator_traits<{}Iterator>::iterator_category` models
|
| 2340 |
+
`derived_from<random_access_iterator_tag>`, and
|
| 2341 |
+
- `iterator_traits<{}Iterator>::iterator_category` otherwise.
|
| 2342 |
+
|
| 2343 |
+
#### Requirements <a id="reverse.iter.requirements">[[reverse.iter.requirements]]</a>
|
| 2344 |
+
|
| 2345 |
+
The template parameter `Iterator` shall either meet the requirements of
|
| 2346 |
+
a *Cpp17BidirectionalIterator* [[bidirectional.iterators]] or model
|
| 2347 |
+
`bidirectional_iterator` [[iterator.concept.bidir]].
|
| 2348 |
+
|
| 2349 |
+
Additionally, `Iterator` shall either meet the requirements of a
|
| 2350 |
+
*Cpp17RandomAccessIterator* [[random.access.iterators]] or model
|
| 2351 |
+
`random_access_iterator` [[iterator.concept.random.access]] if the
|
| 2352 |
+
definitions of any of the members
|
| 2353 |
+
|
| 2354 |
+
- `operator+`, `operator-`, `operator+=`, `operator-=`
|
| 2355 |
+
[[reverse.iter.nav]], or
|
| 2356 |
+
- `operator[]` [[reverse.iter.elem]],
|
| 2357 |
+
|
| 2358 |
+
or the non-member operators [[reverse.iter.cmp]]
|
| 2359 |
+
|
| 2360 |
+
- `operator<`, `operator>`, `operator<=`, `operator>=`, `operator-`, or
|
| 2361 |
+
`operator+` [[reverse.iter.nonmember]]
|
| 2362 |
+
|
| 2363 |
+
are instantiated [[temp.inst]].
|
| 2364 |
+
|
| 2365 |
+
#### Construction and assignment <a id="reverse.iter.cons">[[reverse.iter.cons]]</a>
|
| 2366 |
|
| 2367 |
``` cpp
|
| 2368 |
constexpr reverse_iterator();
|
| 2369 |
```
|
| 2370 |
|
|
|
|
| 2383 |
template<class U> constexpr reverse_iterator(const reverse_iterator<U>& u);
|
| 2384 |
```
|
| 2385 |
|
| 2386 |
*Effects:* Initializes `current` with `u.current`.
|
| 2387 |
|
|
|
|
|
|
|
| 2388 |
``` cpp
|
| 2389 |
template<class U>
|
| 2390 |
constexpr reverse_iterator&
|
| 2391 |
operator=(const reverse_iterator<U>& u);
|
| 2392 |
```
|
| 2393 |
|
| 2394 |
+
*Effects:* Assigns `u.base()` to `current`.
|
| 2395 |
|
| 2396 |
*Returns:* `*this`.
|
| 2397 |
|
| 2398 |
+
#### Conversion <a id="reverse.iter.conv">[[reverse.iter.conv]]</a>
|
| 2399 |
|
| 2400 |
``` cpp
|
| 2401 |
constexpr Iterator base() const; // explicit
|
| 2402 |
```
|
| 2403 |
|
| 2404 |
*Returns:* `current`.
|
| 2405 |
|
| 2406 |
+
#### Element access <a id="reverse.iter.elem">[[reverse.iter.elem]]</a>
|
| 2407 |
|
| 2408 |
``` cpp
|
| 2409 |
constexpr reference operator*() const;
|
| 2410 |
```
|
| 2411 |
|
|
|
|
| 2414 |
``` cpp
|
| 2415 |
Iterator tmp = current;
|
| 2416 |
return *--tmp;
|
| 2417 |
```
|
| 2418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2419 |
``` cpp
|
| 2420 |
+
constexpr pointer operator->() const
|
| 2421 |
+
requires (is_pointer_v<Iterator> ||
|
| 2422 |
+
requires (const Iterator i) { i.operator->(); });
|
| 2423 |
```
|
| 2424 |
|
| 2425 |
+
*Effects:*
|
| 2426 |
|
| 2427 |
+
- If `Iterator` is a pointer type, equivalent to:
|
| 2428 |
+
`return prev(current);`
|
| 2429 |
+
- Otherwise, equivalent to: `return prev(current).operator->();`
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2430 |
|
| 2431 |
``` cpp
|
| 2432 |
+
constexpr unspecified operator[](difference_type n) const;
|
| 2433 |
```
|
| 2434 |
|
| 2435 |
+
*Returns:* `current[-n-1]`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2436 |
|
| 2437 |
+
#### Navigation <a id="reverse.iter.nav">[[reverse.iter.nav]]</a>
|
| 2438 |
|
| 2439 |
``` cpp
|
| 2440 |
constexpr reverse_iterator operator+(difference_type n) const;
|
| 2441 |
```
|
| 2442 |
|
| 2443 |
*Returns:* `reverse_iterator(current-n)`.
|
| 2444 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2445 |
``` cpp
|
| 2446 |
constexpr reverse_iterator operator-(difference_type n) const;
|
| 2447 |
```
|
| 2448 |
|
| 2449 |
*Returns:* `reverse_iterator(current+n)`.
|
| 2450 |
|
| 2451 |
+
``` cpp
|
| 2452 |
+
constexpr reverse_iterator& operator++();
|
| 2453 |
+
```
|
| 2454 |
+
|
| 2455 |
+
*Effects:* As if by: `current;`
|
| 2456 |
+
|
| 2457 |
+
*Returns:* `*this`.
|
| 2458 |
+
|
| 2459 |
+
``` cpp
|
| 2460 |
+
constexpr reverse_iterator operator++(int);
|
| 2461 |
+
```
|
| 2462 |
+
|
| 2463 |
+
*Effects:* As if by:
|
| 2464 |
+
|
| 2465 |
+
``` cpp
|
| 2466 |
+
reverse_iterator tmp = *this;
|
| 2467 |
+
--current;
|
| 2468 |
+
return tmp;
|
| 2469 |
+
```
|
| 2470 |
+
|
| 2471 |
+
``` cpp
|
| 2472 |
+
constexpr reverse_iterator& operator--();
|
| 2473 |
+
```
|
| 2474 |
+
|
| 2475 |
+
*Effects:* As if by `++current`.
|
| 2476 |
+
|
| 2477 |
+
*Returns:* `*this`.
|
| 2478 |
+
|
| 2479 |
+
``` cpp
|
| 2480 |
+
constexpr reverse_iterator operator--(int);
|
| 2481 |
+
```
|
| 2482 |
+
|
| 2483 |
+
*Effects:* As if by:
|
| 2484 |
+
|
| 2485 |
+
``` cpp
|
| 2486 |
+
reverse_iterator tmp = *this;
|
| 2487 |
+
++current;
|
| 2488 |
+
return tmp;
|
| 2489 |
+
```
|
| 2490 |
+
|
| 2491 |
+
``` cpp
|
| 2492 |
+
constexpr reverse_iterator& operator+=(difference_type n);
|
| 2493 |
+
```
|
| 2494 |
+
|
| 2495 |
+
*Effects:* As if by: `current -= n;`
|
| 2496 |
+
|
| 2497 |
+
*Returns:* `*this`.
|
| 2498 |
|
| 2499 |
``` cpp
|
| 2500 |
constexpr reverse_iterator& operator-=(difference_type n);
|
| 2501 |
```
|
| 2502 |
|
| 2503 |
*Effects:* As if by: `current += n;`
|
| 2504 |
|
| 2505 |
*Returns:* `*this`.
|
| 2506 |
|
| 2507 |
+
#### Comparisons <a id="reverse.iter.cmp">[[reverse.iter.cmp]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2508 |
|
| 2509 |
``` cpp
|
| 2510 |
template<class Iterator1, class Iterator2>
|
| 2511 |
constexpr bool operator==(
|
| 2512 |
const reverse_iterator<Iterator1>& x,
|
| 2513 |
const reverse_iterator<Iterator2>& y);
|
| 2514 |
```
|
| 2515 |
|
| 2516 |
+
*Constraints:* `x.base() == y.base()` is well-formed and convertible to
|
| 2517 |
+
`bool`.
|
| 2518 |
|
| 2519 |
+
*Returns:* `x.base() == y.base()`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2520 |
|
| 2521 |
``` cpp
|
| 2522 |
template<class Iterator1, class Iterator2>
|
| 2523 |
constexpr bool operator!=(
|
| 2524 |
const reverse_iterator<Iterator1>& x,
|
| 2525 |
const reverse_iterator<Iterator2>& y);
|
| 2526 |
```
|
| 2527 |
|
| 2528 |
+
*Constraints:* `x.base() != y.base()` is well-formed and convertible to
|
| 2529 |
+
`bool`.
|
| 2530 |
|
| 2531 |
+
*Returns:* `x.base() != y.base()`.
|
| 2532 |
+
|
| 2533 |
+
``` cpp
|
| 2534 |
+
template<class Iterator1, class Iterator2>
|
| 2535 |
+
constexpr bool operator<(
|
| 2536 |
+
const reverse_iterator<Iterator1>& x,
|
| 2537 |
+
const reverse_iterator<Iterator2>& y);
|
| 2538 |
+
```
|
| 2539 |
+
|
| 2540 |
+
*Constraints:* `x.base() > y.base()` is well-formed and convertible to
|
| 2541 |
+
`bool`.
|
| 2542 |
+
|
| 2543 |
+
*Returns:* `x.base() > y.base()`.
|
| 2544 |
|
| 2545 |
``` cpp
|
| 2546 |
template<class Iterator1, class Iterator2>
|
| 2547 |
constexpr bool operator>(
|
| 2548 |
const reverse_iterator<Iterator1>& x,
|
| 2549 |
const reverse_iterator<Iterator2>& y);
|
| 2550 |
```
|
| 2551 |
|
| 2552 |
+
*Constraints:* `x.base() < y.base()` is well-formed and convertible to
|
| 2553 |
+
`bool`.
|
| 2554 |
|
| 2555 |
+
*Returns:* `x.base() < y.base()`.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2556 |
|
| 2557 |
``` cpp
|
| 2558 |
template<class Iterator1, class Iterator2>
|
| 2559 |
constexpr bool operator<=(
|
| 2560 |
const reverse_iterator<Iterator1>& x,
|
| 2561 |
const reverse_iterator<Iterator2>& y);
|
| 2562 |
```
|
| 2563 |
|
| 2564 |
+
*Constraints:* `x.base() >= y.base()` is well-formed and convertible to
|
| 2565 |
+
`bool`.
|
| 2566 |
|
| 2567 |
+
*Returns:* `x.base() >= y.base()`.
|
| 2568 |
+
|
| 2569 |
+
``` cpp
|
| 2570 |
+
template<class Iterator1, class Iterator2>
|
| 2571 |
+
constexpr bool operator>=(
|
| 2572 |
+
const reverse_iterator<Iterator1>& x,
|
| 2573 |
+
const reverse_iterator<Iterator2>& y);
|
| 2574 |
+
```
|
| 2575 |
+
|
| 2576 |
+
*Constraints:* `x.base() <= y.base()` is well-formed and convertible to
|
| 2577 |
+
`bool`.
|
| 2578 |
+
|
| 2579 |
+
*Returns:* `x.base() <= y.base()`.
|
| 2580 |
+
|
| 2581 |
+
``` cpp
|
| 2582 |
+
template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
|
| 2583 |
+
constexpr compare_three_way_result_t<Iterator1, Iterator2>
|
| 2584 |
+
operator<=>(const reverse_iterator<Iterator1>& x,
|
| 2585 |
+
const reverse_iterator<Iterator2>& y);
|
| 2586 |
+
```
|
| 2587 |
+
|
| 2588 |
+
*Returns:* `y.base() <=> x.base()`.
|
| 2589 |
+
|
| 2590 |
+
[*Note 1*: The argument order in the *Returns:* element is reversed
|
| 2591 |
+
because this is a reverse iterator. — *end note*]
|
| 2592 |
+
|
| 2593 |
+
#### Non-member functions <a id="reverse.iter.nonmember">[[reverse.iter.nonmember]]</a>
|
| 2594 |
|
| 2595 |
``` cpp
|
| 2596 |
template<class Iterator1, class Iterator2>
|
| 2597 |
constexpr auto operator-(
|
| 2598 |
const reverse_iterator<Iterator1>& x,
|
| 2599 |
const reverse_iterator<Iterator2>& y) -> decltype(y.base() - x.base());
|
| 2600 |
```
|
| 2601 |
|
| 2602 |
+
*Returns:* `y.base() - x.base()`.
|
|
|
|
|
|
|
| 2603 |
|
| 2604 |
``` cpp
|
| 2605 |
template<class Iterator>
|
| 2606 |
constexpr reverse_iterator<Iterator> operator+(
|
| 2607 |
typename reverse_iterator<Iterator>::difference_type n,
|
| 2608 |
const reverse_iterator<Iterator>& x);
|
| 2609 |
```
|
| 2610 |
|
| 2611 |
+
*Returns:* `reverse_iterator<Iterator>(x.base() - n)`.
|
| 2612 |
|
| 2613 |
+
``` cpp
|
| 2614 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 2615 |
+
iter_move(const reverse_iterator& i) noexcept(see below);
|
| 2616 |
+
```
|
| 2617 |
+
|
| 2618 |
+
*Effects:* Equivalent to:
|
| 2619 |
+
|
| 2620 |
+
``` cpp
|
| 2621 |
+
auto tmp = i.base();
|
| 2622 |
+
return ranges::iter_move(--tmp);
|
| 2623 |
+
```
|
| 2624 |
+
|
| 2625 |
+
*Remarks:* The expression in `noexcept` is equivalent to:
|
| 2626 |
+
|
| 2627 |
+
``` cpp
|
| 2628 |
+
is_nothrow_copy_constructible_v<Iterator> &&
|
| 2629 |
+
noexcept(ranges::iter_move(--declval<Iterator&>()))
|
| 2630 |
+
```
|
| 2631 |
+
|
| 2632 |
+
``` cpp
|
| 2633 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 2634 |
+
friend constexpr void
|
| 2635 |
+
iter_swap(const reverse_iterator& x,
|
| 2636 |
+
const reverse_iterator<Iterator2>& y) noexcept(see below);
|
| 2637 |
+
```
|
| 2638 |
+
|
| 2639 |
+
*Effects:* Equivalent to:
|
| 2640 |
+
|
| 2641 |
+
``` cpp
|
| 2642 |
+
auto xtmp = x.base();
|
| 2643 |
+
auto ytmp = y.base();
|
| 2644 |
+
ranges::iter_swap(--xtmp, --ytmp);
|
| 2645 |
+
```
|
| 2646 |
+
|
| 2647 |
+
*Remarks:* The expression in `noexcept` is equivalent to:
|
| 2648 |
+
|
| 2649 |
+
``` cpp
|
| 2650 |
+
is_nothrow_copy_constructible_v<Iterator> &&
|
| 2651 |
+
is_nothrow_copy_constructible_v<Iterator2> &&
|
| 2652 |
+
noexcept(ranges::iter_swap(--declval<Iterator&>(), --declval<Iterator2&>()))
|
| 2653 |
+
```
|
| 2654 |
|
| 2655 |
``` cpp
|
| 2656 |
template<class Iterator>
|
| 2657 |
constexpr reverse_iterator<Iterator> make_reverse_iterator(Iterator i);
|
| 2658 |
```
|
|
|
|
| 2675 |
of the copying algorithms in the library to work in the *insert mode*
|
| 2676 |
instead of the *regular overwrite* mode.
|
| 2677 |
|
| 2678 |
An insert iterator is constructed from a container and possibly one of
|
| 2679 |
its iterators pointing to where insertion takes place if it is neither
|
| 2680 |
+
at the beginning nor at the end of the container. Insert iterators meet
|
| 2681 |
+
the requirements of output iterators. `operator*` returns the insert
|
| 2682 |
+
iterator itself. The assignment `operator=(const T& x)` is defined on
|
| 2683 |
+
insert iterators to allow writing into them, it inserts `x` right before
|
| 2684 |
+
where the insert iterator is pointing. In other words, an insert
|
| 2685 |
+
iterator is like a cursor pointing into the container where the
|
| 2686 |
insertion takes place. `back_insert_iterator` inserts elements at the
|
| 2687 |
end of a container, `front_insert_iterator` inserts elements at the
|
| 2688 |
beginning of a container, and `insert_iterator` inserts elements where
|
| 2689 |
the iterator points to in a container. `back_inserter`,
|
| 2690 |
`front_inserter`, and `inserter` are three functions making the insert
|
|
|
|
| 2695 |
``` cpp
|
| 2696 |
namespace std {
|
| 2697 |
template<class Container>
|
| 2698 |
class back_insert_iterator {
|
| 2699 |
protected:
|
| 2700 |
+
Container* container = nullptr;
|
| 2701 |
|
| 2702 |
public:
|
| 2703 |
using iterator_category = output_iterator_tag;
|
| 2704 |
using value_type = void;
|
| 2705 |
+
using difference_type = ptrdiff_t;
|
| 2706 |
using pointer = void;
|
| 2707 |
using reference = void;
|
| 2708 |
using container_type = Container;
|
| 2709 |
|
| 2710 |
+
constexpr back_insert_iterator() noexcept = default;
|
| 2711 |
+
constexpr explicit back_insert_iterator(Container& x);
|
| 2712 |
+
constexpr back_insert_iterator& operator=(const typename Container::value_type& value);
|
| 2713 |
+
constexpr back_insert_iterator& operator=(typename Container::value_type&& value);
|
| 2714 |
|
| 2715 |
+
constexpr back_insert_iterator& operator*();
|
| 2716 |
+
constexpr back_insert_iterator& operator++();
|
| 2717 |
+
constexpr back_insert_iterator operator++(int);
|
| 2718 |
};
|
|
|
|
|
|
|
|
|
|
| 2719 |
}
|
| 2720 |
```
|
| 2721 |
|
| 2722 |
+
##### Operations <a id="back.insert.iter.ops">[[back.insert.iter.ops]]</a>
|
|
|
|
|
|
|
| 2723 |
|
| 2724 |
``` cpp
|
| 2725 |
+
constexpr explicit back_insert_iterator(Container& x);
|
| 2726 |
```
|
| 2727 |
|
| 2728 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 2729 |
|
|
|
|
|
|
|
| 2730 |
``` cpp
|
| 2731 |
+
constexpr back_insert_iterator& operator=(const typename Container::value_type& value);
|
| 2732 |
```
|
| 2733 |
|
| 2734 |
*Effects:* As if by: `container->push_back(value);`
|
| 2735 |
|
| 2736 |
*Returns:* `*this`.
|
| 2737 |
|
| 2738 |
``` cpp
|
| 2739 |
+
constexpr back_insert_iterator& operator=(typename Container::value_type&& value);
|
| 2740 |
```
|
| 2741 |
|
| 2742 |
*Effects:* As if by: `container->push_back(std::move(value));`
|
| 2743 |
|
| 2744 |
*Returns:* `*this`.
|
| 2745 |
|
|
|
|
|
|
|
| 2746 |
``` cpp
|
| 2747 |
+
constexpr back_insert_iterator& operator*();
|
| 2748 |
```
|
| 2749 |
|
| 2750 |
*Returns:* `*this`.
|
| 2751 |
|
|
|
|
|
|
|
| 2752 |
``` cpp
|
| 2753 |
+
constexpr back_insert_iterator& operator++();
|
| 2754 |
+
constexpr back_insert_iterator operator++(int);
|
| 2755 |
```
|
| 2756 |
|
| 2757 |
*Returns:* `*this`.
|
| 2758 |
|
| 2759 |
##### `back_inserter` <a id="back.inserter">[[back.inserter]]</a>
|
| 2760 |
|
| 2761 |
``` cpp
|
| 2762 |
template<class Container>
|
| 2763 |
+
constexpr back_insert_iterator<Container> back_inserter(Container& x);
|
| 2764 |
```
|
| 2765 |
|
| 2766 |
*Returns:* `back_insert_iterator<Container>(x)`.
|
| 2767 |
|
| 2768 |
#### Class template `front_insert_iterator` <a id="front.insert.iterator">[[front.insert.iterator]]</a>
|
|
|
|
| 2770 |
``` cpp
|
| 2771 |
namespace std {
|
| 2772 |
template<class Container>
|
| 2773 |
class front_insert_iterator {
|
| 2774 |
protected:
|
| 2775 |
+
Container* container = nullptr;
|
| 2776 |
|
| 2777 |
public:
|
| 2778 |
using iterator_category = output_iterator_tag;
|
| 2779 |
using value_type = void;
|
| 2780 |
+
using difference_type = ptrdiff_t;
|
| 2781 |
using pointer = void;
|
| 2782 |
using reference = void;
|
| 2783 |
using container_type = Container;
|
| 2784 |
|
| 2785 |
+
constexpr front_insert_iterator() noexcept = default;
|
| 2786 |
+
constexpr explicit front_insert_iterator(Container& x);
|
| 2787 |
+
constexpr front_insert_iterator& operator=(const typename Container::value_type& value);
|
| 2788 |
+
constexpr front_insert_iterator& operator=(typename Container::value_type&& value);
|
| 2789 |
|
| 2790 |
+
constexpr front_insert_iterator& operator*();
|
| 2791 |
+
constexpr front_insert_iterator& operator++();
|
| 2792 |
+
constexpr front_insert_iterator operator++(int);
|
| 2793 |
};
|
|
|
|
|
|
|
|
|
|
| 2794 |
}
|
| 2795 |
```
|
| 2796 |
|
| 2797 |
+
##### Operations <a id="front.insert.iter.ops">[[front.insert.iter.ops]]</a>
|
|
|
|
|
|
|
| 2798 |
|
| 2799 |
``` cpp
|
| 2800 |
+
constexpr explicit front_insert_iterator(Container& x);
|
| 2801 |
```
|
| 2802 |
|
| 2803 |
*Effects:* Initializes `container` with `addressof(x)`.
|
| 2804 |
|
|
|
|
|
|
|
| 2805 |
``` cpp
|
| 2806 |
+
constexpr front_insert_iterator& operator=(const typename Container::value_type& value);
|
| 2807 |
```
|
| 2808 |
|
| 2809 |
*Effects:* As if by: `container->push_front(value);`
|
| 2810 |
|
| 2811 |
*Returns:* `*this`.
|
| 2812 |
|
| 2813 |
``` cpp
|
| 2814 |
+
constexpr front_insert_iterator& operator=(typename Container::value_type&& value);
|
| 2815 |
```
|
| 2816 |
|
| 2817 |
*Effects:* As if by: `container->push_front(std::move(value));`
|
| 2818 |
|
| 2819 |
*Returns:* `*this`.
|
| 2820 |
|
|
|
|
|
|
|
| 2821 |
``` cpp
|
| 2822 |
+
constexpr front_insert_iterator& operator*();
|
| 2823 |
```
|
| 2824 |
|
| 2825 |
*Returns:* `*this`.
|
| 2826 |
|
|
|
|
|
|
|
| 2827 |
``` cpp
|
| 2828 |
+
constexpr front_insert_iterator& operator++();
|
| 2829 |
+
constexpr front_insert_iterator operator++(int);
|
| 2830 |
```
|
| 2831 |
|
| 2832 |
*Returns:* `*this`.
|
| 2833 |
|
| 2834 |
##### `front_inserter` <a id="front.inserter">[[front.inserter]]</a>
|
| 2835 |
|
| 2836 |
``` cpp
|
| 2837 |
template<class Container>
|
| 2838 |
+
constexpr front_insert_iterator<Container> front_inserter(Container& x);
|
| 2839 |
```
|
| 2840 |
|
| 2841 |
*Returns:* `front_insert_iterator<Container>(x)`.
|
| 2842 |
|
| 2843 |
#### Class template `insert_iterator` <a id="insert.iterator">[[insert.iterator]]</a>
|
|
|
|
| 2845 |
``` cpp
|
| 2846 |
namespace std {
|
| 2847 |
template<class Container>
|
| 2848 |
class insert_iterator {
|
| 2849 |
protected:
|
| 2850 |
+
Container* container = nullptr;
|
| 2851 |
+
ranges::iterator_t<Container> iter = ranges::iterator_t<Container>();
|
| 2852 |
|
| 2853 |
public:
|
| 2854 |
using iterator_category = output_iterator_tag;
|
| 2855 |
using value_type = void;
|
| 2856 |
+
using difference_type = ptrdiff_t;
|
| 2857 |
using pointer = void;
|
| 2858 |
using reference = void;
|
| 2859 |
using container_type = Container;
|
| 2860 |
|
| 2861 |
+
insert_iterator() = default;
|
| 2862 |
+
constexpr insert_iterator(Container& x, ranges::iterator_t<Container> i);
|
| 2863 |
+
constexpr insert_iterator& operator=(const typename Container::value_type& value);
|
| 2864 |
+
constexpr insert_iterator& operator=(typename Container::value_type&& value);
|
| 2865 |
|
| 2866 |
+
constexpr insert_iterator& operator*();
|
| 2867 |
+
constexpr insert_iterator& operator++();
|
| 2868 |
+
constexpr insert_iterator& operator++(int);
|
| 2869 |
};
|
|
|
|
|
|
|
|
|
|
| 2870 |
}
|
| 2871 |
```
|
| 2872 |
|
| 2873 |
+
##### Operations <a id="insert.iter.ops">[[insert.iter.ops]]</a>
|
|
|
|
|
|
|
| 2874 |
|
| 2875 |
``` cpp
|
| 2876 |
+
constexpr insert_iterator(Container& x, ranges::iterator_t<Container> i);
|
| 2877 |
```
|
| 2878 |
|
| 2879 |
*Effects:* Initializes `container` with `addressof(x)` and `iter` with
|
| 2880 |
`i`.
|
| 2881 |
|
|
|
|
|
|
|
| 2882 |
``` cpp
|
| 2883 |
+
constexpr insert_iterator& operator=(const typename Container::value_type& value);
|
| 2884 |
```
|
| 2885 |
|
| 2886 |
*Effects:* As if by:
|
| 2887 |
|
| 2888 |
``` cpp
|
|
|
|
| 2891 |
```
|
| 2892 |
|
| 2893 |
*Returns:* `*this`.
|
| 2894 |
|
| 2895 |
``` cpp
|
| 2896 |
+
constexpr insert_iterator& operator=(typename Container::value_type&& value);
|
| 2897 |
```
|
| 2898 |
|
| 2899 |
*Effects:* As if by:
|
| 2900 |
|
| 2901 |
``` cpp
|
|
|
|
| 2903 |
++iter;
|
| 2904 |
```
|
| 2905 |
|
| 2906 |
*Returns:* `*this`.
|
| 2907 |
|
|
|
|
|
|
|
| 2908 |
``` cpp
|
| 2909 |
+
constexpr insert_iterator& operator*();
|
| 2910 |
```
|
| 2911 |
|
| 2912 |
*Returns:* `*this`.
|
| 2913 |
|
|
|
|
|
|
|
| 2914 |
``` cpp
|
| 2915 |
+
constexpr insert_iterator& operator++();
|
| 2916 |
+
constexpr insert_iterator& operator++(int);
|
| 2917 |
```
|
| 2918 |
|
| 2919 |
*Returns:* `*this`.
|
| 2920 |
|
| 2921 |
##### `inserter` <a id="inserter">[[inserter]]</a>
|
| 2922 |
|
| 2923 |
``` cpp
|
| 2924 |
template<class Container>
|
| 2925 |
+
constexpr insert_iterator<Container>
|
| 2926 |
+
inserter(Container& x, ranges::iterator_t<Container> i);
|
| 2927 |
```
|
| 2928 |
|
| 2929 |
*Returns:* `insert_iterator<Container>(x, i)`.
|
| 2930 |
|
| 2931 |
+
### Move iterators and sentinels <a id="move.iterators">[[move.iterators]]</a>
|
| 2932 |
|
| 2933 |
Class template `move_iterator` is an iterator adaptor with the same
|
| 2934 |
behavior as the underlying iterator except that its indirection operator
|
| 2935 |
implicitly converts the value returned by the underlying iterator’s
|
| 2936 |
indirection operator to an rvalue. Some generic algorithms can be called
|
|
|
|
| 2954 |
namespace std {
|
| 2955 |
template<class Iterator>
|
| 2956 |
class move_iterator {
|
| 2957 |
public:
|
| 2958 |
using iterator_type = Iterator;
|
| 2959 |
+
using iterator_concept = input_iterator_tag;
|
| 2960 |
+
using iterator_category = see below;
|
| 2961 |
+
using value_type = iter_value_t<Iterator>;
|
| 2962 |
+
using difference_type = iter_difference_t<Iterator>;
|
| 2963 |
using pointer = Iterator;
|
| 2964 |
+
using reference = iter_rvalue_reference_t<Iterator>;
|
| 2965 |
|
| 2966 |
constexpr move_iterator();
|
| 2967 |
constexpr explicit move_iterator(Iterator i);
|
| 2968 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 2969 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 2970 |
|
| 2971 |
+
constexpr iterator_type base() const &;
|
| 2972 |
+
constexpr iterator_type base() &&;
|
| 2973 |
constexpr reference operator*() const;
|
|
|
|
| 2974 |
|
| 2975 |
constexpr move_iterator& operator++();
|
| 2976 |
+
constexpr auto operator++(int);
|
| 2977 |
constexpr move_iterator& operator--();
|
| 2978 |
constexpr move_iterator operator--(int);
|
| 2979 |
|
| 2980 |
constexpr move_iterator operator+(difference_type n) const;
|
| 2981 |
constexpr move_iterator& operator+=(difference_type n);
|
| 2982 |
constexpr move_iterator operator-(difference_type n) const;
|
| 2983 |
constexpr move_iterator& operator-=(difference_type n);
|
| 2984 |
+
constexpr reference operator[](difference_type n) const;
|
| 2985 |
+
|
| 2986 |
+
template<sentinel_for<Iterator> S>
|
| 2987 |
+
friend constexpr bool
|
| 2988 |
+
operator==(const move_iterator& x, const move_sentinel<S>& y);
|
| 2989 |
+
template<sized_sentinel_for<Iterator> S>
|
| 2990 |
+
friend constexpr iter_difference_t<Iterator>
|
| 2991 |
+
operator-(const move_sentinel<S>& x, const move_iterator& y);
|
| 2992 |
+
template<sized_sentinel_for<Iterator> S>
|
| 2993 |
+
friend constexpr iter_difference_t<Iterator>
|
| 2994 |
+
operator-(const move_iterator& x, const move_sentinel<S>& y);
|
| 2995 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 2996 |
+
iter_move(const move_iterator& i)
|
| 2997 |
+
noexcept(noexcept(ranges::iter_move(i.current)));
|
| 2998 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 2999 |
+
friend constexpr void
|
| 3000 |
+
iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y)
|
| 3001 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 3002 |
|
| 3003 |
private:
|
| 3004 |
Iterator current; // exposition only
|
| 3005 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3006 |
}
|
| 3007 |
```
|
| 3008 |
|
| 3009 |
+
The member *typedef-name* `iterator_category` denotes
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3010 |
|
| 3011 |
+
- `random_access_iterator_tag` if the type
|
| 3012 |
+
`iterator_traits<{}Iterator>::iterator_category` models
|
| 3013 |
+
`derived_from<random_access_iterator_tag>`, and
|
| 3014 |
+
- `iterator_traits<{}Iterator>::iterator_category` otherwise.
|
| 3015 |
|
| 3016 |
+
#### Requirements <a id="move.iter.requirements">[[move.iter.requirements]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3017 |
|
| 3018 |
+
The template parameter `Iterator` shall either meet the
|
| 3019 |
+
*Cpp17InputIterator* requirements [[input.iterators]] or model
|
| 3020 |
+
`input_iterator` [[iterator.concept.input]]. Additionally, if any of the
|
| 3021 |
+
bidirectional traversal functions are instantiated, the template
|
| 3022 |
+
parameter shall either meet the *Cpp17BidirectionalIterator*
|
| 3023 |
+
requirements [[bidirectional.iterators]] or model
|
| 3024 |
+
`bidirectional_iterator` [[iterator.concept.bidir]]. If any of the
|
| 3025 |
+
random access traversal functions are instantiated, the template
|
| 3026 |
+
parameter shall either meet the *Cpp17RandomAccessIterator* requirements
|
| 3027 |
+
[[random.access.iterators]] or model `random_access_iterator`
|
| 3028 |
+
[[iterator.concept.random.access]].
|
| 3029 |
|
| 3030 |
+
#### Construction and assignment <a id="move.iter.cons">[[move.iter.cons]]</a>
|
| 3031 |
|
| 3032 |
``` cpp
|
| 3033 |
constexpr move_iterator();
|
| 3034 |
```
|
| 3035 |
|
|
|
|
| 3041 |
``` cpp
|
| 3042 |
constexpr explicit move_iterator(Iterator i);
|
| 3043 |
```
|
| 3044 |
|
| 3045 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 3046 |
+
`std::move(i)`.
|
| 3047 |
|
| 3048 |
``` cpp
|
| 3049 |
template<class U> constexpr move_iterator(const move_iterator<U>& u);
|
| 3050 |
```
|
| 3051 |
|
| 3052 |
+
*Mandates:* `U` is convertible to `Iterator`.
|
| 3053 |
+
|
| 3054 |
*Effects:* Constructs a `move_iterator`, initializing `current` with
|
| 3055 |
`u.base()`.
|
| 3056 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3057 |
``` cpp
|
| 3058 |
template<class U> constexpr move_iterator& operator=(const move_iterator<U>& u);
|
| 3059 |
```
|
| 3060 |
|
| 3061 |
+
*Mandates:* `U` is convertible to `Iterator`.
|
| 3062 |
+
|
| 3063 |
*Effects:* Assigns `u.base()` to `current`.
|
| 3064 |
|
| 3065 |
+
#### Conversion <a id="move.iter.op.conv">[[move.iter.op.conv]]</a>
|
|
|
|
|
|
|
| 3066 |
|
| 3067 |
``` cpp
|
| 3068 |
+
constexpr Iterator base() const &;
|
| 3069 |
```
|
| 3070 |
|
| 3071 |
+
*Constraints:* `Iterator` satisfies `copy_constructible`.
|
| 3072 |
+
|
| 3073 |
+
*Preconditions:* `Iterator` models `copy_constructible`.
|
| 3074 |
+
|
| 3075 |
*Returns:* `current`.
|
| 3076 |
|
| 3077 |
+
``` cpp
|
| 3078 |
+
constexpr Iterator base() &&;
|
| 3079 |
+
```
|
| 3080 |
+
|
| 3081 |
+
*Returns:* `std::move(current)`.
|
| 3082 |
+
|
| 3083 |
+
#### Element access <a id="move.iter.elem">[[move.iter.elem]]</a>
|
| 3084 |
|
| 3085 |
``` cpp
|
| 3086 |
constexpr reference operator*() const;
|
| 3087 |
```
|
| 3088 |
|
| 3089 |
+
*Effects:* Equivalent to: `return ranges::iter_move(current);`
|
|
|
|
|
|
|
| 3090 |
|
| 3091 |
``` cpp
|
| 3092 |
+
constexpr reference operator[](difference_type n) const;
|
| 3093 |
```
|
| 3094 |
|
| 3095 |
+
*Effects:* Equivalent to: `ranges::iter_move(current + n);`
|
| 3096 |
|
| 3097 |
+
#### Navigation <a id="move.iter.nav">[[move.iter.nav]]</a>
|
| 3098 |
|
| 3099 |
``` cpp
|
| 3100 |
constexpr move_iterator& operator++();
|
| 3101 |
```
|
| 3102 |
|
| 3103 |
*Effects:* As if by `++current`.
|
| 3104 |
|
| 3105 |
*Returns:* `*this`.
|
| 3106 |
|
| 3107 |
``` cpp
|
| 3108 |
+
constexpr auto operator++(int);
|
| 3109 |
```
|
| 3110 |
|
| 3111 |
+
*Effects:* If `Iterator` models `forward_iterator`, equivalent to:
|
| 3112 |
|
| 3113 |
``` cpp
|
| 3114 |
move_iterator tmp = *this;
|
| 3115 |
++current;
|
| 3116 |
return tmp;
|
| 3117 |
```
|
| 3118 |
|
| 3119 |
+
Otherwise, equivalent to `++current`.
|
| 3120 |
|
| 3121 |
``` cpp
|
| 3122 |
constexpr move_iterator& operator--();
|
| 3123 |
```
|
| 3124 |
|
|
|
|
| 3136 |
move_iterator tmp = *this;
|
| 3137 |
--current;
|
| 3138 |
return tmp;
|
| 3139 |
```
|
| 3140 |
|
|
|
|
|
|
|
| 3141 |
``` cpp
|
| 3142 |
constexpr move_iterator operator+(difference_type n) const;
|
| 3143 |
```
|
| 3144 |
|
| 3145 |
*Returns:* `move_iterator(current + n)`.
|
| 3146 |
|
|
|
|
|
|
|
| 3147 |
``` cpp
|
| 3148 |
constexpr move_iterator& operator+=(difference_type n);
|
| 3149 |
```
|
| 3150 |
|
| 3151 |
*Effects:* As if by: `current += n;`
|
| 3152 |
|
| 3153 |
*Returns:* `*this`.
|
| 3154 |
|
|
|
|
|
|
|
| 3155 |
``` cpp
|
| 3156 |
constexpr move_iterator operator-(difference_type n) const;
|
| 3157 |
```
|
| 3158 |
|
| 3159 |
*Returns:* `move_iterator(current - n)`.
|
| 3160 |
|
|
|
|
|
|
|
| 3161 |
``` cpp
|
| 3162 |
constexpr move_iterator& operator-=(difference_type n);
|
| 3163 |
```
|
| 3164 |
|
| 3165 |
*Effects:* As if by: `current -= n;`
|
| 3166 |
|
| 3167 |
*Returns:* `*this`.
|
| 3168 |
|
| 3169 |
+
#### Comparisons <a id="move.iter.op.comp">[[move.iter.op.comp]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3170 |
|
| 3171 |
``` cpp
|
| 3172 |
template<class Iterator1, class Iterator2>
|
| 3173 |
+
constexpr bool operator==(const move_iterator<Iterator1>& x,
|
| 3174 |
+
const move_iterator<Iterator2>& y);
|
| 3175 |
+
template<sentinel_for<Iterator> S>
|
| 3176 |
+
friend constexpr bool operator==(const move_iterator& x,
|
| 3177 |
+
const move_sentinel<S>& y);
|
| 3178 |
```
|
| 3179 |
|
| 3180 |
+
*Constraints:* `x.base() == y.base()` is well-formed and convertible to
|
| 3181 |
+
`bool`.
|
| 3182 |
+
|
| 3183 |
*Returns:* `x.base() == y.base()`.
|
| 3184 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3185 |
``` cpp
|
| 3186 |
template<class Iterator1, class Iterator2>
|
| 3187 |
constexpr bool operator<(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 3188 |
```
|
| 3189 |
|
| 3190 |
+
*Constraints:* `x.base() < y.base()` is well-formed and convertible to
|
| 3191 |
+
`bool`.
|
| 3192 |
+
|
| 3193 |
*Returns:* `x.base() < y.base()`.
|
| 3194 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3195 |
``` cpp
|
| 3196 |
template<class Iterator1, class Iterator2>
|
| 3197 |
constexpr bool operator>(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 3198 |
```
|
| 3199 |
|
| 3200 |
+
*Constraints:* `y.base() < x.base()` is well-formed and convertible to
|
| 3201 |
+
`bool`.
|
| 3202 |
+
|
| 3203 |
*Returns:* `y < x`.
|
| 3204 |
|
| 3205 |
+
``` cpp
|
| 3206 |
+
template<class Iterator1, class Iterator2>
|
| 3207 |
+
constexpr bool operator<=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 3208 |
+
```
|
| 3209 |
+
|
| 3210 |
+
*Constraints:* `y.base() < x.base()` is well-formed and convertible to
|
| 3211 |
+
`bool`.
|
| 3212 |
+
|
| 3213 |
+
*Returns:* `!(y < x)`.
|
| 3214 |
+
|
| 3215 |
``` cpp
|
| 3216 |
template<class Iterator1, class Iterator2>
|
| 3217 |
constexpr bool operator>=(const move_iterator<Iterator1>& x, const move_iterator<Iterator2>& y);
|
| 3218 |
```
|
| 3219 |
|
| 3220 |
+
*Constraints:* `x.base() < y.base()` is well-formed and convertible to
|
| 3221 |
+
`bool`.
|
| 3222 |
+
|
| 3223 |
*Returns:* `!(x < y)`.
|
| 3224 |
|
| 3225 |
+
``` cpp
|
| 3226 |
+
template<class Iterator1, three_way_comparable_with<Iterator1> Iterator2>
|
| 3227 |
+
constexpr compare_three_way_result_t<Iterator1, Iterator2>
|
| 3228 |
+
operator<=>(const move_iterator<Iterator1>& x,
|
| 3229 |
+
const move_iterator<Iterator2>& y);
|
| 3230 |
+
```
|
| 3231 |
+
|
| 3232 |
+
*Returns:* `x.base() <=> y.base()`.
|
| 3233 |
+
|
| 3234 |
+
#### Non-member functions <a id="move.iter.nonmember">[[move.iter.nonmember]]</a>
|
| 3235 |
|
| 3236 |
``` cpp
|
| 3237 |
template<class Iterator1, class Iterator2>
|
| 3238 |
+
constexpr auto operator-(const move_iterator<Iterator1>& x,
|
| 3239 |
+
const move_iterator<Iterator2>& y)
|
| 3240 |
+
-> decltype(x.base() - y.base());
|
| 3241 |
+
template<sized_sentinel_for<Iterator> S>
|
| 3242 |
+
friend constexpr iter_difference_t<Iterator>
|
| 3243 |
+
operator-(const move_sentinel<S>& x, const move_iterator& y);
|
| 3244 |
+
template<sized_sentinel_for<Iterator> S>
|
| 3245 |
+
friend constexpr iter_difference_t<Iterator>
|
| 3246 |
+
operator-(const move_iterator& x, const move_sentinel<S>& y);
|
| 3247 |
```
|
| 3248 |
|
| 3249 |
*Returns:* `x.base() - y.base()`.
|
| 3250 |
|
| 3251 |
``` cpp
|
| 3252 |
template<class Iterator>
|
| 3253 |
+
constexpr move_iterator<Iterator>
|
| 3254 |
+
operator+(iter_difference_t<Iterator> n, const move_iterator<Iterator>& x);
|
| 3255 |
```
|
| 3256 |
|
| 3257 |
+
*Constraints:* `x + n` is well-formed and has type `Iterator`.
|
| 3258 |
+
|
| 3259 |
*Returns:* `x + n`.
|
| 3260 |
|
| 3261 |
+
``` cpp
|
| 3262 |
+
friend constexpr iter_rvalue_reference_t<Iterator>
|
| 3263 |
+
iter_move(const move_iterator& i)
|
| 3264 |
+
noexcept(noexcept(ranges::iter_move(i.current)));
|
| 3265 |
+
```
|
| 3266 |
+
|
| 3267 |
+
*Effects:* Equivalent to: `return ranges::iter_move(i.current);`
|
| 3268 |
+
|
| 3269 |
+
``` cpp
|
| 3270 |
+
template<indirectly_swappable<Iterator> Iterator2>
|
| 3271 |
+
friend constexpr void
|
| 3272 |
+
iter_swap(const move_iterator& x, const move_iterator<Iterator2>& y)
|
| 3273 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 3274 |
+
```
|
| 3275 |
+
|
| 3276 |
+
*Effects:* Equivalent to: `ranges::iter_swap(x.current, y.current)`.
|
| 3277 |
+
|
| 3278 |
``` cpp
|
| 3279 |
template<class Iterator>
|
| 3280 |
constexpr move_iterator<Iterator> make_move_iterator(Iterator i);
|
| 3281 |
```
|
| 3282 |
|
| 3283 |
+
*Returns:* `move_iterator<Iterator>(std::move(i))`.
|
| 3284 |
+
|
| 3285 |
+
#### Class template `move_sentinel` <a id="move.sentinel">[[move.sentinel]]</a>
|
| 3286 |
+
|
| 3287 |
+
Class template `move_sentinel` is a sentinel adaptor useful for denoting
|
| 3288 |
+
ranges together with `move_iterator`. When an input iterator type `I`
|
| 3289 |
+
and sentinel type `S` model `sentinel_for<S, I>`, `move_sentinel<S>` and
|
| 3290 |
+
`move_iterator<I>` model
|
| 3291 |
+
`sentinel_for<move_sentinel<S>, move_iterator<I>{>}` as well.
|
| 3292 |
+
|
| 3293 |
+
[*Example 1*:
|
| 3294 |
+
|
| 3295 |
+
A `move_if` algorithm is easily implemented with `copy_if` using
|
| 3296 |
+
`move_iterator` and `move_sentinel`:
|
| 3297 |
+
|
| 3298 |
+
``` cpp
|
| 3299 |
+
template<input_iterator I, sentinel_for<I> S, weakly_incrementable O,
|
| 3300 |
+
indirect_unary_predicate<I> Pred>
|
| 3301 |
+
requires indirectly_movable<I, O>
|
| 3302 |
+
void move_if(I first, S last, O out, Pred pred) {
|
| 3303 |
+
std::ranges::copy_if(move_iterator<I>{first}, move_sentinel<S>{last}, out, pred);
|
| 3304 |
+
}
|
| 3305 |
+
```
|
| 3306 |
+
|
| 3307 |
+
— *end example*]
|
| 3308 |
+
|
| 3309 |
+
``` cpp
|
| 3310 |
+
namespace std {
|
| 3311 |
+
template<semiregular S>
|
| 3312 |
+
class move_sentinel {
|
| 3313 |
+
public:
|
| 3314 |
+
constexpr move_sentinel();
|
| 3315 |
+
constexpr explicit move_sentinel(S s);
|
| 3316 |
+
template<class S2>
|
| 3317 |
+
requires convertible_to<const S2&, S>
|
| 3318 |
+
constexpr move_sentinel(const move_sentinel<S2>& s);
|
| 3319 |
+
template<class S2>
|
| 3320 |
+
requires assignable_from<S&, const S2&>
|
| 3321 |
+
constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
|
| 3322 |
+
|
| 3323 |
+
constexpr S base() const;
|
| 3324 |
+
private:
|
| 3325 |
+
S last; // exposition only
|
| 3326 |
+
};
|
| 3327 |
+
}
|
| 3328 |
+
```
|
| 3329 |
+
|
| 3330 |
+
#### Operations <a id="move.sent.ops">[[move.sent.ops]]</a>
|
| 3331 |
+
|
| 3332 |
+
``` cpp
|
| 3333 |
+
constexpr move_sentinel();
|
| 3334 |
+
```
|
| 3335 |
+
|
| 3336 |
+
*Effects:* Value-initializes `last`. If
|
| 3337 |
+
`is_trivially_default_constructible_v<S>` is `true`, then this
|
| 3338 |
+
constructor is a `constexpr` constructor.
|
| 3339 |
+
|
| 3340 |
+
``` cpp
|
| 3341 |
+
constexpr explicit move_sentinel(S s);
|
| 3342 |
+
```
|
| 3343 |
+
|
| 3344 |
+
*Effects:* Initializes `last` with `std::move(s)`.
|
| 3345 |
+
|
| 3346 |
+
``` cpp
|
| 3347 |
+
template<class S2>
|
| 3348 |
+
requires convertible_to<const S2&, S>
|
| 3349 |
+
constexpr move_sentinel(const move_sentinel<S2>& s);
|
| 3350 |
+
```
|
| 3351 |
+
|
| 3352 |
+
*Effects:* Initializes `last` with `s.last`.
|
| 3353 |
+
|
| 3354 |
+
``` cpp
|
| 3355 |
+
template<class S2>
|
| 3356 |
+
requires assignable_from<S&, const S2&>
|
| 3357 |
+
constexpr move_sentinel& operator=(const move_sentinel<S2>& s);
|
| 3358 |
+
```
|
| 3359 |
+
|
| 3360 |
+
*Effects:* Equivalent to: `last = s.last; return *this;`
|
| 3361 |
+
|
| 3362 |
+
``` cpp
|
| 3363 |
+
constexpr S base() const;
|
| 3364 |
+
```
|
| 3365 |
+
|
| 3366 |
+
*Returns:* `last`.
|
| 3367 |
+
|
| 3368 |
+
### Common iterators <a id="iterators.common">[[iterators.common]]</a>
|
| 3369 |
+
|
| 3370 |
+
#### Class template `common_iterator` <a id="common.iterator">[[common.iterator]]</a>
|
| 3371 |
+
|
| 3372 |
+
Class template `common_iterator` is an iterator/sentinel adaptor that is
|
| 3373 |
+
capable of representing a non-common range of elements (where the types
|
| 3374 |
+
of the iterator and sentinel differ) as a common range (where they are
|
| 3375 |
+
the same). It does this by holding either an iterator or a sentinel, and
|
| 3376 |
+
implementing the equality comparison operators appropriately.
|
| 3377 |
+
|
| 3378 |
+
[*Note 1*: The `common_iterator` type is useful for interfacing with
|
| 3379 |
+
legacy code that expects the begin and end of a range to have the same
|
| 3380 |
+
type. — *end note*]
|
| 3381 |
+
|
| 3382 |
+
[*Example 1*:
|
| 3383 |
+
|
| 3384 |
+
``` cpp
|
| 3385 |
+
template<class ForwardIterator>
|
| 3386 |
+
void fun(ForwardIterator begin, ForwardIterator end);
|
| 3387 |
+
|
| 3388 |
+
list<int> s;
|
| 3389 |
+
// populate the list s
|
| 3390 |
+
using CI = common_iterator<counted_iterator<list<int>::iterator>, default_sentinel_t>;
|
| 3391 |
+
// call fun on a range of 10 ints
|
| 3392 |
+
fun(CI(counted_iterator(s.begin(), 10)), CI(default_sentinel));
|
| 3393 |
+
```
|
| 3394 |
+
|
| 3395 |
+
— *end example*]
|
| 3396 |
+
|
| 3397 |
+
``` cpp
|
| 3398 |
+
namespace std {
|
| 3399 |
+
template<input_or_output_iterator I, sentinel_for<I> S>
|
| 3400 |
+
requires (!same_as<I, S> && copyable<I>)
|
| 3401 |
+
class common_iterator {
|
| 3402 |
+
public:
|
| 3403 |
+
constexpr common_iterator() = default;
|
| 3404 |
+
constexpr common_iterator(I i);
|
| 3405 |
+
constexpr common_iterator(S s);
|
| 3406 |
+
template<class I2, class S2>
|
| 3407 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
|
| 3408 |
+
constexpr common_iterator(const common_iterator<I2, S2>& x);
|
| 3409 |
+
|
| 3410 |
+
template<class I2, class S2>
|
| 3411 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S> &&
|
| 3412 |
+
assignable_from<I&, const I2&> && assignable_from<S&, const S2&>
|
| 3413 |
+
common_iterator& operator=(const common_iterator<I2, S2>& x);
|
| 3414 |
+
|
| 3415 |
+
decltype(auto) operator*();
|
| 3416 |
+
decltype(auto) operator*() const
|
| 3417 |
+
requires dereferenceable<const I>;
|
| 3418 |
+
decltype(auto) operator->() const
|
| 3419 |
+
requires see below;
|
| 3420 |
+
|
| 3421 |
+
common_iterator& operator++();
|
| 3422 |
+
decltype(auto) operator++(int);
|
| 3423 |
+
|
| 3424 |
+
template<class I2, sentinel_for<I> S2>
|
| 3425 |
+
requires sentinel_for<S, I2>
|
| 3426 |
+
friend bool operator==(
|
| 3427 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 3428 |
+
template<class I2, sentinel_for<I> S2>
|
| 3429 |
+
requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
|
| 3430 |
+
friend bool operator==(
|
| 3431 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 3432 |
+
|
| 3433 |
+
template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
|
| 3434 |
+
requires sized_sentinel_for<S, I2>
|
| 3435 |
+
friend iter_difference_t<I2> operator-(
|
| 3436 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 3437 |
+
|
| 3438 |
+
friend iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
|
| 3439 |
+
noexcept(noexcept(ranges::iter_move(declval<const I&>())))
|
| 3440 |
+
requires input_iterator<I>;
|
| 3441 |
+
template<indirectly_swappable<I> I2, class S2>
|
| 3442 |
+
friend void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
|
| 3443 |
+
noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
|
| 3444 |
+
|
| 3445 |
+
private:
|
| 3446 |
+
variant<I, S> v_; // exposition only
|
| 3447 |
+
};
|
| 3448 |
+
|
| 3449 |
+
template<class I, class S>
|
| 3450 |
+
struct incrementable_traits<common_iterator<I, S>> {
|
| 3451 |
+
using difference_type = iter_difference_t<I>;
|
| 3452 |
+
};
|
| 3453 |
+
|
| 3454 |
+
template<input_iterator I, class S>
|
| 3455 |
+
struct iterator_traits<common_iterator<I, S>> {
|
| 3456 |
+
using iterator_concept = see below;
|
| 3457 |
+
using iterator_category = see below;
|
| 3458 |
+
using value_type = iter_value_t<I>;
|
| 3459 |
+
using difference_type = iter_difference_t<I>;
|
| 3460 |
+
using pointer = see below;
|
| 3461 |
+
using reference = iter_reference_t<I>;
|
| 3462 |
+
};
|
| 3463 |
+
}
|
| 3464 |
+
```
|
| 3465 |
+
|
| 3466 |
+
#### Associated types <a id="common.iter.types">[[common.iter.types]]</a>
|
| 3467 |
+
|
| 3468 |
+
The nested *typedef-name*s of the specialization of `iterator_traits`
|
| 3469 |
+
for `common_iterator<I, S>` are defined as follows.
|
| 3470 |
+
|
| 3471 |
+
- `iterator_concept` denotes `forward_iterator_tag` if `I` models
|
| 3472 |
+
`forward_iterator`; otherwise it denotes `input_iterator_tag`.
|
| 3473 |
+
- `iterator_category` denotes `forward_iterator_tag` if
|
| 3474 |
+
`iterator_traits<I>::iterator_category` models
|
| 3475 |
+
`derived_from<forward_iterator_tag>`; otherwise it denotes
|
| 3476 |
+
`input_iterator_tag`.
|
| 3477 |
+
- If the expression `a.operator->()` is well-formed, where `a` is an
|
| 3478 |
+
lvalue of type `const common_iterator<I, S>`, then `pointer` denotes
|
| 3479 |
+
the type of that expression. Otherwise, `pointer` denotes `void`.
|
| 3480 |
+
|
| 3481 |
+
#### Constructors and conversions <a id="common.iter.const">[[common.iter.const]]</a>
|
| 3482 |
+
|
| 3483 |
+
``` cpp
|
| 3484 |
+
constexpr common_iterator(I i);
|
| 3485 |
+
```
|
| 3486 |
+
|
| 3487 |
+
*Effects:* Initializes `v_` as if by
|
| 3488 |
+
`v_{in_place_type<I>, std::move(i)}`.
|
| 3489 |
+
|
| 3490 |
+
``` cpp
|
| 3491 |
+
constexpr common_iterator(S s);
|
| 3492 |
+
```
|
| 3493 |
+
|
| 3494 |
+
*Effects:* Initializes `v_` as if by
|
| 3495 |
+
`v_{in_place_type<S>, std::move(s)}`.
|
| 3496 |
+
|
| 3497 |
+
``` cpp
|
| 3498 |
+
template<class I2, class S2>
|
| 3499 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S>
|
| 3500 |
+
constexpr common_iterator(const common_iterator<I2, S2>& x);
|
| 3501 |
+
```
|
| 3502 |
+
|
| 3503 |
+
*Preconditions:* `x.v_.valueless_by_exception()` is `false`.
|
| 3504 |
+
|
| 3505 |
+
*Effects:* Initializes `v_` as if by
|
| 3506 |
+
`v_{in_place_index<`i`>, get<`i`>(x.v_)}`, where i is `x.v_.index()`.
|
| 3507 |
+
|
| 3508 |
+
``` cpp
|
| 3509 |
+
template<class I2, class S2>
|
| 3510 |
+
requires convertible_to<const I2&, I> && convertible_to<const S2&, S> &&
|
| 3511 |
+
assignable_from<I&, const I2&> && assignable_from<S&, const S2&>
|
| 3512 |
+
common_iterator& operator=(const common_iterator<I2, S2>& x);
|
| 3513 |
+
```
|
| 3514 |
+
|
| 3515 |
+
*Preconditions:* `x.v_.valueless_by_exception()` is `false`.
|
| 3516 |
+
|
| 3517 |
+
*Effects:* Equivalent to:
|
| 3518 |
+
|
| 3519 |
+
- If `v_.index() == x.v_.index()`, then `get<`i`>(v_) = get<`i`>(x.v_)`.
|
| 3520 |
+
- Otherwise, `v_.emplace<`i`>(get<`i`>(x.v_))`.
|
| 3521 |
+
|
| 3522 |
+
where i is `x.v_.index()`.
|
| 3523 |
+
|
| 3524 |
+
*Returns:* `*this`
|
| 3525 |
+
|
| 3526 |
+
#### Accessors <a id="common.iter.access">[[common.iter.access]]</a>
|
| 3527 |
+
|
| 3528 |
+
``` cpp
|
| 3529 |
+
decltype(auto) operator*();
|
| 3530 |
+
decltype(auto) operator*() const
|
| 3531 |
+
requires dereferenceable<const I>;
|
| 3532 |
+
```
|
| 3533 |
+
|
| 3534 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 3535 |
+
|
| 3536 |
+
*Effects:* Equivalent to: `return *get<I>(v_);`
|
| 3537 |
+
|
| 3538 |
+
``` cpp
|
| 3539 |
+
decltype(auto) operator->() const
|
| 3540 |
+
requires see below;
|
| 3541 |
+
```
|
| 3542 |
+
|
| 3543 |
+
The expression in the requires clause is equivalent to:
|
| 3544 |
+
|
| 3545 |
+
``` cpp
|
| 3546 |
+
indirectly_readable<const I> &&
|
| 3547 |
+
(requires(const I& i) { i.operator->(); } ||
|
| 3548 |
+
is_reference_v<iter_reference_t<I>> ||
|
| 3549 |
+
constructible_from<iter_value_t<I>, iter_reference_t<I>>)
|
| 3550 |
+
```
|
| 3551 |
+
|
| 3552 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 3553 |
+
|
| 3554 |
+
*Effects:*
|
| 3555 |
+
|
| 3556 |
+
- If `I` is a pointer type or if the expression
|
| 3557 |
+
`get<I>(v_).operator->()` is well-formed, equivalent to:
|
| 3558 |
+
`return get<I>(v_);`
|
| 3559 |
+
- Otherwise, if `iter_reference_t<I>` is a reference type, equivalent
|
| 3560 |
+
to:
|
| 3561 |
+
``` cpp
|
| 3562 |
+
auto&& tmp = *get<I>(v_);
|
| 3563 |
+
return addressof(tmp);
|
| 3564 |
+
```
|
| 3565 |
+
- Otherwise, equivalent to: `return `*`proxy`*`(*get<I>(v_));` where
|
| 3566 |
+
*proxy* is the exposition-only class:
|
| 3567 |
+
``` cpp
|
| 3568 |
+
class proxy {
|
| 3569 |
+
iter_value_t<I> keep_;
|
| 3570 |
+
proxy(iter_reference_t<I>&& x)
|
| 3571 |
+
: keep_(std::move(x)) {}
|
| 3572 |
+
public:
|
| 3573 |
+
const iter_value_t<I>* operator->() const {
|
| 3574 |
+
return addressof(keep_);
|
| 3575 |
+
}
|
| 3576 |
+
};
|
| 3577 |
+
```
|
| 3578 |
+
|
| 3579 |
+
#### Navigation <a id="common.iter.nav">[[common.iter.nav]]</a>
|
| 3580 |
+
|
| 3581 |
+
``` cpp
|
| 3582 |
+
common_iterator& operator++();
|
| 3583 |
+
```
|
| 3584 |
+
|
| 3585 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 3586 |
+
|
| 3587 |
+
*Effects:* Equivalent to `++get<I>(v_)`.
|
| 3588 |
+
|
| 3589 |
+
*Returns:* `*this`.
|
| 3590 |
+
|
| 3591 |
+
``` cpp
|
| 3592 |
+
decltype(auto) operator++(int);
|
| 3593 |
+
```
|
| 3594 |
+
|
| 3595 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 3596 |
+
|
| 3597 |
+
*Effects:* If `I` models `forward_iterator`, equivalent to:
|
| 3598 |
+
|
| 3599 |
+
``` cpp
|
| 3600 |
+
common_iterator tmp = *this;
|
| 3601 |
+
++*this;
|
| 3602 |
+
return tmp;
|
| 3603 |
+
```
|
| 3604 |
+
|
| 3605 |
+
Otherwise, equivalent to: `return get<I>(v_)++;`
|
| 3606 |
+
|
| 3607 |
+
#### Comparisons <a id="common.iter.cmp">[[common.iter.cmp]]</a>
|
| 3608 |
+
|
| 3609 |
+
``` cpp
|
| 3610 |
+
template<class I2, sentinel_for<I> S2>
|
| 3611 |
+
requires sentinel_for<S, I2>
|
| 3612 |
+
friend bool operator==(
|
| 3613 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 3614 |
+
```
|
| 3615 |
+
|
| 3616 |
+
*Preconditions:* `x.v_.valueless_by_exception()` and
|
| 3617 |
+
`y.v_.valueless_by_exception()` are each `false`.
|
| 3618 |
+
|
| 3619 |
+
*Returns:* `true` if i` == `j, and otherwise
|
| 3620 |
+
`get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
|
| 3621 |
+
`y.v_.index()`.
|
| 3622 |
+
|
| 3623 |
+
``` cpp
|
| 3624 |
+
template<class I2, sentinel_for<I> S2>
|
| 3625 |
+
requires sentinel_for<S, I2> && equality_comparable_with<I, I2>
|
| 3626 |
+
friend bool operator==(
|
| 3627 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 3628 |
+
```
|
| 3629 |
+
|
| 3630 |
+
*Preconditions:* `x.v_.valueless_by_exception()` and
|
| 3631 |
+
`y.v_.valueless_by_exception()` are each `false`.
|
| 3632 |
+
|
| 3633 |
+
*Returns:* `true` if i and j are each `1`, and otherwise
|
| 3634 |
+
`get<`i`>(x.v_) == get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
|
| 3635 |
+
`y.v_.index()`.
|
| 3636 |
+
|
| 3637 |
+
``` cpp
|
| 3638 |
+
template<sized_sentinel_for<I> I2, sized_sentinel_for<I> S2>
|
| 3639 |
+
requires sized_sentinel_for<S, I2>
|
| 3640 |
+
friend iter_difference_t<I2> operator-(
|
| 3641 |
+
const common_iterator& x, const common_iterator<I2, S2>& y);
|
| 3642 |
+
```
|
| 3643 |
+
|
| 3644 |
+
*Preconditions:* `x.v_.valueless_by_exception()` and
|
| 3645 |
+
`y.v_.valueless_by_exception()` are each `false`.
|
| 3646 |
+
|
| 3647 |
+
*Returns:* `0` if i and j are each `1`, and otherwise
|
| 3648 |
+
`get<`i`>(x.v_) - get<`j`>(y.v_)`, where i is `x.v_.index()` and j is
|
| 3649 |
+
`y.v_.index()`.
|
| 3650 |
+
|
| 3651 |
+
#### Customization <a id="common.iter.cust">[[common.iter.cust]]</a>
|
| 3652 |
+
|
| 3653 |
+
``` cpp
|
| 3654 |
+
friend iter_rvalue_reference_t<I> iter_move(const common_iterator& i)
|
| 3655 |
+
noexcept(noexcept(ranges::iter_move(declval<const I&>())))
|
| 3656 |
+
requires input_iterator<I>;
|
| 3657 |
+
```
|
| 3658 |
+
|
| 3659 |
+
*Preconditions:* `holds_alternative<I>(v_)`.
|
| 3660 |
+
|
| 3661 |
+
*Effects:* Equivalent to: `return ranges::iter_move(get<I>(i.v_));`
|
| 3662 |
+
|
| 3663 |
+
``` cpp
|
| 3664 |
+
template<indirectly_swappable<I> I2, class S2>
|
| 3665 |
+
friend void iter_swap(const common_iterator& x, const common_iterator<I2, S2>& y)
|
| 3666 |
+
noexcept(noexcept(ranges::iter_swap(declval<const I&>(), declval<const I2&>())));
|
| 3667 |
+
```
|
| 3668 |
+
|
| 3669 |
+
*Preconditions:* `holds_alternative<I>(x.v_)` and
|
| 3670 |
+
`holds_alternative<I2>(y.v_)` are each `true`.
|
| 3671 |
+
|
| 3672 |
+
*Effects:* Equivalent to
|
| 3673 |
+
`ranges::iter_swap(get<I>(x.v_), get<I2>(y.v_))`.
|
| 3674 |
+
|
| 3675 |
+
### Default sentinels <a id="default.sentinels">[[default.sentinels]]</a>
|
| 3676 |
+
|
| 3677 |
+
``` cpp
|
| 3678 |
+
namespace std {
|
| 3679 |
+
struct default_sentinel_t { };
|
| 3680 |
+
}
|
| 3681 |
+
```
|
| 3682 |
+
|
| 3683 |
+
Class `default_sentinel_t` is an empty type used to denote the end of a
|
| 3684 |
+
range. It can be used together with iterator types that know the bound
|
| 3685 |
+
of their range (e.g., `counted_iterator` [[counted.iterator]]).
|
| 3686 |
+
|
| 3687 |
+
### Counted iterators <a id="iterators.counted">[[iterators.counted]]</a>
|
| 3688 |
+
|
| 3689 |
+
#### Class template `counted_iterator` <a id="counted.iterator">[[counted.iterator]]</a>
|
| 3690 |
+
|
| 3691 |
+
Class template `counted_iterator` is an iterator adaptor with the same
|
| 3692 |
+
behavior as the underlying iterator except that it keeps track of the
|
| 3693 |
+
distance to the end of its range. It can be used together with
|
| 3694 |
+
`default_sentinel` in calls to generic algorithms to operate on a range
|
| 3695 |
+
of N elements starting at a given position without needing to know the
|
| 3696 |
+
end position a priori.
|
| 3697 |
+
|
| 3698 |
+
[*Example 1*:
|
| 3699 |
+
|
| 3700 |
+
``` cpp
|
| 3701 |
+
list<string> s;
|
| 3702 |
+
// populate the list s with at least 10 strings
|
| 3703 |
+
vector<string> v;
|
| 3704 |
+
// copies 10 strings into v:
|
| 3705 |
+
ranges::copy(counted_iterator(s.begin(), 10), default_sentinel, back_inserter(v));
|
| 3706 |
+
```
|
| 3707 |
+
|
| 3708 |
+
— *end example*]
|
| 3709 |
+
|
| 3710 |
+
Two values `i1` and `i2` of types `counted_iterator<I1>` and
|
| 3711 |
+
`counted_iterator<I2>` refer to elements of the same sequence if and
|
| 3712 |
+
only if `next(i1.base(), i1.count())` and `next(i2.base(), i2.count())`
|
| 3713 |
+
refer to the same (possibly past-the-end) element.
|
| 3714 |
+
|
| 3715 |
+
``` cpp
|
| 3716 |
+
namespace std {
|
| 3717 |
+
template<input_or_output_iterator I>
|
| 3718 |
+
class counted_iterator {
|
| 3719 |
+
public:
|
| 3720 |
+
using iterator_type = I;
|
| 3721 |
+
|
| 3722 |
+
constexpr counted_iterator() = default;
|
| 3723 |
+
constexpr counted_iterator(I x, iter_difference_t<I> n);
|
| 3724 |
+
template<class I2>
|
| 3725 |
+
requires convertible_to<const I2&, I>
|
| 3726 |
+
constexpr counted_iterator(const counted_iterator<I2>& x);
|
| 3727 |
+
|
| 3728 |
+
template<class I2>
|
| 3729 |
+
requires assignable_from<I&, const I2&>
|
| 3730 |
+
constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
|
| 3731 |
+
|
| 3732 |
+
constexpr I base() const & requires copy_constructible<I>;
|
| 3733 |
+
constexpr I base() &&;
|
| 3734 |
+
constexpr iter_difference_t<I> count() const noexcept;
|
| 3735 |
+
constexpr decltype(auto) operator*();
|
| 3736 |
+
constexpr decltype(auto) operator*() const
|
| 3737 |
+
requires dereferenceable<const I>;
|
| 3738 |
+
|
| 3739 |
+
constexpr counted_iterator& operator++();
|
| 3740 |
+
decltype(auto) operator++(int);
|
| 3741 |
+
constexpr counted_iterator operator++(int)
|
| 3742 |
+
requires forward_iterator<I>;
|
| 3743 |
+
constexpr counted_iterator& operator--()
|
| 3744 |
+
requires bidirectional_iterator<I>;
|
| 3745 |
+
constexpr counted_iterator operator--(int)
|
| 3746 |
+
requires bidirectional_iterator<I>;
|
| 3747 |
+
|
| 3748 |
+
constexpr counted_iterator operator+(iter_difference_t<I> n) const
|
| 3749 |
+
requires random_access_iterator<I>;
|
| 3750 |
+
friend constexpr counted_iterator operator+(
|
| 3751 |
+
iter_difference_t<I> n, const counted_iterator& x)
|
| 3752 |
+
requires random_access_iterator<I>;
|
| 3753 |
+
constexpr counted_iterator& operator+=(iter_difference_t<I> n)
|
| 3754 |
+
requires random_access_iterator<I>;
|
| 3755 |
+
|
| 3756 |
+
constexpr counted_iterator operator-(iter_difference_t<I> n) const
|
| 3757 |
+
requires random_access_iterator<I>;
|
| 3758 |
+
template<common_with<I> I2>
|
| 3759 |
+
friend constexpr iter_difference_t<I2> operator-(
|
| 3760 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 3761 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 3762 |
+
const counted_iterator& x, default_sentinel_t);
|
| 3763 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 3764 |
+
default_sentinel_t, const counted_iterator& y);
|
| 3765 |
+
constexpr counted_iterator& operator-=(iter_difference_t<I> n)
|
| 3766 |
+
requires random_access_iterator<I>;
|
| 3767 |
+
|
| 3768 |
+
constexpr decltype(auto) operator[](iter_difference_t<I> n) const
|
| 3769 |
+
requires random_access_iterator<I>;
|
| 3770 |
+
|
| 3771 |
+
template<common_with<I> I2>
|
| 3772 |
+
friend constexpr bool operator==(
|
| 3773 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 3774 |
+
friend constexpr bool operator==(
|
| 3775 |
+
const counted_iterator& x, default_sentinel_t);
|
| 3776 |
+
|
| 3777 |
+
template<common_with<I> I2>
|
| 3778 |
+
friend constexpr strong_ordering operator<=>(
|
| 3779 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 3780 |
+
|
| 3781 |
+
friend constexpr iter_rvalue_reference_t<I> iter_move(const counted_iterator& i)
|
| 3782 |
+
noexcept(noexcept(ranges::iter_move(i.current)))
|
| 3783 |
+
requires input_iterator<I>;
|
| 3784 |
+
template<indirectly_swappable<I> I2>
|
| 3785 |
+
friend constexpr void iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
|
| 3786 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 3787 |
+
|
| 3788 |
+
private:
|
| 3789 |
+
I current = I(); // exposition only
|
| 3790 |
+
iter_difference_t<I> length = 0; // exposition only
|
| 3791 |
+
};
|
| 3792 |
+
|
| 3793 |
+
template<class I>
|
| 3794 |
+
struct incrementable_traits<counted_iterator<I>> {
|
| 3795 |
+
using difference_type = iter_difference_t<I>;
|
| 3796 |
+
};
|
| 3797 |
+
|
| 3798 |
+
template<input_iterator I>
|
| 3799 |
+
struct iterator_traits<counted_iterator<I>> : iterator_traits<I> {
|
| 3800 |
+
using pointer = void;
|
| 3801 |
+
};
|
| 3802 |
+
}
|
| 3803 |
+
```
|
| 3804 |
+
|
| 3805 |
+
#### Constructors and conversions <a id="counted.iter.const">[[counted.iter.const]]</a>
|
| 3806 |
+
|
| 3807 |
+
``` cpp
|
| 3808 |
+
constexpr counted_iterator(I i, iter_difference_t<I> n);
|
| 3809 |
+
```
|
| 3810 |
+
|
| 3811 |
+
*Preconditions:* `n >= 0`.
|
| 3812 |
+
|
| 3813 |
+
*Effects:* Initializes `current` with `std::move(i)` and `length` with
|
| 3814 |
+
`n`.
|
| 3815 |
+
|
| 3816 |
+
``` cpp
|
| 3817 |
+
template<class I2>
|
| 3818 |
+
requires convertible_to<const I2&, I>
|
| 3819 |
+
constexpr counted_iterator(const counted_iterator<I2>& x);
|
| 3820 |
+
```
|
| 3821 |
+
|
| 3822 |
+
*Effects:* Initializes `current` with `x.current` and `length` with
|
| 3823 |
+
`x.length`.
|
| 3824 |
+
|
| 3825 |
+
``` cpp
|
| 3826 |
+
template<class I2>
|
| 3827 |
+
requires assignable_from<I&, const I2&>
|
| 3828 |
+
constexpr counted_iterator& operator=(const counted_iterator<I2>& x);
|
| 3829 |
+
```
|
| 3830 |
+
|
| 3831 |
+
*Effects:* Assigns `x.current` to `current` and `x.length` to `length`.
|
| 3832 |
+
|
| 3833 |
+
*Returns:* `*this`.
|
| 3834 |
+
|
| 3835 |
+
#### Accessors <a id="counted.iter.access">[[counted.iter.access]]</a>
|
| 3836 |
+
|
| 3837 |
+
``` cpp
|
| 3838 |
+
constexpr I base() const & requires copy_constructible<I>;
|
| 3839 |
+
```
|
| 3840 |
+
|
| 3841 |
+
*Effects:* Equivalent to: `return current;`
|
| 3842 |
+
|
| 3843 |
+
``` cpp
|
| 3844 |
+
constexpr I base() &&;
|
| 3845 |
+
```
|
| 3846 |
+
|
| 3847 |
+
*Returns:* `std::move(current)`.
|
| 3848 |
+
|
| 3849 |
+
``` cpp
|
| 3850 |
+
constexpr iter_difference_t<I> count() const noexcept;
|
| 3851 |
+
```
|
| 3852 |
+
|
| 3853 |
+
*Effects:* Equivalent to: `return length;`
|
| 3854 |
+
|
| 3855 |
+
#### Element access <a id="counted.iter.elem">[[counted.iter.elem]]</a>
|
| 3856 |
+
|
| 3857 |
+
``` cpp
|
| 3858 |
+
constexpr decltype(auto) operator*();
|
| 3859 |
+
constexpr decltype(auto) operator*() const
|
| 3860 |
+
requires dereferenceable<const I>;
|
| 3861 |
+
```
|
| 3862 |
+
|
| 3863 |
+
*Effects:* Equivalent to: `return *current;`
|
| 3864 |
+
|
| 3865 |
+
``` cpp
|
| 3866 |
+
constexpr decltype(auto) operator[](iter_difference_t<I> n) const
|
| 3867 |
+
requires random_access_iterator<I>;
|
| 3868 |
+
```
|
| 3869 |
+
|
| 3870 |
+
*Preconditions:* `n < length`.
|
| 3871 |
+
|
| 3872 |
+
*Effects:* Equivalent to: `return current[n];`
|
| 3873 |
+
|
| 3874 |
+
#### Navigation <a id="counted.iter.nav">[[counted.iter.nav]]</a>
|
| 3875 |
+
|
| 3876 |
+
``` cpp
|
| 3877 |
+
constexpr counted_iterator& operator++();
|
| 3878 |
+
```
|
| 3879 |
+
|
| 3880 |
+
*Preconditions:* `length > 0`.
|
| 3881 |
+
|
| 3882 |
+
*Effects:* Equivalent to:
|
| 3883 |
+
|
| 3884 |
+
``` cpp
|
| 3885 |
+
++current;
|
| 3886 |
+
--length;
|
| 3887 |
+
return *this;
|
| 3888 |
+
```
|
| 3889 |
+
|
| 3890 |
+
``` cpp
|
| 3891 |
+
decltype(auto) operator++(int);
|
| 3892 |
+
```
|
| 3893 |
+
|
| 3894 |
+
*Preconditions:* `length > 0`.
|
| 3895 |
+
|
| 3896 |
+
*Effects:* Equivalent to:
|
| 3897 |
+
|
| 3898 |
+
``` cpp
|
| 3899 |
+
--length;
|
| 3900 |
+
try { return current++; }
|
| 3901 |
+
catch(...) { ++length; throw; }
|
| 3902 |
+
```
|
| 3903 |
+
|
| 3904 |
+
``` cpp
|
| 3905 |
+
constexpr counted_iterator operator++(int)
|
| 3906 |
+
requires forward_iterator<I>;
|
| 3907 |
+
```
|
| 3908 |
+
|
| 3909 |
+
*Effects:* Equivalent to:
|
| 3910 |
+
|
| 3911 |
+
``` cpp
|
| 3912 |
+
counted_iterator tmp = *this;
|
| 3913 |
+
++*this;
|
| 3914 |
+
return tmp;
|
| 3915 |
+
```
|
| 3916 |
+
|
| 3917 |
+
``` cpp
|
| 3918 |
+
constexpr counted_iterator& operator--()
|
| 3919 |
+
requires bidirectional_iterator<I>;
|
| 3920 |
+
```
|
| 3921 |
+
|
| 3922 |
+
*Effects:* Equivalent to:
|
| 3923 |
+
|
| 3924 |
+
``` cpp
|
| 3925 |
+
--current;
|
| 3926 |
+
++length;
|
| 3927 |
+
return *this;
|
| 3928 |
+
```
|
| 3929 |
+
|
| 3930 |
+
``` cpp
|
| 3931 |
+
constexpr counted_iterator operator--(int)
|
| 3932 |
+
requires bidirectional_iterator<I>;
|
| 3933 |
+
```
|
| 3934 |
+
|
| 3935 |
+
*Effects:* Equivalent to:
|
| 3936 |
+
|
| 3937 |
+
``` cpp
|
| 3938 |
+
counted_iterator tmp = *this;
|
| 3939 |
+
--*this;
|
| 3940 |
+
return tmp;
|
| 3941 |
+
```
|
| 3942 |
+
|
| 3943 |
+
``` cpp
|
| 3944 |
+
constexpr counted_iterator operator+(iter_difference_t<I> n) const
|
| 3945 |
+
requires random_access_iterator<I>;
|
| 3946 |
+
```
|
| 3947 |
+
|
| 3948 |
+
*Effects:* Equivalent to:
|
| 3949 |
+
`return counted_iterator(current + n, length - n);`
|
| 3950 |
+
|
| 3951 |
+
``` cpp
|
| 3952 |
+
friend constexpr counted_iterator operator+(
|
| 3953 |
+
iter_difference_t<I> n, const counted_iterator& x)
|
| 3954 |
+
requires random_access_iterator<I>;
|
| 3955 |
+
```
|
| 3956 |
+
|
| 3957 |
+
*Effects:* Equivalent to: `return x + n;`
|
| 3958 |
+
|
| 3959 |
+
``` cpp
|
| 3960 |
+
constexpr counted_iterator& operator+=(iter_difference_t<I> n)
|
| 3961 |
+
requires random_access_iterator<I>;
|
| 3962 |
+
```
|
| 3963 |
+
|
| 3964 |
+
*Preconditions:* `n <= length`.
|
| 3965 |
+
|
| 3966 |
+
*Effects:* Equivalent to:
|
| 3967 |
+
|
| 3968 |
+
``` cpp
|
| 3969 |
+
current += n;
|
| 3970 |
+
length -= n;
|
| 3971 |
+
return *this;
|
| 3972 |
+
```
|
| 3973 |
+
|
| 3974 |
+
``` cpp
|
| 3975 |
+
constexpr counted_iterator operator-(iter_difference_t<I> n) const
|
| 3976 |
+
requires random_access_iterator<I>;
|
| 3977 |
+
```
|
| 3978 |
+
|
| 3979 |
+
*Effects:* Equivalent to:
|
| 3980 |
+
`return counted_iterator(current - n, length + n);`
|
| 3981 |
+
|
| 3982 |
+
``` cpp
|
| 3983 |
+
template<common_with<I> I2>
|
| 3984 |
+
friend constexpr iter_difference_t<I2> operator-(
|
| 3985 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 3986 |
+
```
|
| 3987 |
+
|
| 3988 |
+
*Preconditions:* `x` and `y` refer to elements of the same
|
| 3989 |
+
sequence [[counted.iterator]].
|
| 3990 |
+
|
| 3991 |
+
*Effects:* Equivalent to: `return y.length - x.length;`
|
| 3992 |
+
|
| 3993 |
+
``` cpp
|
| 3994 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 3995 |
+
const counted_iterator& x, default_sentinel_t);
|
| 3996 |
+
```
|
| 3997 |
+
|
| 3998 |
+
*Effects:* Equivalent to: `return -x.length;`
|
| 3999 |
+
|
| 4000 |
+
``` cpp
|
| 4001 |
+
friend constexpr iter_difference_t<I> operator-(
|
| 4002 |
+
default_sentinel_t, const counted_iterator& y);
|
| 4003 |
+
```
|
| 4004 |
+
|
| 4005 |
+
*Effects:* Equivalent to: `return y.length;`
|
| 4006 |
+
|
| 4007 |
+
``` cpp
|
| 4008 |
+
constexpr counted_iterator& operator-=(iter_difference_t<I> n)
|
| 4009 |
+
requires random_access_iterator<I>;
|
| 4010 |
+
```
|
| 4011 |
+
|
| 4012 |
+
*Preconditions:* `-n <= length`.
|
| 4013 |
+
|
| 4014 |
+
*Effects:* Equivalent to:
|
| 4015 |
+
|
| 4016 |
+
``` cpp
|
| 4017 |
+
current -= n;
|
| 4018 |
+
length += n;
|
| 4019 |
+
return *this;
|
| 4020 |
+
```
|
| 4021 |
+
|
| 4022 |
+
#### Comparisons <a id="counted.iter.cmp">[[counted.iter.cmp]]</a>
|
| 4023 |
+
|
| 4024 |
+
``` cpp
|
| 4025 |
+
template<common_with<I> I2>
|
| 4026 |
+
friend constexpr bool operator==(
|
| 4027 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 4028 |
+
```
|
| 4029 |
+
|
| 4030 |
+
*Preconditions:* `x` and `y` refer to elements of the same
|
| 4031 |
+
sequence [[counted.iterator]].
|
| 4032 |
+
|
| 4033 |
+
*Effects:* Equivalent to: `return x.length == y.length;`
|
| 4034 |
+
|
| 4035 |
+
``` cpp
|
| 4036 |
+
friend constexpr bool operator==(
|
| 4037 |
+
const counted_iterator& x, default_sentinel_t);
|
| 4038 |
+
```
|
| 4039 |
+
|
| 4040 |
+
*Effects:* Equivalent to: `return x.length == 0;`
|
| 4041 |
+
|
| 4042 |
+
``` cpp
|
| 4043 |
+
template<common_with<I> I2>
|
| 4044 |
+
friend constexpr strong_ordering operator<=>(
|
| 4045 |
+
const counted_iterator& x, const counted_iterator<I2>& y);
|
| 4046 |
+
```
|
| 4047 |
+
|
| 4048 |
+
*Preconditions:* `x` and `y` refer to elements of the same
|
| 4049 |
+
sequence [[counted.iterator]].
|
| 4050 |
+
|
| 4051 |
+
*Effects:* Equivalent to: `return y.length <=> x.length;`
|
| 4052 |
+
|
| 4053 |
+
[*Note 1*: The argument order in the *Effects:* element is reversed
|
| 4054 |
+
because `length` counts down, not up. — *end note*]
|
| 4055 |
+
|
| 4056 |
+
#### Customizations <a id="counted.iter.cust">[[counted.iter.cust]]</a>
|
| 4057 |
+
|
| 4058 |
+
``` cpp
|
| 4059 |
+
friend constexpr iter_rvalue_reference_t<I>
|
| 4060 |
+
iter_move(const counted_iterator& i)
|
| 4061 |
+
noexcept(noexcept(ranges::iter_move(i.current)))
|
| 4062 |
+
requires input_iterator<I>;
|
| 4063 |
+
```
|
| 4064 |
+
|
| 4065 |
+
*Effects:* Equivalent to: `return ranges::iter_move(i.current);`
|
| 4066 |
+
|
| 4067 |
+
``` cpp
|
| 4068 |
+
template<indirectly_swappable<I> I2>
|
| 4069 |
+
friend constexpr void
|
| 4070 |
+
iter_swap(const counted_iterator& x, const counted_iterator<I2>& y)
|
| 4071 |
+
noexcept(noexcept(ranges::iter_swap(x.current, y.current)));
|
| 4072 |
+
```
|
| 4073 |
+
|
| 4074 |
+
*Effects:* Equivalent to `ranges::iter_swap(x.current, y.current)`.
|
| 4075 |
+
|
| 4076 |
+
### Unreachable sentinel <a id="unreachable.sentinels">[[unreachable.sentinels]]</a>
|
| 4077 |
+
|
| 4078 |
+
#### Class `unreachable_sentinel_t` <a id="unreachable.sentinel">[[unreachable.sentinel]]</a>
|
| 4079 |
+
|
| 4080 |
+
Class `unreachable_sentinel_t` can be used with any
|
| 4081 |
+
`weakly_incrementable` type to denote the “upper bound” of an unbounded
|
| 4082 |
+
interval.
|
| 4083 |
+
|
| 4084 |
+
[*Example 1*:
|
| 4085 |
+
|
| 4086 |
+
``` cpp
|
| 4087 |
+
char* p;
|
| 4088 |
+
// set p to point to a character buffer containing newlines
|
| 4089 |
+
char* nl = find(p, unreachable_sentinel, '\n');
|
| 4090 |
+
```
|
| 4091 |
+
|
| 4092 |
+
Provided a newline character really exists in the buffer, the use of
|
| 4093 |
+
`unreachable_sentinel` above potentially makes the call to `find` more
|
| 4094 |
+
efficient since the loop test against the sentinel does not require a
|
| 4095 |
+
conditional branch.
|
| 4096 |
+
|
| 4097 |
+
— *end example*]
|
| 4098 |
+
|
| 4099 |
+
``` cpp
|
| 4100 |
+
namespace std {
|
| 4101 |
+
struct unreachable_sentinel_t {
|
| 4102 |
+
template<weakly_incrementable I>
|
| 4103 |
+
friend constexpr bool operator==(unreachable_sentinel_t, const I&) noexcept
|
| 4104 |
+
{ return false; }
|
| 4105 |
+
};
|
| 4106 |
+
}
|
| 4107 |
+
```
|
| 4108 |
|
| 4109 |
## Stream iterators <a id="stream.iterators">[[stream.iterators]]</a>
|
| 4110 |
|
| 4111 |
To make it possible for algorithmic templates to work directly with
|
| 4112 |
input/output streams, appropriate iterator-like class templates are
|
|
|
|
| 4125 |
|
| 4126 |
— *end example*]
|
| 4127 |
|
| 4128 |
### Class template `istream_iterator` <a id="istream.iterator">[[istream.iterator]]</a>
|
| 4129 |
|
| 4130 |
+
The class template `istream_iterator` is an input iterator
|
| 4131 |
+
[[input.iterators]] that reads successive elements from the input stream
|
| 4132 |
+
for which it was constructed.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4133 |
|
| 4134 |
``` cpp
|
| 4135 |
namespace std {
|
| 4136 |
template<class T, class charT = char, class traits = char_traits<charT>,
|
| 4137 |
class Distance = ptrdiff_t>
|
|
|
|
| 4145 |
using char_type = charT;
|
| 4146 |
using traits_type = traits;
|
| 4147 |
using istream_type = basic_istream<charT,traits>;
|
| 4148 |
|
| 4149 |
constexpr istream_iterator();
|
| 4150 |
+
constexpr istream_iterator(default_sentinel_t);
|
| 4151 |
istream_iterator(istream_type& s);
|
| 4152 |
istream_iterator(const istream_iterator& x) = default;
|
| 4153 |
~istream_iterator() = default;
|
| 4154 |
+
istream_iterator& operator=(const istream_iterator&) = default;
|
| 4155 |
|
| 4156 |
const T& operator*() const;
|
| 4157 |
const T* operator->() const;
|
| 4158 |
istream_iterator& operator++();
|
| 4159 |
istream_iterator operator++(int);
|
| 4160 |
+
|
| 4161 |
+
friend bool operator==(const istream_iterator& i, default_sentinel_t);
|
| 4162 |
+
|
| 4163 |
private:
|
| 4164 |
basic_istream<charT,traits>* in_stream; // exposition only
|
| 4165 |
T value; // exposition only
|
| 4166 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4167 |
}
|
| 4168 |
```
|
| 4169 |
|
| 4170 |
+
The type `T` shall meet the *Cpp17DefaultConstructible*,
|
| 4171 |
+
*Cpp17CopyConstructible*, and *Cpp17CopyAssignable* requirements.
|
| 4172 |
+
|
| 4173 |
+
#### Constructors and destructor <a id="istream.iterator.cons">[[istream.iterator.cons]]</a>
|
| 4174 |
|
| 4175 |
``` cpp
|
| 4176 |
constexpr istream_iterator();
|
| 4177 |
+
constexpr istream_iterator(default_sentinel_t);
|
| 4178 |
```
|
| 4179 |
|
| 4180 |
+
*Effects:* Constructs the end-of-stream iterator, value-initializing
|
| 4181 |
+
`value`.
|
|
|
|
| 4182 |
|
| 4183 |
+
*Ensures:* `in_stream == nullptr` is `true`.
|
| 4184 |
+
|
| 4185 |
+
*Remarks:* If the initializer `T()` in the declaration `auto x = T();`
|
| 4186 |
+
is a constant initializer [[expr.const]], then these constructors are
|
| 4187 |
+
`constexpr` constructors.
|
| 4188 |
|
| 4189 |
``` cpp
|
| 4190 |
istream_iterator(istream_type& s);
|
| 4191 |
```
|
| 4192 |
|
| 4193 |
+
*Effects:* Initializes `in_stream` with `addressof(s)`,
|
| 4194 |
+
value-initializes `value`, and then calls `operator++()`.
|
|
|
|
|
|
|
| 4195 |
|
| 4196 |
``` cpp
|
| 4197 |
istream_iterator(const istream_iterator& x) = default;
|
| 4198 |
```
|
| 4199 |
|
| 4200 |
+
*Ensures:* `in_stream == x.in_stream` is `true`.
|
|
|
|
|
|
|
| 4201 |
|
| 4202 |
+
*Remarks:* If `is_trivially_copy_constructible_v<T>` is `true`, then
|
| 4203 |
+
this constructor is trivial.
|
| 4204 |
|
| 4205 |
``` cpp
|
| 4206 |
~istream_iterator() = default;
|
| 4207 |
```
|
| 4208 |
|
| 4209 |
+
*Remarks:* If `is_trivially_destructible_v<T>` is `true`, then this
|
| 4210 |
+
destructor is trivial.
|
|
|
|
| 4211 |
|
| 4212 |
+
#### Operations <a id="istream.iterator.ops">[[istream.iterator.ops]]</a>
|
| 4213 |
|
| 4214 |
``` cpp
|
| 4215 |
const T& operator*() const;
|
| 4216 |
```
|
| 4217 |
|
| 4218 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 4219 |
+
|
| 4220 |
*Returns:* `value`.
|
| 4221 |
|
| 4222 |
``` cpp
|
| 4223 |
const T* operator->() const;
|
| 4224 |
```
|
| 4225 |
|
| 4226 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 4227 |
+
|
| 4228 |
+
*Returns:* `addressof(value)`.
|
| 4229 |
|
| 4230 |
``` cpp
|
| 4231 |
istream_iterator& operator++();
|
| 4232 |
```
|
| 4233 |
|
| 4234 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 4235 |
|
| 4236 |
+
*Effects:* Equivalent to:
|
| 4237 |
+
|
| 4238 |
+
``` cpp
|
| 4239 |
+
if (!(*in_stream >> value))
|
| 4240 |
+
in_stream = nullptr;
|
| 4241 |
+
```
|
| 4242 |
|
| 4243 |
*Returns:* `*this`.
|
| 4244 |
|
| 4245 |
``` cpp
|
| 4246 |
istream_iterator operator++(int);
|
| 4247 |
```
|
| 4248 |
|
| 4249 |
+
*Preconditions:* `in_stream != nullptr` is `true`.
|
| 4250 |
|
| 4251 |
+
*Effects:* Equivalent to:
|
| 4252 |
|
| 4253 |
``` cpp
|
| 4254 |
istream_iterator tmp = *this;
|
| 4255 |
+
++*this;
|
| 4256 |
+
return tmp;
|
| 4257 |
```
|
| 4258 |
|
| 4259 |
``` cpp
|
| 4260 |
template<class T, class charT, class traits, class Distance>
|
| 4261 |
bool operator==(const istream_iterator<T,charT,traits,Distance>& x,
|
|
|
|
| 4263 |
```
|
| 4264 |
|
| 4265 |
*Returns:* `x.in_stream == y.in_stream`.
|
| 4266 |
|
| 4267 |
``` cpp
|
| 4268 |
+
friend bool operator==(const istream_iterator& i, default_sentinel_t);
|
|
|
|
|
|
|
| 4269 |
```
|
| 4270 |
|
| 4271 |
+
*Returns:* `!i.in_stream`.
|
| 4272 |
|
| 4273 |
### Class template `ostream_iterator` <a id="ostream.iterator">[[ostream.iterator]]</a>
|
| 4274 |
|
| 4275 |
`ostream_iterator` writes (using `operator<<`) successive elements onto
|
| 4276 |
the output stream from which it was constructed. If it was constructed
|
| 4277 |
with `charT*` as a constructor argument, this string, called a
|
| 4278 |
*delimiter string*, is written to the stream after every `T` is written.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4279 |
|
| 4280 |
``` cpp
|
| 4281 |
namespace std {
|
| 4282 |
template<class T, class charT = char, class traits = char_traits<charT>>
|
| 4283 |
class ostream_iterator {
|
| 4284 |
public:
|
| 4285 |
using iterator_category = output_iterator_tag;
|
| 4286 |
using value_type = void;
|
| 4287 |
+
using difference_type = ptrdiff_t;
|
| 4288 |
using pointer = void;
|
| 4289 |
using reference = void;
|
| 4290 |
using char_type = charT;
|
| 4291 |
using traits_type = traits;
|
| 4292 |
using ostream_type = basic_ostream<charT,traits>;
|
| 4293 |
|
| 4294 |
+
constexpr ostream_iterator() noexcept = default;
|
| 4295 |
ostream_iterator(ostream_type& s);
|
| 4296 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 4297 |
ostream_iterator(const ostream_iterator& x);
|
| 4298 |
~ostream_iterator();
|
| 4299 |
+
ostream_iterator& operator=(const ostream_iterator&) = default;
|
| 4300 |
ostream_iterator& operator=(const T& value);
|
| 4301 |
|
| 4302 |
ostream_iterator& operator*();
|
| 4303 |
ostream_iterator& operator++();
|
| 4304 |
ostream_iterator& operator++(int);
|
| 4305 |
+
|
| 4306 |
private:
|
| 4307 |
+
basic_ostream<charT,traits>* out_stream = nullptr; // exposition only
|
| 4308 |
+
const charT* delim = nullptr; // exposition only
|
| 4309 |
};
|
| 4310 |
}
|
| 4311 |
```
|
| 4312 |
|
| 4313 |
+
#### Constructors and destructor <a id="ostream.iterator.cons.des">[[ostream.iterator.cons.des]]</a>
|
| 4314 |
|
| 4315 |
``` cpp
|
| 4316 |
ostream_iterator(ostream_type& s);
|
| 4317 |
```
|
| 4318 |
|
| 4319 |
*Effects:* Initializes `out_stream` with `addressof(s)` and `delim` with
|
| 4320 |
+
`nullptr`.
|
| 4321 |
|
| 4322 |
``` cpp
|
| 4323 |
ostream_iterator(ostream_type& s, const charT* delimiter);
|
| 4324 |
```
|
| 4325 |
|
| 4326 |
*Effects:* Initializes `out_stream` with `addressof(s)` and `delim` with
|
| 4327 |
`delimiter`.
|
| 4328 |
|
| 4329 |
+
#### Operations <a id="ostream.iterator.ops">[[ostream.iterator.ops]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4330 |
|
| 4331 |
``` cpp
|
| 4332 |
ostream_iterator& operator=(const T& value);
|
| 4333 |
```
|
| 4334 |
|
| 4335 |
*Effects:* As if by:
|
| 4336 |
|
| 4337 |
``` cpp
|
| 4338 |
*out_stream << value;
|
| 4339 |
+
if (delim)
|
| 4340 |
*out_stream << delim;
|
| 4341 |
return *this;
|
| 4342 |
```
|
| 4343 |
|
| 4344 |
``` cpp
|
|
|
|
| 4354 |
|
| 4355 |
*Returns:* `*this`.
|
| 4356 |
|
| 4357 |
### Class template `istreambuf_iterator` <a id="istreambuf.iterator">[[istreambuf.iterator]]</a>
|
| 4358 |
|
| 4359 |
+
The class template `istreambuf_iterator` defines an input iterator
|
| 4360 |
+
[[input.iterators]] that reads successive *characters* from the
|
| 4361 |
streambuf for which it was constructed. `operator*` provides access to
|
| 4362 |
the current input character, if any. Each time `operator++` is
|
| 4363 |
evaluated, the iterator advances to the next input character. If the end
|
| 4364 |
of stream is reached (`streambuf_type::sgetc()` returns
|
| 4365 |
`traits::eof()`), the iterator becomes equal to the *end-of-stream*
|
| 4366 |
iterator value. The default constructor `istreambuf_iterator()` and the
|
| 4367 |
+
constructor `istreambuf_iterator(nullptr)` both construct an
|
| 4368 |
+
end-of-stream iterator object suitable for use as an end-of-range. All
|
| 4369 |
+
specializations of `istreambuf_iterator` shall have a trivial copy
|
| 4370 |
+
constructor, a `constexpr` default constructor, and a trivial
|
| 4371 |
+
destructor.
|
| 4372 |
|
| 4373 |
The result of `operator*()` on an end-of-stream iterator is undefined.
|
| 4374 |
For any other iterator value a `char_type` value is returned. It is
|
| 4375 |
impossible to assign a character via an input iterator.
|
| 4376 |
|
|
|
|
| 4391 |
using istream_type = basic_istream<charT,traits>;
|
| 4392 |
|
| 4393 |
class proxy; // exposition only
|
| 4394 |
|
| 4395 |
constexpr istreambuf_iterator() noexcept;
|
| 4396 |
+
constexpr istreambuf_iterator(default_sentinel_t) noexcept;
|
| 4397 |
istreambuf_iterator(const istreambuf_iterator&) noexcept = default;
|
| 4398 |
~istreambuf_iterator() = default;
|
| 4399 |
istreambuf_iterator(istream_type& s) noexcept;
|
| 4400 |
istreambuf_iterator(streambuf_type* s) noexcept;
|
| 4401 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 4402 |
+
istreambuf_iterator& operator=(const istreambuf_iterator&) noexcept = default;
|
| 4403 |
charT operator*() const;
|
| 4404 |
istreambuf_iterator& operator++();
|
| 4405 |
proxy operator++(int);
|
| 4406 |
bool equal(const istreambuf_iterator& b) const;
|
| 4407 |
+
|
| 4408 |
+
friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s);
|
| 4409 |
+
|
| 4410 |
private:
|
| 4411 |
streambuf_type* sbuf_; // exposition only
|
| 4412 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4413 |
}
|
| 4414 |
```
|
| 4415 |
|
| 4416 |
+
#### Class `istreambuf_iterator::proxy` <a id="istreambuf.iterator.proxy">[[istreambuf.iterator.proxy]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4417 |
|
| 4418 |
Class `istreambuf_iterator<charT,traits>::proxy` is for exposition only.
|
| 4419 |
An implementation is permitted to provide equivalent functionality
|
| 4420 |
without providing a class with this name. Class
|
| 4421 |
`istreambuf_iterator<charT, traits>::proxy` provides a temporary
|
| 4422 |
placeholder as the return value of the post-increment operator
|
| 4423 |
(`operator++`). It keeps the character pointed to by the previous value
|
| 4424 |
of the iterator for some possible future access to get the character.
|
| 4425 |
|
| 4426 |
+
``` cpp
|
| 4427 |
+
namespace std {
|
| 4428 |
+
template<class charT, class traits>
|
| 4429 |
+
class istreambuf_iterator<charT, traits>::proxy { // exposition only
|
| 4430 |
+
charT keep_;
|
| 4431 |
+
basic_streambuf<charT,traits>* sbuf_;
|
| 4432 |
+
proxy(charT c, basic_streambuf<charT,traits>* sbuf)
|
| 4433 |
+
: keep_(c), sbuf_(sbuf) { }
|
| 4434 |
+
public:
|
| 4435 |
+
charT operator*() { return keep_; }
|
| 4436 |
+
};
|
| 4437 |
+
}
|
| 4438 |
+
```
|
| 4439 |
|
| 4440 |
+
#### Constructors <a id="istreambuf.iterator.cons">[[istreambuf.iterator.cons]]</a>
|
| 4441 |
+
|
| 4442 |
+
For each `istreambuf_iterator` constructor in this subclause, an
|
| 4443 |
end-of-stream iterator is constructed if and only if the exposition-only
|
| 4444 |
member `sbuf_` is initialized with a null pointer value.
|
| 4445 |
|
| 4446 |
``` cpp
|
| 4447 |
constexpr istreambuf_iterator() noexcept;
|
| 4448 |
+
constexpr istreambuf_iterator(default_sentinel_t) noexcept;
|
| 4449 |
```
|
| 4450 |
|
| 4451 |
*Effects:* Initializes `sbuf_` with `nullptr`.
|
| 4452 |
|
| 4453 |
``` cpp
|
|
|
|
| 4466 |
istreambuf_iterator(const proxy& p) noexcept;
|
| 4467 |
```
|
| 4468 |
|
| 4469 |
*Effects:* Initializes `sbuf_` with `p.sbuf_`.
|
| 4470 |
|
| 4471 |
+
#### Operations <a id="istreambuf.iterator.ops">[[istreambuf.iterator.ops]]</a>
|
| 4472 |
|
| 4473 |
``` cpp
|
| 4474 |
+
charT operator*() const;
|
| 4475 |
```
|
| 4476 |
|
| 4477 |
*Returns:* The character obtained via the `streambuf` member
|
| 4478 |
`sbuf_->sgetc()`.
|
| 4479 |
|
|
|
|
| 4487 |
|
| 4488 |
``` cpp
|
| 4489 |
proxy operator++(int);
|
| 4490 |
```
|
| 4491 |
|
| 4492 |
+
*Returns:* *`proxy`*`(sbuf_->sbumpc(), sbuf_)`.
|
| 4493 |
|
| 4494 |
``` cpp
|
| 4495 |
bool equal(const istreambuf_iterator& b) const;
|
| 4496 |
```
|
| 4497 |
|
|
|
|
| 4506 |
```
|
| 4507 |
|
| 4508 |
*Returns:* `a.equal(b)`.
|
| 4509 |
|
| 4510 |
``` cpp
|
| 4511 |
+
friend bool operator==(const istreambuf_iterator& i, default_sentinel_t s);
|
|
|
|
|
|
|
| 4512 |
```
|
| 4513 |
|
| 4514 |
+
*Returns:* `i.equal(s)`.
|
| 4515 |
|
| 4516 |
### Class template `ostreambuf_iterator` <a id="ostreambuf.iterator">[[ostreambuf.iterator]]</a>
|
| 4517 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4518 |
The class template `ostreambuf_iterator` writes successive *characters*
|
| 4519 |
+
onto the output stream from which it was constructed.
|
|
|
|
| 4520 |
|
| 4521 |
+
``` cpp
|
| 4522 |
+
namespace std {
|
| 4523 |
+
template<class charT, class traits = char_traits<charT>>
|
| 4524 |
+
class ostreambuf_iterator {
|
| 4525 |
+
public:
|
| 4526 |
+
using iterator_category = output_iterator_tag;
|
| 4527 |
+
using value_type = void;
|
| 4528 |
+
using difference_type = ptrdiff_t;
|
| 4529 |
+
using pointer = void;
|
| 4530 |
+
using reference = void;
|
| 4531 |
+
using char_type = charT;
|
| 4532 |
+
using traits_type = traits;
|
| 4533 |
+
using streambuf_type = basic_streambuf<charT,traits>;
|
| 4534 |
+
using ostream_type = basic_ostream<charT,traits>;
|
| 4535 |
+
|
| 4536 |
+
constexpr ostreambuf_iterator() noexcept = default;
|
| 4537 |
+
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 4538 |
+
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 4539 |
+
ostreambuf_iterator& operator=(charT c);
|
| 4540 |
+
|
| 4541 |
+
ostreambuf_iterator& operator*();
|
| 4542 |
+
ostreambuf_iterator& operator++();
|
| 4543 |
+
ostreambuf_iterator& operator++(int);
|
| 4544 |
+
bool failed() const noexcept;
|
| 4545 |
+
|
| 4546 |
+
private:
|
| 4547 |
+
streambuf_type* sbuf_ = nullptr; // exposition only
|
| 4548 |
+
};
|
| 4549 |
+
}
|
| 4550 |
+
```
|
| 4551 |
+
|
| 4552 |
+
#### Constructors <a id="ostreambuf.iter.cons">[[ostreambuf.iter.cons]]</a>
|
| 4553 |
|
| 4554 |
``` cpp
|
| 4555 |
ostreambuf_iterator(ostream_type& s) noexcept;
|
| 4556 |
```
|
| 4557 |
|
| 4558 |
+
*Preconditions:* `s.rdbuf()` is not a null pointer.
|
| 4559 |
|
| 4560 |
*Effects:* Initializes `sbuf_` with `s.rdbuf()`.
|
| 4561 |
|
| 4562 |
``` cpp
|
| 4563 |
ostreambuf_iterator(streambuf_type* s) noexcept;
|
| 4564 |
```
|
| 4565 |
|
| 4566 |
+
*Preconditions:* `s` is not a null pointer.
|
| 4567 |
|
| 4568 |
*Effects:* Initializes `sbuf_` with `s`.
|
| 4569 |
|
| 4570 |
+
#### Operations <a id="ostreambuf.iter.ops">[[ostreambuf.iter.ops]]</a>
|
| 4571 |
|
| 4572 |
``` cpp
|
| 4573 |
ostreambuf_iterator& operator=(charT c);
|
| 4574 |
```
|
| 4575 |
|
|
|
|
| 4601 |
## Range access <a id="iterator.range">[[iterator.range]]</a>
|
| 4602 |
|
| 4603 |
In addition to being available via inclusion of the `<iterator>` header,
|
| 4604 |
the function templates in [[iterator.range]] are available when any of
|
| 4605 |
the following headers are included: `<array>`, `<deque>`,
|
| 4606 |
+
`<forward_list>`, `<list>`, `<map>`, `<regex>`, `<set>`, `<span>`,
|
| 4607 |
+
`<string>`, `<string_view>`, `<unordered_map>`, `<unordered_set>`, and
|
| 4608 |
+
`<vector>`. Each of these templates is a designated customization point
|
| 4609 |
+
[[namespace.std]].
|
| 4610 |
|
| 4611 |
``` cpp
|
| 4612 |
template<class C> constexpr auto begin(C& c) -> decltype(c.begin());
|
| 4613 |
template<class C> constexpr auto begin(const C& c) -> decltype(c.begin());
|
| 4614 |
```
|
|
|
|
| 4696 |
template<class C> constexpr auto crend(const C& c) -> decltype(std::rend(c));
|
| 4697 |
```
|
| 4698 |
|
| 4699 |
*Returns:* `std::rend(c)`.
|
| 4700 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4701 |
``` cpp
|
| 4702 |
template<class C> constexpr auto size(const C& c) -> decltype(c.size());
|
| 4703 |
```
|
| 4704 |
|
| 4705 |
*Returns:* `c.size()`.
|
|
|
|
| 4709 |
```
|
| 4710 |
|
| 4711 |
*Returns:* `N`.
|
| 4712 |
|
| 4713 |
``` cpp
|
| 4714 |
+
template<class C> constexpr auto ssize(const C& c)
|
| 4715 |
+
-> common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>;
|
| 4716 |
+
```
|
| 4717 |
+
|
| 4718 |
+
*Effects:* Equivalent to:
|
| 4719 |
+
|
| 4720 |
+
``` cpp
|
| 4721 |
+
return static_cast<common_type_t<ptrdiff_t, make_signed_t<decltype(c.size())>>>(c.size());
|
| 4722 |
+
```
|
| 4723 |
+
|
| 4724 |
+
``` cpp
|
| 4725 |
+
template<class T, ptrdiff_t N> constexpr ptrdiff_t ssize(const T (&array)[N]) noexcept;
|
| 4726 |
+
```
|
| 4727 |
+
|
| 4728 |
+
*Returns:* `N`.
|
| 4729 |
+
|
| 4730 |
+
``` cpp
|
| 4731 |
+
template<class C> [[nodiscard]] constexpr auto empty(const C& c) -> decltype(c.empty());
|
| 4732 |
```
|
| 4733 |
|
| 4734 |
*Returns:* `c.empty()`.
|
| 4735 |
|
| 4736 |
``` cpp
|
| 4737 |
+
template<class T, size_t N> [[nodiscard]] constexpr bool empty(const T (&array)[N]) noexcept;
|
| 4738 |
```
|
| 4739 |
|
| 4740 |
*Returns:* `false`.
|
| 4741 |
|
| 4742 |
``` cpp
|
| 4743 |
+
template<class E> [[nodiscard]] constexpr bool empty(initializer_list<E> il) noexcept;
|
| 4744 |
```
|
| 4745 |
|
| 4746 |
*Returns:* `il.size() == 0`.
|
| 4747 |
|
| 4748 |
``` cpp
|
|
|
|
| 4763 |
```
|
| 4764 |
|
| 4765 |
*Returns:* `il.begin()`.
|
| 4766 |
|
| 4767 |
<!-- Link reference definitions -->
|
| 4768 |
+
[alg.req]: #alg.req
|
| 4769 |
+
[alg.req.general]: #alg.req.general
|
| 4770 |
+
[alg.req.ind.cmp]: #alg.req.ind.cmp
|
| 4771 |
+
[alg.req.ind.copy]: #alg.req.ind.copy
|
| 4772 |
+
[alg.req.ind.move]: #alg.req.ind.move
|
| 4773 |
+
[alg.req.ind.swap]: #alg.req.ind.swap
|
| 4774 |
+
[alg.req.mergeable]: #alg.req.mergeable
|
| 4775 |
+
[alg.req.permutable]: #alg.req.permutable
|
| 4776 |
+
[alg.req.sortable]: #alg.req.sortable
|
| 4777 |
[back.insert.iter.ops]: #back.insert.iter.ops
|
| 4778 |
[back.insert.iterator]: #back.insert.iterator
|
| 4779 |
[back.inserter]: #back.inserter
|
| 4780 |
+
[basic.fundamental]: basic.md#basic.fundamental
|
| 4781 |
+
[basic.lookup.argdep]: basic.md#basic.lookup.argdep
|
| 4782 |
+
[basic.lookup.unqual]: basic.md#basic.lookup.unqual
|
| 4783 |
+
[basic.lval]: expr.md#basic.lval
|
| 4784 |
[bidirectional.iterators]: #bidirectional.iterators
|
| 4785 |
+
[bidirectionaliterator]: #bidirectionaliterator
|
| 4786 |
+
[common.iter.access]: #common.iter.access
|
| 4787 |
+
[common.iter.cmp]: #common.iter.cmp
|
| 4788 |
+
[common.iter.const]: #common.iter.const
|
| 4789 |
+
[common.iter.cust]: #common.iter.cust
|
| 4790 |
+
[common.iter.nav]: #common.iter.nav
|
| 4791 |
+
[common.iter.types]: #common.iter.types
|
| 4792 |
+
[common.iterator]: #common.iterator
|
| 4793 |
+
[concept.swappable]: concepts.md#concept.swappable
|
| 4794 |
+
[concept.totallyordered]: concepts.md#concept.totallyordered
|
| 4795 |
+
[concepts.object]: concepts.md#concepts.object
|
| 4796 |
[containers]: containers.md#containers
|
| 4797 |
+
[counted.iter.access]: #counted.iter.access
|
| 4798 |
+
[counted.iter.cmp]: #counted.iter.cmp
|
| 4799 |
+
[counted.iter.const]: #counted.iter.const
|
| 4800 |
+
[counted.iter.cust]: #counted.iter.cust
|
| 4801 |
+
[counted.iter.elem]: #counted.iter.elem
|
| 4802 |
+
[counted.iter.nav]: #counted.iter.nav
|
| 4803 |
+
[counted.iterator]: #counted.iterator
|
| 4804 |
+
[cpp17.copyassignable]: #cpp17.copyassignable
|
| 4805 |
+
[cpp17.equalitycomparable]: #cpp17.equalitycomparable
|
| 4806 |
+
[customization.point.object]: library.md#customization.point.object
|
| 4807 |
+
[default.sentinels]: #default.sentinels
|
| 4808 |
+
[defns.projection]: library.md#defns.projection
|
| 4809 |
+
[expr.call]: expr.md#expr.call
|
| 4810 |
+
[expr.const]: expr.md#expr.const
|
| 4811 |
[forward.iterators]: #forward.iterators
|
| 4812 |
+
[forwarditerator]: #forwarditerator
|
|
|
|
|
|
|
|
|
|
| 4813 |
[front.insert.iter.ops]: #front.insert.iter.ops
|
| 4814 |
[front.insert.iterator]: #front.insert.iterator
|
| 4815 |
[front.inserter]: #front.inserter
|
| 4816 |
+
[func.def]: utilities.md#func.def
|
| 4817 |
+
[incrementable.traits]: #incrementable.traits
|
| 4818 |
+
[indirectcallable]: #indirectcallable
|
| 4819 |
+
[indirectcallable.general]: #indirectcallable.general
|
| 4820 |
+
[indirectcallable.indirectinvocable]: #indirectcallable.indirectinvocable
|
| 4821 |
[input.iterators]: #input.iterators
|
| 4822 |
+
[inputiterator]: #inputiterator
|
|
|
|
|
|
|
|
|
|
| 4823 |
[insert.iter.ops]: #insert.iter.ops
|
| 4824 |
[insert.iterator]: #insert.iterator
|
| 4825 |
[insert.iterators]: #insert.iterators
|
| 4826 |
[inserter]: #inserter
|
| 4827 |
[iostream.format]: input.md#iostream.format
|
|
|
|
| 4830 |
[istream.iterator.ops]: #istream.iterator.ops
|
| 4831 |
[istreambuf.iterator]: #istreambuf.iterator
|
| 4832 |
[istreambuf.iterator.cons]: #istreambuf.iterator.cons
|
| 4833 |
[istreambuf.iterator.ops]: #istreambuf.iterator.ops
|
| 4834 |
[istreambuf.iterator.proxy]: #istreambuf.iterator.proxy
|
| 4835 |
+
[iterator]: #iterator
|
| 4836 |
+
[iterator.assoc.types]: #iterator.assoc.types
|
| 4837 |
+
[iterator.concept.bidir]: #iterator.concept.bidir
|
| 4838 |
+
[iterator.concept.contiguous]: #iterator.concept.contiguous
|
| 4839 |
+
[iterator.concept.forward]: #iterator.concept.forward
|
| 4840 |
+
[iterator.concept.inc]: #iterator.concept.inc
|
| 4841 |
+
[iterator.concept.input]: #iterator.concept.input
|
| 4842 |
+
[iterator.concept.iterator]: #iterator.concept.iterator
|
| 4843 |
+
[iterator.concept.output]: #iterator.concept.output
|
| 4844 |
+
[iterator.concept.random.access]: #iterator.concept.random.access
|
| 4845 |
+
[iterator.concept.readable]: #iterator.concept.readable
|
| 4846 |
+
[iterator.concept.sentinel]: #iterator.concept.sentinel
|
| 4847 |
+
[iterator.concept.sizedsentinel]: #iterator.concept.sizedsentinel
|
| 4848 |
+
[iterator.concept.winc]: #iterator.concept.winc
|
| 4849 |
+
[iterator.concept.writable]: #iterator.concept.writable
|
| 4850 |
+
[iterator.concepts]: #iterator.concepts
|
| 4851 |
+
[iterator.concepts.general]: #iterator.concepts.general
|
| 4852 |
+
[iterator.cpp17]: #iterator.cpp17
|
| 4853 |
+
[iterator.cust]: #iterator.cust
|
| 4854 |
+
[iterator.cust.move]: #iterator.cust.move
|
| 4855 |
+
[iterator.cust.swap]: #iterator.cust.swap
|
| 4856 |
[iterator.iterators]: #iterator.iterators
|
| 4857 |
[iterator.operations]: #iterator.operations
|
| 4858 |
[iterator.primitives]: #iterator.primitives
|
| 4859 |
[iterator.range]: #iterator.range
|
| 4860 |
[iterator.requirements]: #iterator.requirements
|
| 4861 |
[iterator.requirements.general]: #iterator.requirements.general
|
| 4862 |
[iterator.synopsis]: #iterator.synopsis
|
| 4863 |
[iterator.traits]: #iterator.traits
|
| 4864 |
[iterators]: #iterators
|
| 4865 |
+
[iterators.common]: #iterators.common
|
| 4866 |
+
[iterators.counted]: #iterators.counted
|
| 4867 |
[iterators.general]: #iterators.general
|
| 4868 |
+
[iterators.relations]: #iterators.relations
|
| 4869 |
+
[iterators.summary]: #iterators.summary
|
| 4870 |
+
[lib.types.movedfrom]: library.md#lib.types.movedfrom
|
| 4871 |
+
[move.iter.cons]: #move.iter.cons
|
| 4872 |
+
[move.iter.elem]: #move.iter.elem
|
| 4873 |
+
[move.iter.nav]: #move.iter.nav
|
| 4874 |
[move.iter.nonmember]: #move.iter.nonmember
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4875 |
[move.iter.op.comp]: #move.iter.op.comp
|
|
|
|
| 4876 |
[move.iter.op.conv]: #move.iter.op.conv
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4877 |
[move.iter.requirements]: #move.iter.requirements
|
| 4878 |
[move.iterator]: #move.iterator
|
| 4879 |
[move.iterators]: #move.iterators
|
| 4880 |
+
[move.sent.ops]: #move.sent.ops
|
| 4881 |
+
[move.sentinel]: #move.sentinel
|
| 4882 |
+
[namespace.std]: library.md#namespace.std
|
| 4883 |
[ostream.iterator]: #ostream.iterator
|
| 4884 |
[ostream.iterator.cons.des]: #ostream.iterator.cons.des
|
| 4885 |
[ostream.iterator.ops]: #ostream.iterator.ops
|
| 4886 |
[ostreambuf.iter.cons]: #ostreambuf.iter.cons
|
| 4887 |
[ostreambuf.iter.ops]: #ostreambuf.iter.ops
|
| 4888 |
[ostreambuf.iterator]: #ostreambuf.iterator
|
| 4889 |
[output.iterators]: #output.iterators
|
| 4890 |
+
[outputiterator]: #outputiterator
|
| 4891 |
[predef.iterators]: #predef.iterators
|
| 4892 |
+
[projected]: #projected
|
| 4893 |
[random.access.iterators]: #random.access.iterators
|
| 4894 |
+
[randomaccessiterator]: #randomaccessiterator
|
| 4895 |
+
[range.cmp]: utilities.md#range.cmp
|
| 4896 |
+
[range.iter.op.advance]: #range.iter.op.advance
|
| 4897 |
+
[range.iter.op.distance]: #range.iter.op.distance
|
| 4898 |
+
[range.iter.op.next]: #range.iter.op.next
|
| 4899 |
+
[range.iter.op.prev]: #range.iter.op.prev
|
| 4900 |
+
[range.iter.ops]: #range.iter.ops
|
| 4901 |
+
[ranges]: ranges.md#ranges
|
| 4902 |
+
[readable.traits]: #readable.traits
|
| 4903 |
+
[reverse.iter.cmp]: #reverse.iter.cmp
|
| 4904 |
[reverse.iter.cons]: #reverse.iter.cons
|
| 4905 |
[reverse.iter.conv]: #reverse.iter.conv
|
| 4906 |
+
[reverse.iter.elem]: #reverse.iter.elem
|
| 4907 |
+
[reverse.iter.nav]: #reverse.iter.nav
|
| 4908 |
+
[reverse.iter.nonmember]: #reverse.iter.nonmember
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4909 |
[reverse.iter.requirements]: #reverse.iter.requirements
|
| 4910 |
[reverse.iterator]: #reverse.iterator
|
| 4911 |
[reverse.iterators]: #reverse.iterators
|
| 4912 |
[std.iterator.tags]: #std.iterator.tags
|
| 4913 |
[stream.buffers]: input.md#stream.buffers
|
| 4914 |
[stream.iterators]: #stream.iterators
|
| 4915 |
[swappable.requirements]: library.md#swappable.requirements
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4916 |
[temp.deduct]: temp.md#temp.deduct
|
| 4917 |
+
[temp.func.order]: temp.md#temp.func.order
|
| 4918 |
[temp.inst]: temp.md#temp.inst
|
| 4919 |
+
[unreachable.sentinel]: #unreachable.sentinel
|
| 4920 |
+
[unreachable.sentinels]: #unreachable.sentinels
|
| 4921 |
[utility.arg.requirements]: library.md#utility.arg.requirements
|
| 4922 |
|
| 4923 |
+
[^1]: The sentinel denoting the end of a range may have the same type as
|
| 4924 |
+
the iterator denoting the beginning of the range, or a different
|
| 4925 |
+
type.
|
| 4926 |
+
|
| 4927 |
+
[^2]: This definition applies to pointers, since pointers are iterators.
|
| 4928 |
The effect of dereferencing an iterator that has been invalidated is
|
| 4929 |
undefined.
|