From Jason Turner

[range.take.overview]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpzupw04g2/{from.md → to.md} +38 -0
tmp/tmpzupw04g2/{from.md → to.md} RENAMED
@@ -0,0 +1,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
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
+