From Jason Turner

[range.drop.while]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmp2w5it085/{from.md → to.md} +86 -0
tmp/tmp2w5it085/{from.md → to.md} RENAMED
@@ -0,0 +1,86 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### Drop while view <a id="range.drop.while">[[range.drop.while]]</a>
2
+
3
+ #### Overview <a id="range.drop.while.overview">[[range.drop.while.overview]]</a>
4
+
5
+ Given a unary predicate `pred` and a `view` `r`, `drop_while_view`
6
+ produces a `view` of the range \[`ranges::find_if_not(r, pred)`,
7
+ `ranges::end(r)`).
8
+
9
+ The name `views::drop_while` denotes a range adaptor object
10
+ [[range.adaptor.object]]. Given subexpressions `E` and `F`, the
11
+ expression `views::drop_while(E, F)` is expression-equivalent to
12
+ `drop_while_view{E, F}`.
13
+
14
+ [*Example 1*:
15
+
16
+ ``` cpp
17
+ constexpr auto source = " \t \t \t hello there";
18
+ auto is_invisible = [](const auto x) { return x == ' ' || x == '\t'; };
19
+ auto skip_ws = drop_while_view{source, is_invisible};
20
+ for (auto c : skip_ws) {
21
+ cout << c; // prints hello there with no leading space
22
+ }
23
+ ```
24
+
25
+ — *end example*]
26
+
27
+ #### Class template `drop_while_view` <a id="range.drop.while.view">[[range.drop.while.view]]</a>
28
+
29
+ ``` cpp
30
+ namespace std::ranges {
31
+ template<view V, class Pred>
32
+ requires input_range<V> && is_object_v<Pred> &&
33
+ indirect_unary_predicate<const Pred, iterator_t<V>>
34
+ class drop_while_view : public view_interface<drop_while_view<V, Pred>> {
35
+ public:
36
+ drop_while_view() = default;
37
+ constexpr drop_while_view(V base, Pred pred);
38
+
39
+ constexpr V base() const& requires copy_constructible<V> { return base_; }
40
+ constexpr V base() && { return std::move(base_); }
41
+
42
+ constexpr const Pred& pred() const;
43
+
44
+ constexpr auto begin();
45
+
46
+ constexpr auto end()
47
+ { return ranges::end(base_); }
48
+
49
+ private:
50
+ V base_ = V(); // exposition only
51
+ semiregular-box<Pred> pred_; // exposition only
52
+ };
53
+
54
+ template<class R, class Pred>
55
+ drop_while_view(R&&, Pred) -> drop_while_view<views::all_t<R>, Pred>;
56
+ }
57
+ ```
58
+
59
+ ``` cpp
60
+ constexpr drop_while_view(V base, Pred pred);
61
+ ```
62
+
63
+ *Effects:* Initializes *base\_* with `std::move(base)` and *pred\_* with
64
+ `std::move(pred)`.
65
+
66
+ ``` cpp
67
+ constexpr const Pred& pred() const;
68
+ ```
69
+
70
+ *Effects:* Equivalent to: `return *`*`pred_`*`;`
71
+
72
+ ``` cpp
73
+ constexpr auto begin();
74
+ ```
75
+
76
+ *Returns:* `ranges::find_if_not(base_, cref(*pred_))`.
77
+
78
+ *Remarks:* In order to provide the amortized constant-time complexity
79
+ required by the `range` concept when `drop_while_view` models
80
+ `forward_range`, the first call caches the result within the
81
+ `drop_while_view` for use on subsequent calls.
82
+
83
+ [*Note 1*: Without this, applying a `reverse_view` over a
84
+ `drop_while_view` would have quadratic iteration
85
+ complexity. — *end note*]
86
+