tmp/tmprztumwls/{from.md → to.md}
RENAMED
|
@@ -1,24 +1,24 @@
|
|
| 1 |
### Filter view <a id="range.filter">[[range.filter]]</a>
|
| 2 |
|
| 3 |
#### Overview <a id="range.filter.overview">[[range.filter.overview]]</a>
|
| 4 |
|
| 5 |
-
`filter_view` presents a
|
| 6 |
-
|
| 7 |
|
| 8 |
The name `views::filter` denotes a range adaptor object
|
| 9 |
[[range.adaptor.object]]. Given subexpressions `E` and `P`, the
|
| 10 |
expression `views::filter(E, P)` is expression-equivalent to
|
| 11 |
-
`filter_view
|
| 12 |
|
| 13 |
[*Example 1*:
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
vector<int> is{ 0, 1, 2, 3, 4, 5, 6 };
|
| 17 |
-
|
| 18 |
for (int i : evens)
|
| 19 |
-
cout << i << ' '; // prints
|
| 20 |
```
|
| 21 |
|
| 22 |
— *end example*]
|
| 23 |
|
| 24 |
#### Class template `filter_view` <a id="range.filter.view">[[range.filter.view]]</a>
|
|
@@ -28,20 +28,21 @@ namespace std::ranges {
|
|
| 28 |
template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
|
| 29 |
requires view<V> && is_object_v<Pred>
|
| 30 |
class filter_view : public view_interface<filter_view<V, Pred>> {
|
| 31 |
private:
|
| 32 |
V base_ = V(); // exposition only
|
| 33 |
-
|
| 34 |
|
| 35 |
// [range.filter.iterator], class filter_view::iterator
|
| 36 |
class iterator; // exposition only
|
|
|
|
| 37 |
// [range.filter.sentinel], class filter_view::sentinel
|
| 38 |
class sentinel; // exposition only
|
| 39 |
|
| 40 |
public:
|
| 41 |
-
filter_view() = default;
|
| 42 |
-
constexpr filter_view(V base, Pred pred);
|
| 43 |
|
| 44 |
constexpr V base() const & requires copy_constructible<V> { return base_; }
|
| 45 |
constexpr V base() && { return std::move(base_); }
|
| 46 |
|
| 47 |
constexpr const Pred& pred() const;
|
|
@@ -59,11 +60,11 @@ namespace std::ranges {
|
|
| 59 |
filter_view(R&&, Pred) -> filter_view<views::all_t<R>, Pred>;
|
| 60 |
}
|
| 61 |
```
|
| 62 |
|
| 63 |
``` cpp
|
| 64 |
-
constexpr filter_view(V base, Pred pred);
|
| 65 |
```
|
| 66 |
|
| 67 |
*Effects:* Initializes *base\_* with `std::move(base)` and initializes
|
| 68 |
*pred\_* with `std::move(pred)`.
|
| 69 |
|
|
@@ -75,11 +76,11 @@ constexpr const Pred& pred() const;
|
|
| 75 |
|
| 76 |
``` cpp
|
| 77 |
constexpr iterator begin();
|
| 78 |
```
|
| 79 |
|
| 80 |
-
*Preconditions:* `pred_.has_value()`.
|
| 81 |
|
| 82 |
*Returns:* `{*this, ranges::find_if(`*`base_`*`, ref(*`*`pred_`*`))}`.
|
| 83 |
|
| 84 |
*Remarks:* In order to provide the amortized constant time complexity
|
| 85 |
required by the `range` concept when `filter_view` models
|
|
@@ -94,21 +95,21 @@ namespace std::ranges {
|
|
| 94 |
requires view<V> && is_object_v<Pred>
|
| 95 |
class filter_view<V, Pred>::iterator {
|
| 96 |
private:
|
| 97 |
iterator_t<V> current_ = iterator_t<V>(); // exposition only
|
| 98 |
filter_view* parent_ = nullptr; // exposition only
|
|
|
|
| 99 |
public:
|
| 100 |
-
using iterator_concept = see
|
| 101 |
-
using iterator_category = see
|
| 102 |
using value_type = range_value_t<V>;
|
| 103 |
using difference_type = range_difference_t<V>;
|
| 104 |
|
| 105 |
-
iterator() = default;
|
| 106 |
constexpr iterator(filter_view& parent, iterator_t<V> current);
|
| 107 |
|
| 108 |
-
constexpr iterator_t<V> base() const &
|
| 109 |
-
requires copyable<iterator_t<V>>;
|
| 110 |
constexpr iterator_t<V> base() &&;
|
| 111 |
constexpr range_reference_t<V> operator*() const;
|
| 112 |
constexpr iterator_t<V> operator->() const
|
| 113 |
requires has-arrow<iterator_t<V>> && copyable<iterator_t<V>>;
|
| 114 |
|
|
@@ -122,10 +123,11 @@ namespace std::ranges {
|
|
| 122 |
friend constexpr bool operator==(const iterator& x, const iterator& y)
|
| 123 |
requires equality_comparable<iterator_t<V>>;
|
| 124 |
|
| 125 |
friend constexpr range_rvalue_reference_t<V> iter_move(const iterator& i)
|
| 126 |
noexcept(noexcept(ranges::iter_move(i.current_)));
|
|
|
|
| 127 |
friend constexpr void iter_swap(const iterator& x, const iterator& y)
|
| 128 |
noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
|
| 129 |
requires indirectly_swappable<iterator_t<V>>;
|
| 130 |
};
|
| 131 |
}
|
|
@@ -141,11 +143,13 @@ not satisfy the filter predicate.
|
|
| 141 |
`bidirectional_iterator_tag`.
|
| 142 |
- Otherwise, if `V` models `forward_range`, then `iterator_concept`
|
| 143 |
denotes `forward_iterator_tag`.
|
| 144 |
- Otherwise, `iterator_concept` denotes `input_iterator_tag`.
|
| 145 |
|
| 146 |
-
`
|
|
|
|
|
|
|
| 147 |
|
| 148 |
- Let `C` denote the type
|
| 149 |
`iterator_traits<iterator_t<V>>::iterator_category`.
|
| 150 |
- If `C` models `derived_from<bidirectional_iterator_tag>`, then
|
| 151 |
`iterator_category` denotes `bidirectional_iterator_tag`.
|
|
@@ -159,21 +163,20 @@ constexpr iterator(filter_view& parent, iterator_t<V> current);
|
|
| 159 |
|
| 160 |
*Effects:* Initializes *current\_* with `std::move(current)` and
|
| 161 |
*parent\_* with `addressof(parent)`.
|
| 162 |
|
| 163 |
``` cpp
|
| 164 |
-
constexpr iterator_t<V> base() const &
|
| 165 |
-
requires copyable<iterator_t<V>>;
|
| 166 |
```
|
| 167 |
|
| 168 |
*Effects:* Equivalent to: `return `*`current_`*`;`
|
| 169 |
|
| 170 |
``` cpp
|
| 171 |
constexpr iterator_t<V> base() &&;
|
| 172 |
```
|
| 173 |
|
| 174 |
-
*Effects:* Equivalent to: `return std::move(current_);`
|
| 175 |
|
| 176 |
``` cpp
|
| 177 |
constexpr range_reference_t<V> operator*() const;
|
| 178 |
```
|
| 179 |
|
|
@@ -271,10 +274,11 @@ namespace std::ranges {
|
|
| 271 |
template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
|
| 272 |
requires view<V> && is_object_v<Pred>
|
| 273 |
class filter_view<V, Pred>::sentinel {
|
| 274 |
private:
|
| 275 |
sentinel_t<V> end_ = sentinel_t<V>(); // exposition only
|
|
|
|
| 276 |
public:
|
| 277 |
sentinel() = default;
|
| 278 |
constexpr explicit sentinel(filter_view& parent);
|
| 279 |
|
| 280 |
constexpr sentinel_t<V> base() const;
|
|
|
|
| 1 |
### Filter view <a id="range.filter">[[range.filter]]</a>
|
| 2 |
|
| 3 |
#### Overview <a id="range.filter.overview">[[range.filter.overview]]</a>
|
| 4 |
|
| 5 |
+
`filter_view` presents a view of the elements of an underlying sequence
|
| 6 |
+
that satisfy a predicate.
|
| 7 |
|
| 8 |
The name `views::filter` denotes a range adaptor object
|
| 9 |
[[range.adaptor.object]]. Given subexpressions `E` and `P`, the
|
| 10 |
expression `views::filter(E, P)` is expression-equivalent to
|
| 11 |
+
`filter_view(E, P)`.
|
| 12 |
|
| 13 |
[*Example 1*:
|
| 14 |
|
| 15 |
``` cpp
|
| 16 |
vector<int> is{ 0, 1, 2, 3, 4, 5, 6 };
|
| 17 |
+
auto evens = views::filter(is, [](int i) { return 0 == i % 2; });
|
| 18 |
for (int i : evens)
|
| 19 |
+
cout << i << ' '; // prints 0 2 4 6
|
| 20 |
```
|
| 21 |
|
| 22 |
— *end example*]
|
| 23 |
|
| 24 |
#### Class template `filter_view` <a id="range.filter.view">[[range.filter.view]]</a>
|
|
|
|
| 28 |
template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
|
| 29 |
requires view<V> && is_object_v<Pred>
|
| 30 |
class filter_view : public view_interface<filter_view<V, Pred>> {
|
| 31 |
private:
|
| 32 |
V base_ = V(); // exposition only
|
| 33 |
+
movable-box<Pred> pred_; // exposition only
|
| 34 |
|
| 35 |
// [range.filter.iterator], class filter_view::iterator
|
| 36 |
class iterator; // exposition only
|
| 37 |
+
|
| 38 |
// [range.filter.sentinel], class filter_view::sentinel
|
| 39 |
class sentinel; // exposition only
|
| 40 |
|
| 41 |
public:
|
| 42 |
+
filter_view() requires default_initializable<V> && default_initializable<Pred> = default;
|
| 43 |
+
constexpr explicit filter_view(V base, Pred pred);
|
| 44 |
|
| 45 |
constexpr V base() const & requires copy_constructible<V> { return base_; }
|
| 46 |
constexpr V base() && { return std::move(base_); }
|
| 47 |
|
| 48 |
constexpr const Pred& pred() const;
|
|
|
|
| 60 |
filter_view(R&&, Pred) -> filter_view<views::all_t<R>, Pred>;
|
| 61 |
}
|
| 62 |
```
|
| 63 |
|
| 64 |
``` cpp
|
| 65 |
+
constexpr explicit filter_view(V base, Pred pred);
|
| 66 |
```
|
| 67 |
|
| 68 |
*Effects:* Initializes *base\_* with `std::move(base)` and initializes
|
| 69 |
*pred\_* with `std::move(pred)`.
|
| 70 |
|
|
|
|
| 76 |
|
| 77 |
``` cpp
|
| 78 |
constexpr iterator begin();
|
| 79 |
```
|
| 80 |
|
| 81 |
+
*Preconditions:* *`pred_`*`.has_value()` is `true`.
|
| 82 |
|
| 83 |
*Returns:* `{*this, ranges::find_if(`*`base_`*`, ref(*`*`pred_`*`))}`.
|
| 84 |
|
| 85 |
*Remarks:* In order to provide the amortized constant time complexity
|
| 86 |
required by the `range` concept when `filter_view` models
|
|
|
|
| 95 |
requires view<V> && is_object_v<Pred>
|
| 96 |
class filter_view<V, Pred>::iterator {
|
| 97 |
private:
|
| 98 |
iterator_t<V> current_ = iterator_t<V>(); // exposition only
|
| 99 |
filter_view* parent_ = nullptr; // exposition only
|
| 100 |
+
|
| 101 |
public:
|
| 102 |
+
using iterator_concept = see belownc;
|
| 103 |
+
using iterator_category = see belownc; // not always present
|
| 104 |
using value_type = range_value_t<V>;
|
| 105 |
using difference_type = range_difference_t<V>;
|
| 106 |
|
| 107 |
+
iterator() requires default_initializable<iterator_t<V>> = default;
|
| 108 |
constexpr iterator(filter_view& parent, iterator_t<V> current);
|
| 109 |
|
| 110 |
+
constexpr const iterator_t<V>& base() const & noexcept;
|
|
|
|
| 111 |
constexpr iterator_t<V> base() &&;
|
| 112 |
constexpr range_reference_t<V> operator*() const;
|
| 113 |
constexpr iterator_t<V> operator->() const
|
| 114 |
requires has-arrow<iterator_t<V>> && copyable<iterator_t<V>>;
|
| 115 |
|
|
|
|
| 123 |
friend constexpr bool operator==(const iterator& x, const iterator& y)
|
| 124 |
requires equality_comparable<iterator_t<V>>;
|
| 125 |
|
| 126 |
friend constexpr range_rvalue_reference_t<V> iter_move(const iterator& i)
|
| 127 |
noexcept(noexcept(ranges::iter_move(i.current_)));
|
| 128 |
+
|
| 129 |
friend constexpr void iter_swap(const iterator& x, const iterator& y)
|
| 130 |
noexcept(noexcept(ranges::iter_swap(x.current_, y.current_)))
|
| 131 |
requires indirectly_swappable<iterator_t<V>>;
|
| 132 |
};
|
| 133 |
}
|
|
|
|
| 143 |
`bidirectional_iterator_tag`.
|
| 144 |
- Otherwise, if `V` models `forward_range`, then `iterator_concept`
|
| 145 |
denotes `forward_iterator_tag`.
|
| 146 |
- Otherwise, `iterator_concept` denotes `input_iterator_tag`.
|
| 147 |
|
| 148 |
+
The member *typedef-name* `iterator_category` is defined if and only if
|
| 149 |
+
`V` models `forward_range`. In that case, `iterator::iterator_category`
|
| 150 |
+
is defined as follows:
|
| 151 |
|
| 152 |
- Let `C` denote the type
|
| 153 |
`iterator_traits<iterator_t<V>>::iterator_category`.
|
| 154 |
- If `C` models `derived_from<bidirectional_iterator_tag>`, then
|
| 155 |
`iterator_category` denotes `bidirectional_iterator_tag`.
|
|
|
|
| 163 |
|
| 164 |
*Effects:* Initializes *current\_* with `std::move(current)` and
|
| 165 |
*parent\_* with `addressof(parent)`.
|
| 166 |
|
| 167 |
``` cpp
|
| 168 |
+
constexpr const iterator_t<V>& base() const & noexcept;
|
|
|
|
| 169 |
```
|
| 170 |
|
| 171 |
*Effects:* Equivalent to: `return `*`current_`*`;`
|
| 172 |
|
| 173 |
``` cpp
|
| 174 |
constexpr iterator_t<V> base() &&;
|
| 175 |
```
|
| 176 |
|
| 177 |
+
*Effects:* Equivalent to: `return std::move(`*`current_`*`);`
|
| 178 |
|
| 179 |
``` cpp
|
| 180 |
constexpr range_reference_t<V> operator*() const;
|
| 181 |
```
|
| 182 |
|
|
|
|
| 274 |
template<input_range V, indirect_unary_predicate<iterator_t<V>> Pred>
|
| 275 |
requires view<V> && is_object_v<Pred>
|
| 276 |
class filter_view<V, Pred>::sentinel {
|
| 277 |
private:
|
| 278 |
sentinel_t<V> end_ = sentinel_t<V>(); // exposition only
|
| 279 |
+
|
| 280 |
public:
|
| 281 |
sentinel() = default;
|
| 282 |
constexpr explicit sentinel(filter_view& parent);
|
| 283 |
|
| 284 |
constexpr sentinel_t<V> base() const;
|