From Jason Turner

[range.take.overview]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpr5_xluuy/{from.md → to.md} +32 -17
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 `view` of the first N elements from another
4
- `view`, 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 `ranges::empty_view`
14
- [[range.empty.view]], then `((void) F, decay-copy(E))`.
 
15
  - Otherwise, if `T` models `random_access_range` and `sized_range` and
16
- is
17
- - a specialization of `span` [[views.span]] where
18
- `T::extent == dynamic_extent`,
19
- - a specialization of `basic_string_view` [[string.view]],
20
- - a specialization of `ranges::iota_view` [[range.iota.view]], or
21
- - a specialization of `ranges::subrange` [[range.subrange]],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
- then
24
- `T{ranges::begin(E), ranges::begin(E) + min<D>(ranges::size(E), F)}`,
25
- except that `E` is evaluated only once.
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
- take_view few{is, 5};
33
- for (int i : few)
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