tmp/tmpa678i_6x/{from.md → to.md}
RENAMED
|
@@ -1,11 +1,11 @@
|
|
| 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
|
| 6 |
-
and sentinel and turns it into a
|
| 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*]
|
|
@@ -25,11 +25,11 @@ The name `views::common` denotes a range adaptor object
|
|
| 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 =
|
| 31 |
auto cnt = count(common.begin(), common.end());
|
| 32 |
// ...
|
| 33 |
}
|
| 34 |
```
|
| 35 |
|
|
@@ -42,19 +42,16 @@ 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>)
|
|
@@ -70,18 +67,18 @@ namespace std::ranges {
|
|
| 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::
|
| 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::
|
| 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> {
|
|
@@ -101,13 +98,5 @@ namespace std::ranges {
|
|
| 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 |
-
|
|
|
|
| 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*]
|
|
|
|
| 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 = views::common(r);
|
| 31 |
auto cnt = count(common.begin(), common.end());
|
| 32 |
// ...
|
| 33 |
}
|
| 34 |
```
|
| 35 |
|
|
|
|
| 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 |
+
|
| 48 |
public:
|
| 49 |
+
common_view() requires default_initializable<V> = default;
|
| 50 |
|
| 51 |
constexpr explicit common_view(V r);
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
constexpr V base() const & requires copy_constructible<V> { return base_; }
|
| 54 |
constexpr V base() && { return std::move(base_); }
|
| 55 |
|
| 56 |
constexpr auto begin() {
|
| 57 |
if constexpr (random_access_range<V> && sized_range<V>)
|
|
|
|
| 67 |
return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::begin(base_));
|
| 68 |
}
|
| 69 |
|
| 70 |
constexpr auto end() {
|
| 71 |
if constexpr (random_access_range<V> && sized_range<V>)
|
| 72 |
+
return ranges::begin(base_) + ranges::distance(base_);
|
| 73 |
else
|
| 74 |
return common_iterator<iterator_t<V>, sentinel_t<V>>(ranges::end(base_));
|
| 75 |
}
|
| 76 |
|
| 77 |
constexpr auto end() const requires range<const V> {
|
| 78 |
if constexpr (random_access_range<const V> && sized_range<const V>)
|
| 79 |
+
return ranges::begin(base_) + ranges::distance(base_);
|
| 80 |
else
|
| 81 |
return common_iterator<iterator_t<const V>, sentinel_t<const V>>(ranges::end(base_));
|
| 82 |
}
|
| 83 |
|
| 84 |
constexpr auto size() requires sized_range<V> {
|
|
|
|
| 98 |
constexpr explicit common_view(V base);
|
| 99 |
```
|
| 100 |
|
| 101 |
*Effects:* Initializes *base\_* with `std::move(base)`.
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|