From Jason Turner

[range.take.while]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpusho_fzr/{from.md → to.md} +29 -14
tmp/tmpusho_fzr/{from.md → to.md} RENAMED
@@ -1,24 +1,24 @@
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;
@@ -37,41 +37,45 @@ namespace std::ranges {
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
 
@@ -87,24 +91,30 @@ constexpr const Pred& pred() const;
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
@@ -116,15 +126,20 @@ constexpr explicit sentinel(sentinel_t<Base> end, const Pred* pred);
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
 
 
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 \[`ranges::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 = views::istream<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;
 
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
+ movable-box<Pred> pred_; // exposition only
43
 
44
  public:
45
+ take_while_view() requires default_initializable<V> && default_initializable<Pred> = default;
46
+ constexpr explicit 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
57
+ requires range<const V> &&
58
+ indirect_unary_predicate<const Pred, iterator_t<const V>>
59
  { return ranges::begin(base_); }
60
 
61
  constexpr auto end() requires (!simple-view<V>)
62
  { return sentinel<false>(ranges::end(base_), addressof(*pred_)); }
63
 
64
+ constexpr auto end() const
65
+ requires range<const V> &&
66
+ indirect_unary_predicate<const Pred, iterator_t<const V>>
67
  { return sentinel<true>(ranges::end(base_), addressof(*pred_)); }
68
  };
69
 
70
  template<class R, class Pred>
71
  take_while_view(R&&, Pred) -> take_while_view<views::all_t<R>, Pred>;
72
  }
73
  ```
74
 
75
  ``` cpp
76
+ constexpr explicit take_while_view(V base, Pred pred);
77
  ```
78
 
79
  *Effects:* Initializes *base\_* with `std::move(base)` and *pred\_* with
80
  `std::move(pred)`.
81
 
 
91
  namespace std::ranges {
92
  template<view V, class Pred>
93
  requires input_range<V> && is_object_v<Pred> &&
94
  indirect_unary_predicate<const Pred, iterator_t<V>>
95
  template<bool Const>
96
+ class take_while_view<V, Pred>::sentinel {
97
+ using Base = maybe-const<Const, V>; // exposition only
98
 
99
  sentinel_t<Base> end_ = sentinel_t<Base>(); // exposition only
100
  const Pred* pred_ = nullptr; // exposition only
101
+
102
  public:
103
  sentinel() = default;
104
  constexpr explicit sentinel(sentinel_t<Base> end, const Pred* pred);
105
  constexpr sentinel(sentinel<!Const> s)
106
  requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
107
 
108
  constexpr sentinel_t<Base> base() const { return end_; }
109
 
110
  friend constexpr bool operator==(const iterator_t<Base>& x, const sentinel& y);
111
+
112
+ template<bool OtherConst = !Const>
113
+ requires sentinel_for<sentinel_t<Base>, iterator_t<maybe-const<OtherConst, V>>>
114
+ friend constexpr bool operator==(const iterator_t<maybe-const<OtherConst, V>>& x,
115
+ const sentinel& y);
116
  };
117
  }
118
  ```
119
 
120
  ``` cpp
 
126
  ``` cpp
127
  constexpr sentinel(sentinel<!Const> s)
128
  requires Const && convertible_to<sentinel_t<V>, sentinel_t<Base>>;
129
  ```
130
 
131
+ *Effects:* Initializes *end\_* with `std::move(s.`*`end_`*`)` and
132
+ *pred\_* with `s.`*`pred_`*.
133
 
134
  ``` cpp
135
  friend constexpr bool operator==(const iterator_t<Base>& x, const sentinel& y);
136
+
137
+ template<bool OtherConst = !Const>
138
+ requires sentinel_for<sentinel_t<Base>, iterator_t<maybe-const<OtherConst, V>>>
139
+ friend constexpr bool operator==(const iterator_t<maybe-const<OtherConst, V>>& x,
140
+ const sentinel& y);
141
  ```
142
 
143
  *Effects:* Equivalent to:
144
  `return y.`*`end_`*` == x || !invoke(*y.`*`pred_`*`, *x);`
145