From Jason Turner

[range.drop]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp10z6vhai/{from.md → to.md} +120 -0
tmp/tmp10z6vhai/{from.md → to.md} RENAMED
@@ -0,0 +1,120 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Drop view <a id="range.drop">[[range.drop]]</a>
2
+
3
+ #### Overview <a id="range.drop.overview">[[range.drop.overview]]</a>
4
+
5
+ `drop_view` produces a `view` excluding the first N elements from
6
+ another `view`, or an empty range if the adapted `view` contains fewer
7
+ than N elements.
8
+
9
+ The name `views::drop` denotes a range adaptor object
10
+ [[range.adaptor.object]]. Let `E` and `F` be expressions, let `T` be
11
+ `remove_cvref_t<decltype((E))>`, and let `D` be
12
+ `range_difference_t<decltype((E))>`. If `decltype((F))` does not model
13
+ `convertible_to<D>`, `views::drop(E, F)` is ill-formed. Otherwise, the
14
+ expression `views::drop(E, F)` is expression-equivalent to:
15
+
16
+ - If `T` is a specialization of `ranges::empty_view`
17
+ [[range.empty.view]], then `((void) F, decay-copy(E))`.
18
+ - Otherwise, if `T` models `random_access_range` and `sized_range` and
19
+ is
20
+ - a specialization of `span` [[views.span]] where
21
+ `T::extent == dynamic_extent`,
22
+ - a specialization of `basic_string_view` [[string.view]],
23
+ - a specialization of `ranges::iota_view` [[range.iota.view]], or
24
+ - a specialization of `ranges::subrange` [[range.subrange]],
25
+
26
+ then
27
+ `T{ranges::begin(E) + min<D>(ranges::size(E), F), ranges::end(E)}`,
28
+ except that `E` is evaluated only once.
29
+ - Otherwise, `ranges::drop_view{E, F}`.
30
+
31
+ [*Example 1*:
32
+
33
+ ``` cpp
34
+ auto ints = views::iota(0) | views::take(10);
35
+ auto latter_half = drop_view{ints, 5};
36
+ for (auto i : latter_half) {
37
+ cout << i << ' '; // prints 5 6 7 8 9
38
+ }
39
+ ```
40
+
41
+ — *end example*]
42
+
43
+ #### Class template `drop_view` <a id="range.drop.view">[[range.drop.view]]</a>
44
+
45
+ ``` cpp
46
+ namespace std::ranges {
47
+ template<view V>
48
+ class drop_view : public view_interface<drop_view<V>> {
49
+ public:
50
+ drop_view() = default;
51
+ constexpr drop_view(V base, range_difference_t<V> count);
52
+
53
+ constexpr V base() const& requires copy_constructible<V> { return base_; }
54
+ constexpr V base() && { return std::move(base_); }
55
+
56
+ constexpr auto begin()
57
+ requires (!(simple-view<V> && random_access_range<V>));
58
+ constexpr auto begin() const
59
+ requires random_access_range<const V>;
60
+
61
+ constexpr auto end()
62
+ requires (!simple-view<V>)
63
+ { return ranges::end(base_); }
64
+
65
+ constexpr auto end() const
66
+ requires range<const V>
67
+ { return ranges::end(base_); }
68
+
69
+ constexpr auto size()
70
+ requires sized_range<V>
71
+ {
72
+ const auto s = ranges::size(base_);
73
+ const auto c = static_cast<decltype(s)>(count_);
74
+ return s < c ? 0 : s - c;
75
+ }
76
+
77
+ constexpr auto size() const
78
+ requires sized_range<const V>
79
+ {
80
+ const auto s = ranges::size(base_);
81
+ const auto c = static_cast<decltype(s)>(count_);
82
+ return s < c ? 0 : s - c;
83
+ }
84
+ private:
85
+ V base_ = V(); // exposition only
86
+ range_difference_t<V> count_ = 0; // exposition only
87
+ };
88
+
89
+ template<class R>
90
+ drop_view(R&&, range_difference_t<R>) -> drop_view<views::all_t<R>>;
91
+ }
92
+ ```
93
+
94
+ ``` cpp
95
+ constexpr drop_view(V base, range_difference_t<V> count);
96
+ ```
97
+
98
+ *Preconditions:* `count >= 0` is `true`.
99
+
100
+ *Effects:* Initializes *base\_* with `std::move(base)` and *count\_*
101
+ with `count`.
102
+
103
+ ``` cpp
104
+ constexpr auto begin()
105
+ requires (!(simple-view<V> && random_access_range<V>));
106
+ constexpr auto begin() const
107
+ requires random_access_range<const V>;
108
+ ```
109
+
110
+ *Returns:*
111
+ `ranges::next(ranges::begin(base_), count_, ranges::end(base_))`.
112
+
113
+ *Remarks:* In order to provide the amortized constant-time complexity
114
+ required by the `range` concept when `drop_view` models `forward_range`,
115
+ the first overload caches the result within the `drop_view` for use on
116
+ subsequent calls.
117
+
118
+ [*Note 1*: Without this, applying a `reverse_view` over a `drop_view`
119
+ would have quadratic iteration complexity. — *end note*]
120
+