tmp/tmpv18u6o9l/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,130 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Take while view <a id="range.take.while">[[range.take.while]]</a>
|
| 2 |
+
|
| 3 |
+
#### Overview <a id="range.take.while.overview">[[range.take.while.overview]]</a>
|
| 4 |
+
|
| 5 |
+
Given a unary predicate `pred` and a `view` `r`, `take_while_view`
|
| 6 |
+
produces a `view` of the range \[`begin(r)`,
|
| 7 |
+
`ranges::find_if_not(r, pred)`).
|
| 8 |
+
|
| 9 |
+
The name `views::take_while` denotes a range adaptor object
|
| 10 |
+
[[range.adaptor.object]]. Given subexpressions `E` and `F`, the
|
| 11 |
+
expression `views::take_while(E, F)` is expression-equivalent to
|
| 12 |
+
`take_while_view{E, F}`.
|
| 13 |
+
|
| 14 |
+
[*Example 1*:
|
| 15 |
+
|
| 16 |
+
``` cpp
|
| 17 |
+
auto input = istringstream{"0 1 2 3 4 5 6 7 8 9"};
|
| 18 |
+
auto small = [](const auto x) noexcept { return x < 5; };
|
| 19 |
+
auto small_ints = istream_view<int>(input) | views::take_while(small);
|
| 20 |
+
for (const auto i : small_ints) {
|
| 21 |
+
cout << i << ' '; // prints 0 1 2 3 4
|
| 22 |
+
}
|
| 23 |
+
auto i = 0;
|
| 24 |
+
input >> i;
|
| 25 |
+
cout << i; // prints 6
|
| 26 |
+
```
|
| 27 |
+
|
| 28 |
+
— *end example*]
|
| 29 |
+
|
| 30 |
+
#### Class template `take_while_view` <a id="range.take.while.view">[[range.take.while.view]]</a>
|
| 31 |
+
|
| 32 |
+
``` cpp
|
| 33 |
+
namespace std::ranges {
|
| 34 |
+
template<view V, class Pred>
|
| 35 |
+
requires input_range<V> && is_object_v<Pred> &&
|
| 36 |
+
indirect_unary_predicate<const Pred, iterator_t<V>>
|
| 37 |
+
class take_while_view : public view_interface<take_while_view<V, Pred>> {
|
| 38 |
+
// [range.take.while.sentinel], class template take_while_view::sentinel
|
| 39 |
+
template<bool> class sentinel; // exposition only
|
| 40 |
+
|
| 41 |
+
V base_ = V(); // exposition only
|
| 42 |
+
semiregular-box<Pred> pred_; // exposition only
|
| 43 |
+
|
| 44 |
+
public:
|
| 45 |
+
take_while_view() = default;
|
| 46 |
+
constexpr take_while_view(V base, Pred pred);
|
| 47 |
+
|
| 48 |
+
constexpr V base() const& requires copy_constructible<V> { return base_; }
|
| 49 |
+
constexpr V base() && { return std::move(base_); }
|
| 50 |
+
|
| 51 |
+
constexpr const Pred& pred() const;
|
| 52 |
+
|
| 53 |
+
constexpr auto begin() requires (!simple-view<V>)
|
| 54 |
+
{ return ranges::begin(base_); }
|
| 55 |
+
|
| 56 |
+
constexpr auto begin() const requires range<const V>
|
| 57 |
+
{ return ranges::begin(base_); }
|
| 58 |
+
|
| 59 |
+
constexpr auto end() requires (!simple-view<V>)
|
| 60 |
+
{ return sentinel<false>(ranges::end(base_), addressof(*pred_)); }
|
| 61 |
+
|
| 62 |
+
constexpr auto end() const requires range<const V>
|
| 63 |
+
{ return sentinel<true>(ranges::end(base_), addressof(*pred_)); }
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
template<class R, class Pred>
|
| 67 |
+
take_while_view(R&&, Pred) -> take_while_view<views::all_t<R>, Pred>;
|
| 68 |
+
}
|
| 69 |
+
```
|
| 70 |
+
|
| 71 |
+
``` cpp
|
| 72 |
+
constexpr take_while_view(V base, Pred pred);
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
*Effects:* Initializes *base\_* with `std::move(base)` and *pred\_* with
|
| 76 |
+
`std::move(pred)`.
|
| 77 |
+
|
| 78 |
+
``` cpp
|
| 79 |
+
constexpr const Pred& pred() const;
|
| 80 |
+
```
|
| 81 |
+
|
| 82 |
+
*Effects:* Equivalent to: `return *`*`pred_`*`;`
|
| 83 |
+
|
| 84 |
+
#### Class template `take_while_view::sentinel` <a id="range.take.while.sentinel">[[range.take.while.sentinel]]</a>
|
| 85 |
+
|
| 86 |
+
``` cpp
|
| 87 |
+
namespace std::ranges {
|
| 88 |
+
template<view V, class Pred>
|
| 89 |
+
requires input_range<V> && is_object_v<Pred> &&
|
| 90 |
+
indirect_unary_predicate<const Pred, iterator_t<V>>
|
| 91 |
+
template<bool Const>
|
| 92 |
+
class take_while_view<V, Pred>::sentinel { // exposition only
|
| 93 |
+
using Base = conditional_t<Const, const V, V>; // exposition only
|
| 94 |
+
|
| 95 |
+
sentinel_t<Base> end_ = sentinel_t<Base>(); // exposition only
|
| 96 |
+
const Pred* pred_ = nullptr; // exposition only
|
| 97 |
+
public:
|
| 98 |
+
sentinel() = default;
|
| 99 |
+
constexpr explicit sentinel(sentinel_t<Base> end, const Pred* pred);
|
| 100 |
+
constexpr sentinel(sentinel<!Const> s)
|
| 101 |
+
requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
|
| 102 |
+
|
| 103 |
+
constexpr sentinel_t<Base> base() const { return end_; }
|
| 104 |
+
|
| 105 |
+
friend constexpr bool operator==(const iterator_t<Base>& x, const sentinel& y);
|
| 106 |
+
};
|
| 107 |
+
}
|
| 108 |
+
```
|
| 109 |
+
|
| 110 |
+
``` cpp
|
| 111 |
+
constexpr explicit sentinel(sentinel_t<Base> end, const Pred* pred);
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
*Effects:* Initializes *end\_* with `end` and *pred\_* with `pred`.
|
| 115 |
+
|
| 116 |
+
``` cpp
|
| 117 |
+
constexpr sentinel(sentinel<!Const> s)
|
| 118 |
+
requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
|
| 119 |
+
```
|
| 120 |
+
|
| 121 |
+
*Effects:* Initializes *end\_* with `s.`*`end_`* and *pred\_* with
|
| 122 |
+
`s.`*`pred_`*.
|
| 123 |
+
|
| 124 |
+
``` cpp
|
| 125 |
+
friend constexpr bool operator==(const iterator_t<Base>& x, const sentinel& y);
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
*Effects:* Equivalent to:
|
| 129 |
+
`return y.`*`end_`*` == x || !invoke(*y.`*`pred_`*`, *x);`
|
| 130 |
+
|