tmp/tmpmo2zyye9/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#### Concept <a id="iterator.concept.random.access">[[iterator.concept.random.access]]</a>
|
| 2 |
+
|
| 3 |
+
The `random_access_iterator` concept adds support for constant-time
|
| 4 |
+
advancement with `+=`, `+`, `-=`, and `-`, as well as the computation of
|
| 5 |
+
distance in constant time with `-`. Random access iterators also support
|
| 6 |
+
array notation via subscripting.
|
| 7 |
+
|
| 8 |
+
``` cpp
|
| 9 |
+
template<class I>
|
| 10 |
+
concept random_access_iterator =
|
| 11 |
+
bidirectional_iterator<I> &&
|
| 12 |
+
derived_from<ITER_CONCEPT(I), random_access_iterator_tag> &&
|
| 13 |
+
totally_ordered<I> &&
|
| 14 |
+
sized_sentinel_for<I, I> &&
|
| 15 |
+
requires(I i, const I j, const iter_difference_t<I> n) {
|
| 16 |
+
{ i += n } -> same_as<I&>;
|
| 17 |
+
{ j + n } -> same_as<I>;
|
| 18 |
+
{ n + j } -> same_as<I>;
|
| 19 |
+
{ i -= n } -> same_as<I&>;
|
| 20 |
+
{ j - n } -> same_as<I>;
|
| 21 |
+
{ j[n] } -> same_as<iter_reference_t<I>>;
|
| 22 |
+
};
|
| 23 |
+
```
|
| 24 |
+
|
| 25 |
+
Let `a` and `b` be valid iterators of type `I` such that `b` is
|
| 26 |
+
reachable from `a` after `n` applications of `++a`, let `D` be
|
| 27 |
+
`iter_difference_t<I>`, and let `n` denote a value of type `D`. `I`
|
| 28 |
+
models `random_access_iterator` only if
|
| 29 |
+
|
| 30 |
+
- `(a += n)` is equal to `b`.
|
| 31 |
+
- `addressof(a += n)` is equal to `addressof(a)`.
|
| 32 |
+
- `(a + n)` is equal to `(a += n)`.
|
| 33 |
+
- For any two positive values `x` and `y` of type `D`, if
|
| 34 |
+
`(a + D(x + y))` is valid, then `(a + D(x + y))` is equal to
|
| 35 |
+
`((a + x) + y)`.
|
| 36 |
+
- `(a + D(0))` is equal to `a`.
|
| 37 |
+
- If `(a + D(n - 1))` is valid, then `(a + n)` is equal to
|
| 38 |
+
`[](I c){ return ++c; }(a + D(n - 1))`.
|
| 39 |
+
- `(b += D(-n))` is equal to `a`.
|
| 40 |
+
- `(b -= n)` is equal to `a`.
|
| 41 |
+
- `addressof(b -= n)` is equal to `addressof(b)`.
|
| 42 |
+
- `(b - n)` is equal to `(b -= n)`.
|
| 43 |
+
- If `b` is dereferenceable, then `a[n]` is valid and is equal to `*b`.
|
| 44 |
+
- `bool(a <= b)` is `true`.
|
| 45 |
+
|