tmp/tmphxvmf82s/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,113 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### Common view <a id="range.common">[[range.common]]</a>
|
| 2 |
+
|
| 3 |
+
#### Overview <a id="range.common.overview">[[range.common.overview]]</a>
|
| 4 |
+
|
| 5 |
+
`common_view` takes a `view` which has different types for its iterator
|
| 6 |
+
and sentinel and turns it into a `view` of the same elements with an
|
| 7 |
+
iterator and sentinel of the same type.
|
| 8 |
+
|
| 9 |
+
[*Note 1*: `common_view` is useful for calling legacy algorithms that
|
| 10 |
+
expect a range’s iterator and sentinel types to be the
|
| 11 |
+
same. — *end note*]
|
| 12 |
+
|
| 13 |
+
The name `views::common` denotes a range adaptor object
|
| 14 |
+
[[range.adaptor.object]]. Given a subexpression `E`, the expression
|
| 15 |
+
`views::common(E)` is expression-equivalent to:
|
| 16 |
+
|
| 17 |
+
- `views::all(E)`, if `decltype((E))` models `common_range` and
|
| 18 |
+
`views::all(E)` is a well-formed expression.
|
| 19 |
+
- Otherwise, `common_view{E}`.
|
| 20 |
+
|
| 21 |
+
[*Example 1*:
|
| 22 |
+
|
| 23 |
+
``` cpp
|
| 24 |
+
// Legacy algorithm:
|
| 25 |
+
template<class ForwardIterator>
|
| 26 |
+
size_t count(ForwardIterator first, ForwardIterator last);
|
| 27 |
+
|
| 28 |
+
template<forward_range R>
|
| 29 |
+
void my_algo(R&& r) {
|
| 30 |
+
auto&& common = common_view{r};
|
| 31 |
+
auto cnt = count(common.begin(), common.end());
|
| 32 |
+
// ...
|
| 33 |
+
}
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
— *end example*]
|
| 37 |
+
|
| 38 |
+
#### Class template `common_view` <a id="range.common.view">[[range.common.view]]</a>
|
| 39 |
+
|
| 40 |
+
``` cpp
|
| 41 |
+
namespace std::ranges {
|
| 42 |
+
template<view V>
|
| 43 |
+
requires (!common_range<V> && copyable<iterator_t<V>>)
|
| 44 |
+
class common_view : public view_interface<common_view<V>> {
|
| 45 |
+
private:
|
| 46 |
+
V base_ = V(); // exposition only
|
| 47 |
+
public:
|
| 48 |
+
common_view() = default;
|
| 49 |
+
|
| 50 |
+
constexpr explicit common_view(V r);
|
| 51 |
+
|
| 52 |
+
template<viewable_range R>
|
| 53 |
+
requires (!common_range<R> && constructible_from<V, views::all_t<R>>)
|
| 54 |
+
constexpr explicit common_view(R&& r);
|
| 55 |
+
|
| 56 |
+
constexpr V base() const& requires copy_constructible<V> { return base_; }
|
| 57 |
+
constexpr V base() && { return std::move(base_); }
|
| 58 |
+
|
| 59 |
+
constexpr auto begin() {
|
| 60 |
+
if constexpr (random_access_range<V> && sized_range<V>)
|
| 61 |
+
return ranges::begin(base_);
|
| 62 |
+
else
|
| 63 |
+
return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::begin(base_));
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
constexpr auto begin() const requires range<const V> {
|
| 67 |
+
if constexpr (random_access_range<const V> && sized_range<const V>)
|
| 68 |
+
return ranges::begin(base_);
|
| 69 |
+
else
|
| 70 |
+
return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::begin(base_));
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
constexpr auto end() {
|
| 74 |
+
if constexpr (random_access_range<V> && sized_range<V>)
|
| 75 |
+
return ranges::begin(base_) + ranges::size(base_);
|
| 76 |
+
else
|
| 77 |
+
return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::end(base_));
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
constexpr auto end() const requires range<const V> {
|
| 81 |
+
if constexpr (random_access_range<const V> && sized_range<const V>)
|
| 82 |
+
return ranges::begin(base_) + ranges::size(base_);
|
| 83 |
+
else
|
| 84 |
+
return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::end(base_));
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
constexpr auto size() requires sized_range<V> {
|
| 88 |
+
return ranges::size(base_);
|
| 89 |
+
}
|
| 90 |
+
constexpr auto size() const requires sized_range<const V> {
|
| 91 |
+
return ranges::size(base_);
|
| 92 |
+
}
|
| 93 |
+
};
|
| 94 |
+
|
| 95 |
+
template<class R>
|
| 96 |
+
common_view(R&&) -> common_view<views::all_t<R>>;
|
| 97 |
+
}
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
``` cpp
|
| 101 |
+
constexpr explicit common_view(V base);
|
| 102 |
+
```
|
| 103 |
+
|
| 104 |
+
*Effects:* Initializes *base\_* with `std::move(base)`.
|
| 105 |
+
|
| 106 |
+
``` cpp
|
| 107 |
+
template<viewable_range R>
|
| 108 |
+
requires (!common_range<R> && constructible_from<V, views::all_t<R>>)
|
| 109 |
+
constexpr explicit common_view(R&& r);
|
| 110 |
+
```
|
| 111 |
+
|
| 112 |
+
*Effects:* Initializes *base\_* with `views::all(std::forward<R>(r))`.
|
| 113 |
+
|