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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Iterator concepts <a id="iterator.concepts">[[iterator.concepts]]</a>
|
| 2 |
+
|
| 3 |
+
#### General <a id="iterator.concepts.general">[[iterator.concepts.general]]</a>
|
| 4 |
+
|
| 5 |
+
For a type `I`, let `ITER_TRAITS(I)` denote the type `I` if
|
| 6 |
+
`iterator_traits<I>` names a specialization generated from the primary
|
| 7 |
+
template. Otherwise, `ITER_TRAITS(I)` denotes `iterator_traits<I>`.
|
| 8 |
+
|
| 9 |
+
- If the *qualified-id* `ITER_TRAITS(I)::iterator_concept` is valid and
|
| 10 |
+
names a type, then `ITER_CONCEPT(I)` denotes that type.
|
| 11 |
+
- Otherwise, if the *qualified-id* `ITER_TRAITS(I){}::iterator_category`
|
| 12 |
+
is valid and names a type, then `ITER_CONCEPT(I)` denotes that type.
|
| 13 |
+
- Otherwise, if `iterator_traits<I>` names a specialization generated
|
| 14 |
+
from the primary template, then `ITER_CONCEPT(I)` denotes
|
| 15 |
+
`random_access_iterator_tag`.
|
| 16 |
+
- Otherwise, `ITER_CONCEPT(I)` does not denote a type.
|
| 17 |
+
|
| 18 |
+
[*Note 1*: `ITER_TRAITS` enables independent syntactic determination of
|
| 19 |
+
an iterator’s category and concept. — *end note*]
|
| 20 |
+
|
| 21 |
+
[*Example 1*:
|
| 22 |
+
|
| 23 |
+
``` cpp
|
| 24 |
+
struct I {
|
| 25 |
+
using value_type = int;
|
| 26 |
+
using difference_type = int;
|
| 27 |
+
|
| 28 |
+
int operator*() const;
|
| 29 |
+
I& operator++();
|
| 30 |
+
I operator++(int);
|
| 31 |
+
I& operator--();
|
| 32 |
+
I operator--(int);
|
| 33 |
+
|
| 34 |
+
bool operator==(I) const;
|
| 35 |
+
bool operator!=(I) const;
|
| 36 |
+
};
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
`iterator_traits<I>::iterator_category` denotes `input_iterator_tag`,
|
| 40 |
+
and `ITER_CONCEPT(I)` denotes `random_access_iterator_tag`.
|
| 41 |
+
|
| 42 |
+
— *end example*]
|
| 43 |
+
|
| 44 |
+
#### Concept <a id="iterator.concept.readable">[[iterator.concept.readable]]</a>
|
| 45 |
+
|
| 46 |
+
Types that are indirectly readable by applying `operator*` model the
|
| 47 |
+
`indirectly_readable` concept, including pointers, smart pointers, and
|
| 48 |
+
iterators.
|
| 49 |
+
|
| 50 |
+
``` cpp
|
| 51 |
+
template<class In>
|
| 52 |
+
concept indirectly-readable-impl =
|
| 53 |
+
requires(const In in) {
|
| 54 |
+
typename iter_value_t<In>;
|
| 55 |
+
typename iter_reference_t<In>;
|
| 56 |
+
typename iter_rvalue_reference_t<In>;
|
| 57 |
+
{ *in } -> same_as<iter_reference_t<In>>;
|
| 58 |
+
{ ranges::iter_move(in) } -> same_as<iter_rvalue_reference_t<In>>;
|
| 59 |
+
} &&
|
| 60 |
+
common_reference_with<iter_reference_t<In>&&, iter_value_t<In>&> &&
|
| 61 |
+
common_reference_with<iter_reference_t<In>&&, iter_rvalue_reference_t<In>&&> &&
|
| 62 |
+
common_reference_with<iter_rvalue_reference_t<In>&&, const iter_value_t<In>&>;
|
| 63 |
+
```
|
| 64 |
+
|
| 65 |
+
``` cpp
|
| 66 |
+
template<class In>
|
| 67 |
+
concept indirectly_readable =
|
| 68 |
+
indirectly-readable-impl<remove_cvref_t<In>>;
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
Given a value `i` of type `I`, `I` models `indirectly_readable` only if
|
| 72 |
+
the expression `*i` is equality-preserving.
|
| 73 |
+
|
| 74 |
+
[*Note 1*: The expression `*i` is indirectly required to be valid via
|
| 75 |
+
the exposition-only `dereferenceable` concept
|
| 76 |
+
[[iterator.synopsis]]. — *end note*]
|
| 77 |
+
|
| 78 |
+
#### Concept <a id="iterator.concept.writable">[[iterator.concept.writable]]</a>
|
| 79 |
+
|
| 80 |
+
The `indirectly_writable` concept specifies the requirements for writing
|
| 81 |
+
a value into an iterator’s referenced object.
|
| 82 |
+
|
| 83 |
+
``` cpp
|
| 84 |
+
template<class Out, class T>
|
| 85 |
+
concept indirectly_writable =
|
| 86 |
+
requires(Out&& o, T&& t) {
|
| 87 |
+
*o = std::forward<T>(t); // not required to be equality-preserving
|
| 88 |
+
*std::forward<Out>(o) = std::forward<T>(t); // not required to be equality-preserving
|
| 89 |
+
const_cast<const iter_reference_t<Out>&&>(*o) =
|
| 90 |
+
std::forward<T>(t); // not required to be equality-preserving
|
| 91 |
+
const_cast<const iter_reference_t<Out>&&>(*std::forward<Out>(o)) =
|
| 92 |
+
std::forward<T>(t); // not required to be equality-preserving
|
| 93 |
+
};
|
| 94 |
+
```
|
| 95 |
+
|
| 96 |
+
Let `E` be an expression such that `decltype((E))` is `T`, and let `o`
|
| 97 |
+
be a dereferenceable object of type `Out`. `Out` and `T` model
|
| 98 |
+
`indirectly_writable<Out, T>` only if
|
| 99 |
+
|
| 100 |
+
- If `Out` and `T` model
|
| 101 |
+
`indirectly_readable<Out> && same_as<iter_value_t<Out>, decay_t<T>{>}`,
|
| 102 |
+
then `*o` after any above assignment is equal to the value of `E`
|
| 103 |
+
before the assignment.
|
| 104 |
+
|
| 105 |
+
After evaluating any above assignment expression, `o` is not required to
|
| 106 |
+
be dereferenceable.
|
| 107 |
+
|
| 108 |
+
If `E` is an xvalue [[basic.lval]], the resulting state of the object it
|
| 109 |
+
denotes is valid but unspecified [[lib.types.movedfrom]].
|
| 110 |
+
|
| 111 |
+
[*Note 1*: The only valid use of an `operator*` is on the left side of
|
| 112 |
+
the assignment statement. Assignment through the same value of the
|
| 113 |
+
indirectly writable type happens only once. — *end note*]
|
| 114 |
+
|
| 115 |
+
[*Note 2*: `indirectly_writable` has the awkward `const_cast`
|
| 116 |
+
expressions to reject iterators with prvalue non-proxy reference types
|
| 117 |
+
that permit rvalue assignment but do not also permit `const` rvalue
|
| 118 |
+
assignment. Consequently, an iterator type `I` that returns
|
| 119 |
+
`std::string` by value does not model
|
| 120 |
+
`indirectly_writable<I, std::string>`. — *end note*]
|
| 121 |
+
|
| 122 |
+
#### Concept <a id="iterator.concept.winc">[[iterator.concept.winc]]</a>
|
| 123 |
+
|
| 124 |
+
The `weakly_incrementable` concept specifies the requirements on types
|
| 125 |
+
that can be incremented with the pre- and post-increment operators. The
|
| 126 |
+
increment operations are not required to be equality-preserving, nor is
|
| 127 |
+
the type required to be `equality_comparable`.
|
| 128 |
+
|
| 129 |
+
``` cpp
|
| 130 |
+
template<class T>
|
| 131 |
+
inline constexpr bool is-integer-like = see below; // exposition only
|
| 132 |
+
|
| 133 |
+
template<class T>
|
| 134 |
+
inline constexpr bool is-signed-integer-like = see below; // exposition only
|
| 135 |
+
|
| 136 |
+
template<class I>
|
| 137 |
+
concept weakly_incrementable =
|
| 138 |
+
default_initializable<I> && movable<I> &&
|
| 139 |
+
requires(I i) {
|
| 140 |
+
typename iter_difference_t<I>;
|
| 141 |
+
requires is-signed-integer-like<iter_difference_t<I>>;
|
| 142 |
+
{ ++i } -> same_as<I&>; // not required to be equality-preserving
|
| 143 |
+
i++; // not required to be equality-preserving
|
| 144 |
+
};
|
| 145 |
+
```
|
| 146 |
+
|
| 147 |
+
A type `I` is an *integer-class type* if it is in a set of
|
| 148 |
+
implementation-defined class types that behave as integer types do, as
|
| 149 |
+
defined in below.
|
| 150 |
+
|
| 151 |
+
The range of representable values of an integer-class type is the
|
| 152 |
+
continuous set of values over which it is defined. The values 0 and 1
|
| 153 |
+
are part of the range of every integer-class type. If any negative
|
| 154 |
+
numbers are part of the range, the type is a
|
| 155 |
+
*signed-integer-class type*; otherwise, it is an
|
| 156 |
+
*unsigned-integer-class type*.
|
| 157 |
+
|
| 158 |
+
For every integer-class type `I`, let `B(I)` be a hypothetical extended
|
| 159 |
+
integer type of the same signedness with the smallest width
|
| 160 |
+
[[basic.fundamental]] capable of representing the same range of values.
|
| 161 |
+
The width of `I` is equal to the width of `B(I)`.
|
| 162 |
+
|
| 163 |
+
Let `a` and `b` be objects of integer-class type `I`, let `x` and `y` be
|
| 164 |
+
objects of type `B(I)` as described above that represent the same values
|
| 165 |
+
as `a` and `b` respectively, and let `c` be an lvalue of any integral
|
| 166 |
+
type.
|
| 167 |
+
|
| 168 |
+
- For every unary operator `@` for which the expression `@x` is
|
| 169 |
+
well-formed, `@a` shall also be well-formed and have the same value,
|
| 170 |
+
effects, and value category as `@x` provided that value is
|
| 171 |
+
representable by `I`. If `@x` has type `bool`, so too does `@a`; if
|
| 172 |
+
`@x` has type `B(I)`, then `@a` has type `I`.
|
| 173 |
+
- For every assignment operator `@=` for which `c @= x` is well-formed,
|
| 174 |
+
`c @= a` shall also be well-formed and shall have the same value and
|
| 175 |
+
effects as `c @= x`. The expression `c @= a` shall be an lvalue
|
| 176 |
+
referring to `c`.
|
| 177 |
+
- For every binary operator `@` for which `x @ y` is well-formed,
|
| 178 |
+
`a @ b` shall also be well-formed and shall have the same value,
|
| 179 |
+
effects, and value category as `x @ y` provided that value is
|
| 180 |
+
representable by `I`. If `x @ y` has type `bool`, so too does `a @ b`;
|
| 181 |
+
if `x @ y` has type `B(I)`, then `a @ b` has type `I`.
|
| 182 |
+
|
| 183 |
+
Expressions of integer-class type are explicitly convertible to any
|
| 184 |
+
integral type. Expressions of integral type are both implicitly and
|
| 185 |
+
explicitly convertible to any integer-class type. Conversions between
|
| 186 |
+
integral and integer-class types do not exit via an exception.
|
| 187 |
+
|
| 188 |
+
An expression `E` of integer-class type `I` is contextually convertible
|
| 189 |
+
to `bool` as if by `bool(E != I(0))`.
|
| 190 |
+
|
| 191 |
+
All integer-class types model `regular` [[concepts.object]] and
|
| 192 |
+
`totally_ordered` [[concept.totallyordered]].
|
| 193 |
+
|
| 194 |
+
A value-initialized object of integer-class type has value 0.
|
| 195 |
+
|
| 196 |
+
For every (possibly cv-qualified) integer-class type `I`,
|
| 197 |
+
`numeric_limits<I>` is specialized such that:
|
| 198 |
+
|
| 199 |
+
- `numeric_limits<I>::is_specialized` is `true`,
|
| 200 |
+
- `numeric_limits<I>::is_signed` is `true` if and only if `I` is a
|
| 201 |
+
signed-integer-class type,
|
| 202 |
+
- `numeric_limits<I>::is_integer` is `true`,
|
| 203 |
+
- `numeric_limits<I>::is_exact` is `true`,
|
| 204 |
+
- `numeric_limits<I>::digits` is equal to the width of the integer-class
|
| 205 |
+
type,
|
| 206 |
+
- `numeric_limits<I>::digits10` is equal to
|
| 207 |
+
`static_cast<int>(digits * log10(2))`, and
|
| 208 |
+
- `numeric_limits<I>::min()` and `numeric_limits<I>::max()` return the
|
| 209 |
+
lowest and highest representable values of `I`, respectively, and
|
| 210 |
+
`numeric_limits<I>::lowest()` returns `numeric_limits<I>::{}min()`.
|
| 211 |
+
|
| 212 |
+
A type `I` is *integer-like* if it models `integral<I>` or if it is an
|
| 213 |
+
integer-class type. A type `I` is *signed-integer-like* if it models
|
| 214 |
+
`signed_integral<I>` or if it is a signed-integer-class type. A type `I`
|
| 215 |
+
is *unsigned-integer-like* if it models `unsigned_integral<I>` or if it
|
| 216 |
+
is an unsigned-integer-class type.
|
| 217 |
+
|
| 218 |
+
`is-integer-like<I>` is `true` if and only if `I` is an integer-like
|
| 219 |
+
type. `is-signed-integer-like<I>` is `true` if and only if I is a
|
| 220 |
+
signed-integer-like type.
|
| 221 |
+
|
| 222 |
+
Let `i` be an object of type `I`. When `i` is in the domain of both pre-
|
| 223 |
+
and post-increment, `i` is said to be *incrementable*. `I` models
|
| 224 |
+
`weakly_incrementable<I>` only if
|
| 225 |
+
|
| 226 |
+
- The expressions `++i` and `i++` have the same domain.
|
| 227 |
+
- If `i` is incrementable, then both `++i` and `i++` advance `i` to the
|
| 228 |
+
next element.
|
| 229 |
+
- If `i` is incrementable, then `addressof(++i)` is equal to
|
| 230 |
+
`addressof(i)`.
|
| 231 |
+
|
| 232 |
+
[*Note 1*: For `weakly_incrementable` types, `a` equals `b` does not
|
| 233 |
+
imply that `++a` equals `++b`. (Equality does not guarantee the
|
| 234 |
+
substitution property or referential transparency.) Algorithms on weakly
|
| 235 |
+
incrementable types should never attempt to pass through the same
|
| 236 |
+
incrementable value twice. They should be single-pass algorithms. These
|
| 237 |
+
algorithms can be used with istreams as the source of the input data
|
| 238 |
+
through the `istream_iterator` class template. — *end note*]
|
| 239 |
+
|
| 240 |
+
#### Concept <a id="iterator.concept.inc">[[iterator.concept.inc]]</a>
|
| 241 |
+
|
| 242 |
+
The `incrementable` concept specifies requirements on types that can be
|
| 243 |
+
incremented with the pre- and post-increment operators. The increment
|
| 244 |
+
operations are required to be equality-preserving, and the type is
|
| 245 |
+
required to be `equality_comparable`.
|
| 246 |
+
|
| 247 |
+
[*Note 1*: This supersedes the annotations on the increment expressions
|
| 248 |
+
in the definition of `weakly_incrementable`. — *end note*]
|
| 249 |
+
|
| 250 |
+
``` cpp
|
| 251 |
+
template<class I>
|
| 252 |
+
concept incrementable =
|
| 253 |
+
regular<I> &&
|
| 254 |
+
weakly_incrementable<I> &&
|
| 255 |
+
requires(I i) {
|
| 256 |
+
{ i++ } -> same_as<I>;
|
| 257 |
+
};
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
Let `a` and `b` be incrementable objects of type `I`. `I` models
|
| 261 |
+
`incrementable` only if
|
| 262 |
+
|
| 263 |
+
- If `bool(a == b)` then `bool(a++ == b)`.
|
| 264 |
+
- If `bool(a == b)` then `bool(((void)a++, a) == ++b)`.
|
| 265 |
+
|
| 266 |
+
[*Note 2*: The requirement that `a` equals `b` implies `++a` equals
|
| 267 |
+
`++b` (which is not true for weakly incrementable types) allows the use
|
| 268 |
+
of multi-pass one-directional algorithms with types that model
|
| 269 |
+
`incrementable`. — *end note*]
|
| 270 |
+
|
| 271 |
+
#### Concept <a id="iterator.concept.iterator">[[iterator.concept.iterator]]</a>
|
| 272 |
+
|
| 273 |
+
The `input_or_output_iterator` concept forms the basis of the iterator
|
| 274 |
+
concept taxonomy; every iterator models `input_or_output_iterator`. This
|
| 275 |
+
concept specifies operations for dereferencing and incrementing an
|
| 276 |
+
iterator. Most algorithms will require additional operations to compare
|
| 277 |
+
iterators with sentinels [[iterator.concept.sentinel]], to read
|
| 278 |
+
[[iterator.concept.input]] or write [[iterator.concept.output]] values,
|
| 279 |
+
or to provide a richer set of iterator movements (
|
| 280 |
+
[[iterator.concept.forward]], [[iterator.concept.bidir]],
|
| 281 |
+
[[iterator.concept.random.access]]).
|
| 282 |
+
|
| 283 |
+
``` cpp
|
| 284 |
+
template<class I>
|
| 285 |
+
concept input_or_output_iterator =
|
| 286 |
+
requires(I i) {
|
| 287 |
+
{ *i } -> can-reference;
|
| 288 |
+
} &&
|
| 289 |
+
weakly_incrementable<I>;
|
| 290 |
+
```
|
| 291 |
+
|
| 292 |
+
[*Note 1*: Unlike the *Cpp17Iterator* requirements, the
|
| 293 |
+
`input_or_output_iterator` concept does not require
|
| 294 |
+
copyability. — *end note*]
|
| 295 |
+
|
| 296 |
+
#### Concept <a id="iterator.concept.sentinel">[[iterator.concept.sentinel]]</a>
|
| 297 |
+
|
| 298 |
+
The `sentinel_for` concept specifies the relationship between an
|
| 299 |
+
`input_or_output_iterator` type and a `semiregular` type whose values
|
| 300 |
+
denote a range.
|
| 301 |
+
|
| 302 |
+
``` cpp
|
| 303 |
+
template<class S, class I>
|
| 304 |
+
concept sentinel_for =
|
| 305 |
+
semiregular<S> &&
|
| 306 |
+
input_or_output_iterator<I> &&
|
| 307 |
+
weakly-equality-comparable-with<S, I>; // See [concept.equalitycomparable]
|
| 308 |
+
```
|
| 309 |
+
|
| 310 |
+
Let `s` and `i` be values of type `S` and `I` such that \[`i`, `s`)
|
| 311 |
+
denotes a range. Types `S` and `I` model `sentinel_for<S, I>` only if
|
| 312 |
+
|
| 313 |
+
- `i == s` is well-defined.
|
| 314 |
+
- If `bool(i != s)` then `i` is dereferenceable and \[`++i`, `s`)
|
| 315 |
+
denotes a range.
|
| 316 |
+
|
| 317 |
+
The domain of `==` is not static. Given an iterator `i` and sentinel `s`
|
| 318 |
+
such that \[`i`, `s`) denotes a range and `i != s`, `i` and `s` are not
|
| 319 |
+
required to continue to denote a range after incrementing any other
|
| 320 |
+
iterator equal to `i`. Consequently, `i == s` is no longer required to
|
| 321 |
+
be well-defined.
|
| 322 |
+
|
| 323 |
+
#### Concept <a id="iterator.concept.sizedsentinel">[[iterator.concept.sizedsentinel]]</a>
|
| 324 |
+
|
| 325 |
+
The `sized_sentinel_for` concept specifies requirements on an
|
| 326 |
+
`input_or_output_iterator` type `I` and a corresponding
|
| 327 |
+
`sentinel_for<I>` that allow the use of the `-` operator to compute the
|
| 328 |
+
distance between them in constant time.
|
| 329 |
+
|
| 330 |
+
``` cpp
|
| 331 |
+
template<class S, class I>
|
| 332 |
+
concept sized_sentinel_for =
|
| 333 |
+
sentinel_for<S, I> &&
|
| 334 |
+
!disable_sized_sentinel_for<remove_cv_t<S>, remove_cv_t<I>> &&
|
| 335 |
+
requires(const I& i, const S& s) {
|
| 336 |
+
{ s - i } -> same_as<iter_difference_t<I>>;
|
| 337 |
+
{ i - s } -> same_as<iter_difference_t<I>>;
|
| 338 |
+
};
|
| 339 |
+
```
|
| 340 |
+
|
| 341 |
+
Let `i` be an iterator of type `I`, and `s` a sentinel of type `S` such
|
| 342 |
+
that \[`i`, `s`) denotes a range. Let N be the smallest number of
|
| 343 |
+
applications of `++i` necessary to make `bool(i == s)` be `true`. `S`
|
| 344 |
+
and `I` model `sized_sentinel_for<S, I>` only if
|
| 345 |
+
|
| 346 |
+
- If N is representable by `iter_difference_t<I>`, then `s - i` is
|
| 347 |
+
well-defined and equals N.
|
| 348 |
+
- If -N is representable by `iter_difference_t<I>`, then `i - s` is
|
| 349 |
+
well-defined and equals -N.
|
| 350 |
+
|
| 351 |
+
``` cpp
|
| 352 |
+
template<class S, class I>
|
| 353 |
+
inline constexpr bool disable_sized_sentinel_for = false;
|
| 354 |
+
```
|
| 355 |
+
|
| 356 |
+
*Remarks:* Pursuant to [[namespace.std]], users may specialize
|
| 357 |
+
`disable_sized_sentinel_for` for cv-unqualified non-array object types
|
| 358 |
+
`S` and `I` if `S` and/or `I` is a program-defined type. Such
|
| 359 |
+
specializations shall be usable in constant expressions [[expr.const]]
|
| 360 |
+
and have type `const bool`.
|
| 361 |
+
|
| 362 |
+
[*Note 1*: `disable_sized_sentinel_for` allows use of sentinels and
|
| 363 |
+
iterators with the library that satisfy but do not in fact model
|
| 364 |
+
`sized_sentinel_for`. — *end note*]
|
| 365 |
+
|
| 366 |
+
[*Example 1*: The `sized_sentinel_for` concept is modeled by pairs of
|
| 367 |
+
`random_access_iterator`s [[iterator.concept.random.access]] and by
|
| 368 |
+
counted iterators and their
|
| 369 |
+
sentinels [[counted.iterator]]. — *end example*]
|
| 370 |
+
|
| 371 |
+
#### Concept <a id="iterator.concept.input">[[iterator.concept.input]]</a>
|
| 372 |
+
|
| 373 |
+
The `input_iterator` concept defines requirements for a type whose
|
| 374 |
+
referenced values can be read (from the requirement for
|
| 375 |
+
`indirectly_readable` [[iterator.concept.readable]]) and which can be
|
| 376 |
+
both pre- and post-incremented.
|
| 377 |
+
|
| 378 |
+
[*Note 1*: Unlike the *Cpp17InputIterator* requirements
|
| 379 |
+
[[input.iterators]], the `input_iterator` concept does not need equality
|
| 380 |
+
comparison since iterators are typically compared to
|
| 381 |
+
sentinels. — *end note*]
|
| 382 |
+
|
| 383 |
+
``` cpp
|
| 384 |
+
template<class I>
|
| 385 |
+
concept input_iterator =
|
| 386 |
+
input_or_output_iterator<I> &&
|
| 387 |
+
indirectly_readable<I> &&
|
| 388 |
+
requires { typename ITER_CONCEPT(I); } &&
|
| 389 |
+
derived_from<ITER_CONCEPT(I), input_iterator_tag>;
|
| 390 |
+
```
|
| 391 |
+
|
| 392 |
+
#### Concept <a id="iterator.concept.output">[[iterator.concept.output]]</a>
|
| 393 |
+
|
| 394 |
+
The `output_iterator` concept defines requirements for a type that can
|
| 395 |
+
be used to write values (from the requirement for `indirectly_writable`
|
| 396 |
+
[[iterator.concept.writable]]) and which can be both pre- and
|
| 397 |
+
post-incremented.
|
| 398 |
+
|
| 399 |
+
[*Note 1*: Output iterators are not required to model
|
| 400 |
+
`equality_comparable`. — *end note*]
|
| 401 |
+
|
| 402 |
+
``` cpp
|
| 403 |
+
template<class I, class T>
|
| 404 |
+
concept output_iterator =
|
| 405 |
+
input_or_output_iterator<I> &&
|
| 406 |
+
indirectly_writable<I, T> &&
|
| 407 |
+
requires(I i, T&& t) {
|
| 408 |
+
*i++ = std::forward<T>(t); // not required to be equality-preserving
|
| 409 |
+
};
|
| 410 |
+
```
|
| 411 |
+
|
| 412 |
+
Let `E` be an expression such that `decltype((E))` is `T`, and let `i`
|
| 413 |
+
be a dereferenceable object of type `I`. `I` and `T` model
|
| 414 |
+
`output_iterator<I, T>` only if `*i++ = E;` has effects equivalent to:
|
| 415 |
+
|
| 416 |
+
``` cpp
|
| 417 |
+
*i = E;
|
| 418 |
+
++i;
|
| 419 |
+
```
|
| 420 |
+
|
| 421 |
+
[*Note 2*: Algorithms on output iterators should never attempt to pass
|
| 422 |
+
through the same iterator twice. They should be single-pass
|
| 423 |
+
algorithms. — *end note*]
|
| 424 |
+
|
| 425 |
+
#### Concept <a id="iterator.concept.forward">[[iterator.concept.forward]]</a>
|
| 426 |
+
|
| 427 |
+
The `forward_iterator` concept adds copyability, equality comparison,
|
| 428 |
+
and the multi-pass guarantee, specified below.
|
| 429 |
+
|
| 430 |
+
``` cpp
|
| 431 |
+
template<class I>
|
| 432 |
+
concept forward_iterator =
|
| 433 |
+
input_iterator<I> &&
|
| 434 |
+
derived_from<ITER_CONCEPT(I), forward_iterator_tag> &&
|
| 435 |
+
incrementable<I> &&
|
| 436 |
+
sentinel_for<I, I>;
|
| 437 |
+
```
|
| 438 |
+
|
| 439 |
+
The domain of `==` for forward iterators is that of iterators over the
|
| 440 |
+
same underlying sequence. However, value-initialized iterators of the
|
| 441 |
+
same type may be compared and shall compare equal to other
|
| 442 |
+
value-initialized iterators of the same type.
|
| 443 |
+
|
| 444 |
+
[*Note 1*: Value-initialized iterators behave as if they refer past the
|
| 445 |
+
end of the same empty sequence. — *end note*]
|
| 446 |
+
|
| 447 |
+
Pointers and references obtained from a forward iterator into a range
|
| 448 |
+
\[`i`, `s`) shall remain valid while \[`i`, `s`) continues to denote a
|
| 449 |
+
range.
|
| 450 |
+
|
| 451 |
+
Two dereferenceable iterators `a` and `b` of type `X` offer the
|
| 452 |
+
*multi-pass guarantee* if:
|
| 453 |
+
|
| 454 |
+
- `a == b` implies `++a == ++b` and
|
| 455 |
+
- The expression `((void)[](X x){++x;}(a), *a)` is equivalent to the
|
| 456 |
+
expression `*a`.
|
| 457 |
+
|
| 458 |
+
[*Note 2*: The requirement that `a == b` implies `++a == ++b` and the
|
| 459 |
+
removal of the restrictions on the number of assignments through a
|
| 460 |
+
mutable iterator (which applies to output iterators) allow the use of
|
| 461 |
+
multi-pass one-directional algorithms with forward
|
| 462 |
+
iterators. — *end note*]
|
| 463 |
+
|
| 464 |
+
#### Concept <a id="iterator.concept.bidir">[[iterator.concept.bidir]]</a>
|
| 465 |
+
|
| 466 |
+
The `bidirectional_iterator` concept adds the ability to move an
|
| 467 |
+
iterator backward as well as forward.
|
| 468 |
+
|
| 469 |
+
``` cpp
|
| 470 |
+
template<class I>
|
| 471 |
+
concept bidirectional_iterator =
|
| 472 |
+
forward_iterator<I> &&
|
| 473 |
+
derived_from<ITER_CONCEPT(I), bidirectional_iterator_tag> &&
|
| 474 |
+
requires(I i) {
|
| 475 |
+
{ --i } -> same_as<I&>;
|
| 476 |
+
{ i-- } -> same_as<I>;
|
| 477 |
+
};
|
| 478 |
+
```
|
| 479 |
+
|
| 480 |
+
A bidirectional iterator `r` is decrementable if and only if there
|
| 481 |
+
exists some `q` such that `++q == r`. Decrementable iterators `r` shall
|
| 482 |
+
be in the domain of the expressions `--r` and `r--`.
|
| 483 |
+
|
| 484 |
+
Let `a` and `b` be equal objects of type `I`. `I` models
|
| 485 |
+
`bidirectional_iterator` only if:
|
| 486 |
+
|
| 487 |
+
- If `a` and `b` are decrementable, then all of the following are
|
| 488 |
+
`true`:
|
| 489 |
+
- `addressof(--a) == addressof(a)`
|
| 490 |
+
- `bool(a-- == b)`
|
| 491 |
+
- after evaluating both `a--` and `--b`, `bool(a == b)` is still
|
| 492 |
+
`true`
|
| 493 |
+
- `bool(++(--a) == b)`
|
| 494 |
+
- If `a` and `b` are incrementable, then `bool(--(++a) == b)`.
|
| 495 |
+
|
| 496 |
+
#### Concept <a id="iterator.concept.random.access">[[iterator.concept.random.access]]</a>
|
| 497 |
+
|
| 498 |
+
The `random_access_iterator` concept adds support for constant-time
|
| 499 |
+
advancement with `+=`, `+`, `-=`, and `-`, as well as the computation of
|
| 500 |
+
distance in constant time with `-`. Random access iterators also support
|
| 501 |
+
array notation via subscripting.
|
| 502 |
+
|
| 503 |
+
``` cpp
|
| 504 |
+
template<class I>
|
| 505 |
+
concept random_access_iterator =
|
| 506 |
+
bidirectional_iterator<I> &&
|
| 507 |
+
derived_from<ITER_CONCEPT(I), random_access_iterator_tag> &&
|
| 508 |
+
totally_ordered<I> &&
|
| 509 |
+
sized_sentinel_for<I, I> &&
|
| 510 |
+
requires(I i, const I j, const iter_difference_t<I> n) {
|
| 511 |
+
{ i += n } -> same_as<I&>;
|
| 512 |
+
{ j + n } -> same_as<I>;
|
| 513 |
+
{ n + j } -> same_as<I>;
|
| 514 |
+
{ i -= n } -> same_as<I&>;
|
| 515 |
+
{ j - n } -> same_as<I>;
|
| 516 |
+
{ j[n] } -> same_as<iter_reference_t<I>>;
|
| 517 |
+
};
|
| 518 |
+
```
|
| 519 |
+
|
| 520 |
+
Let `a` and `b` be valid iterators of type `I` such that `b` is
|
| 521 |
+
reachable from `a` after `n` applications of `++a`, let `D` be
|
| 522 |
+
`iter_difference_t<I>`, and let `n` denote a value of type `D`. `I`
|
| 523 |
+
models `random_access_iterator` only if
|
| 524 |
+
|
| 525 |
+
- `(a += n)` is equal to `b`.
|
| 526 |
+
- `addressof(a += n)` is equal to `addressof(a)`.
|
| 527 |
+
- `(a + n)` is equal to `(a += n)`.
|
| 528 |
+
- For any two positive values `x` and `y` of type `D`, if
|
| 529 |
+
`(a + D(x + y))` is valid, then `(a + D(x + y))` is equal to
|
| 530 |
+
`((a + x) + y)`.
|
| 531 |
+
- `(a + D(0))` is equal to `a`.
|
| 532 |
+
- If `(a + D(n - 1))` is valid, then `(a + n)` is equal to
|
| 533 |
+
`[](I c){ return ++c; }(a + D(n - 1))`.
|
| 534 |
+
- `(b += D(-n))` is equal to `a`.
|
| 535 |
+
- `(b -= n)` is equal to `a`.
|
| 536 |
+
- `addressof(b -= n)` is equal to `addressof(b)`.
|
| 537 |
+
- `(b - n)` is equal to `(b -= n)`.
|
| 538 |
+
- If `b` is dereferenceable, then `a[n]` is valid and is equal to `*b`.
|
| 539 |
+
- `bool(a <= b)` is `true`.
|
| 540 |
+
|
| 541 |
+
#### Concept <a id="iterator.concept.contiguous">[[iterator.concept.contiguous]]</a>
|
| 542 |
+
|
| 543 |
+
The `contiguous_iterator` concept provides a guarantee that the denoted
|
| 544 |
+
elements are stored contiguously in memory.
|
| 545 |
+
|
| 546 |
+
``` cpp
|
| 547 |
+
template<class I>
|
| 548 |
+
concept contiguous_iterator =
|
| 549 |
+
random_access_iterator<I> &&
|
| 550 |
+
derived_from<ITER_CONCEPT(I), contiguous_iterator_tag> &&
|
| 551 |
+
is_lvalue_reference_v<iter_reference_t<I>> &&
|
| 552 |
+
same_as<iter_value_t<I>, remove_cvref_t<iter_reference_t<I>>> &&
|
| 553 |
+
requires(const I& i) {
|
| 554 |
+
{ to_address(i) } -> same_as<add_pointer_t<iter_reference_t<I>>>;
|
| 555 |
+
};
|
| 556 |
+
```
|
| 557 |
+
|
| 558 |
+
Let `a` and `b` be dereferenceable iterators and `c` be a
|
| 559 |
+
non-dereferenceable iterator of type `I` such that `b` is reachable from
|
| 560 |
+
`a` and `c` is reachable from `b`, and let `D` be
|
| 561 |
+
`iter_difference_t<I>`. The type `I` models `contiguous_iterator` only
|
| 562 |
+
if
|
| 563 |
+
|
| 564 |
+
- `to_address(a) == addressof(*a)`,
|
| 565 |
+
- `to_address(b) == to_address(a) + D(b - a)`, and
|
| 566 |
+
- `to_address(c) == to_address(a) + D(c - a)`.
|
| 567 |
+
|