tmp/tmpr5_xluuy/{from.md → to.md}
RENAMED
|
@@ -1,38 +1,53 @@
|
|
| 1 |
#### Overview <a id="range.take.overview">[[range.take.overview]]</a>
|
| 2 |
|
| 3 |
-
`take_view` produces a
|
| 4 |
-
|
| 5 |
|
| 6 |
The name `views::take` denotes a range adaptor object
|
| 7 |
[[range.adaptor.object]]. Let `E` and `F` be expressions, let `T` be
|
| 8 |
`remove_cvref_t<decltype((E))>`, and let `D` be
|
| 9 |
`range_difference_t<decltype((E))>`. If `decltype((F))` does not model
|
| 10 |
`convertible_to<D>`, `views::take(E, F)` is ill-formed. Otherwise, the
|
| 11 |
expression `views::take(E, F)` is expression-equivalent to:
|
| 12 |
|
| 13 |
-
- If `T` is a specialization of `
|
| 14 |
-
|
|
|
|
| 15 |
- Otherwise, if `T` models `random_access_range` and `sized_range` and
|
| 16 |
-
is
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
- a specialization of `
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
-
|
| 24 |
-
`
|
| 25 |
-
|
| 26 |
-
- Otherwise, `ranges::take_view{E, F}`.
|
| 27 |
|
| 28 |
[*Example 1*:
|
| 29 |
|
| 30 |
``` cpp
|
| 31 |
vector<int> is{0,1,2,3,4,5,6,7,8,9};
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
cout << i << ' '; // prints: 0 1 2 3 4
|
| 35 |
```
|
| 36 |
|
| 37 |
— *end example*]
|
| 38 |
|
|
|
|
| 1 |
#### Overview <a id="range.take.overview">[[range.take.overview]]</a>
|
| 2 |
|
| 3 |
+
`take_view` produces a view of the first N elements from another view,
|
| 4 |
+
or all the elements if the adapted view contains fewer than N.
|
| 5 |
|
| 6 |
The name `views::take` denotes a range adaptor object
|
| 7 |
[[range.adaptor.object]]. Let `E` and `F` be expressions, let `T` be
|
| 8 |
`remove_cvref_t<decltype((E))>`, and let `D` be
|
| 9 |
`range_difference_t<decltype((E))>`. If `decltype((F))` does not model
|
| 10 |
`convertible_to<D>`, `views::take(E, F)` is ill-formed. Otherwise, the
|
| 11 |
expression `views::take(E, F)` is expression-equivalent to:
|
| 12 |
|
| 13 |
+
- If `T` is a specialization of `empty_view` [[range.empty.view]], then
|
| 14 |
+
`((void)F, decay-copy(E))`, except that the evaluations of `E` and `F`
|
| 15 |
+
are indeterminately sequenced.
|
| 16 |
- Otherwise, if `T` models `random_access_range` and `sized_range` and
|
| 17 |
+
is a specialization of `span` [[views.span]], `basic_string_view`
|
| 18 |
+
[[string.view]], or `subrange` [[range.subrange]], then
|
| 19 |
+
`U(ranges::begin(E),
|
| 20 |
+
ranges::begin(E) + std::min<D>(ranges::distance(E), F))`, except that
|
| 21 |
+
`E` is evaluated only once, where `U` is a type determined as follows:
|
| 22 |
+
- if `T` is a specialization of `span`, then `U` is
|
| 23 |
+
`span<typename T::element_type>`;
|
| 24 |
+
- otherwise, if `T` is a specialization of `basic_string_view`, then
|
| 25 |
+
`U` is `T`;
|
| 26 |
+
- otherwise, `T` is a specialization of `subrange`, and `U` is
|
| 27 |
+
`subrange<iterator_t<T>>`;
|
| 28 |
+
- otherwise, if `T` is a specialization of `iota_view`
|
| 29 |
+
[[range.iota.view]] that models `random_access_range` and
|
| 30 |
+
`sized_range`, then `iota_view(*ranges::begin(E),
|
| 31 |
+
*(ranges::begin(E) + std::{}min<D>(ranges::distance(E), F)))`, except
|
| 32 |
+
that `E` is evaluated only once.
|
| 33 |
+
- Otherwise, if `T` is a specialization of `repeat_view`
|
| 34 |
+
[[range.repeat.view]]:
|
| 35 |
+
- if `T` models `sized_range`, then
|
| 36 |
+
``` cpp
|
| 37 |
+
views::repeat(*E.value_, std::min<D>(ranges::distance(E), F))
|
| 38 |
+
```
|
| 39 |
|
| 40 |
+
except that `E` is evaluated only once;
|
| 41 |
+
- otherwise, `views::repeat(*E.value_, static_cast<D>(F))`.
|
| 42 |
+
- Otherwise, `take_view(E, F)`.
|
|
|
|
| 43 |
|
| 44 |
[*Example 1*:
|
| 45 |
|
| 46 |
``` cpp
|
| 47 |
vector<int> is{0,1,2,3,4,5,6,7,8,9};
|
| 48 |
+
for (int i : is | views::take(5))
|
| 49 |
+
cout << i << ' '; // prints 0 1 2 3 4
|
|
|
|
| 50 |
```
|
| 51 |
|
| 52 |
— *end example*]
|
| 53 |
|