tmp/tmpv3jnj28j/{from.md → to.md}
RENAMED
|
@@ -1,41 +1,59 @@
|
|
| 1 |
### Drop view <a id="range.drop">[[range.drop]]</a>
|
| 2 |
|
| 3 |
#### Overview <a id="range.drop.overview">[[range.drop.overview]]</a>
|
| 4 |
|
| 5 |
-
`drop_view` produces a
|
| 6 |
-
|
| 7 |
-
|
| 8 |
|
| 9 |
The name `views::drop` denotes a range adaptor object
|
| 10 |
[[range.adaptor.object]]. Let `E` and `F` be expressions, let `T` be
|
| 11 |
`remove_cvref_t<decltype((E))>`, and let `D` be
|
| 12 |
`range_difference_t<decltype((E))>`. If `decltype((F))` does not model
|
| 13 |
`convertible_to<D>`, `views::drop(E, F)` is ill-formed. Otherwise, the
|
| 14 |
expression `views::drop(E, F)` is expression-equivalent to:
|
| 15 |
|
| 16 |
-
- If `T` is a specialization of `
|
| 17 |
-
|
|
|
|
| 18 |
- Otherwise, if `T` models `random_access_range` and `sized_range` and
|
| 19 |
is
|
| 20 |
-
- a specialization of `span` [[views.span]]
|
| 21 |
-
`T::extent == dynamic_extent`,
|
| 22 |
- a specialization of `basic_string_view` [[string.view]],
|
| 23 |
-
- a specialization of `
|
| 24 |
-
- a specialization of `
|
|
|
|
| 25 |
|
| 26 |
then
|
| 27 |
-
`
|
| 28 |
-
except that `E` is evaluated only once
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
[*Example 1*:
|
| 32 |
|
| 33 |
``` cpp
|
| 34 |
auto ints = views::iota(0) | views::take(10);
|
| 35 |
-
auto
|
| 36 |
-
for (auto i : latter_half) {
|
| 37 |
cout << i << ' '; // prints 5 6 7 8 9
|
| 38 |
}
|
| 39 |
```
|
| 40 |
|
| 41 |
— *end example*]
|
|
@@ -45,44 +63,40 @@ for (auto i : latter_half) {
|
|
| 45 |
``` cpp
|
| 46 |
namespace std::ranges {
|
| 47 |
template<view V>
|
| 48 |
class drop_view : public view_interface<drop_view<V>> {
|
| 49 |
public:
|
| 50 |
-
drop_view() = default;
|
| 51 |
-
constexpr drop_view(V base, range_difference_t<V> count);
|
| 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 |
-
requires (!(simple-view<V> &&
|
|
|
|
| 58 |
constexpr auto begin() const
|
| 59 |
-
requires random_access_range<const V>;
|
| 60 |
|
| 61 |
-
constexpr auto end()
|
| 62 |
-
requires (!simple-view<V>)
|
| 63 |
{ return ranges::end(base_); }
|
| 64 |
|
| 65 |
-
constexpr auto end() const
|
| 66 |
-
requires range<const V>
|
| 67 |
{ return ranges::end(base_); }
|
| 68 |
|
| 69 |
-
constexpr auto size()
|
| 70 |
-
requires sized_range<V>
|
| 71 |
-
{
|
| 72 |
const auto s = ranges::size(base_);
|
| 73 |
const auto c = static_cast<decltype(s)>(count_);
|
| 74 |
return s < c ? 0 : s - c;
|
| 75 |
}
|
| 76 |
|
| 77 |
-
constexpr auto size() const
|
| 78 |
-
requires sized_range<const V>
|
| 79 |
-
{
|
| 80 |
const auto s = ranges::size(base_);
|
| 81 |
const auto c = static_cast<decltype(s)>(count_);
|
| 82 |
return s < c ? 0 : s - c;
|
| 83 |
}
|
|
|
|
| 84 |
private:
|
| 85 |
V base_ = V(); // exposition only
|
| 86 |
range_difference_t<V> count_ = 0; // exposition only
|
| 87 |
};
|
| 88 |
|
|
@@ -90,27 +104,28 @@ namespace std::ranges {
|
|
| 90 |
drop_view(R&&, range_difference_t<R>) -> drop_view<views::all_t<R>>;
|
| 91 |
}
|
| 92 |
```
|
| 93 |
|
| 94 |
``` cpp
|
| 95 |
-
constexpr drop_view(V base, range_difference_t<V> count);
|
| 96 |
```
|
| 97 |
|
| 98 |
*Preconditions:* `count >= 0` is `true`.
|
| 99 |
|
| 100 |
*Effects:* Initializes *base\_* with `std::move(base)` and *count\_*
|
| 101 |
with `count`.
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
constexpr auto begin()
|
| 105 |
-
requires (!(simple-view<V> &&
|
|
|
|
| 106 |
constexpr auto begin() const
|
| 107 |
-
requires random_access_range<const V>;
|
| 108 |
```
|
| 109 |
|
| 110 |
*Returns:*
|
| 111 |
-
`ranges::next(ranges::begin(base_), count_, ranges::end(base_))`.
|
| 112 |
|
| 113 |
*Remarks:* In order to provide the amortized constant-time complexity
|
| 114 |
required by the `range` concept when `drop_view` models `forward_range`,
|
| 115 |
the first overload caches the result within the `drop_view` for use on
|
| 116 |
subsequent calls.
|
|
|
|
| 1 |
### Drop view <a id="range.drop">[[range.drop]]</a>
|
| 2 |
|
| 3 |
#### Overview <a id="range.drop.overview">[[range.drop.overview]]</a>
|
| 4 |
|
| 5 |
+
`drop_view` produces a view excluding the first N elements from another
|
| 6 |
+
view, or an empty range if the adapted view contains fewer than N
|
| 7 |
+
elements.
|
| 8 |
|
| 9 |
The name `views::drop` denotes a range adaptor object
|
| 10 |
[[range.adaptor.object]]. Let `E` and `F` be expressions, let `T` be
|
| 11 |
`remove_cvref_t<decltype((E))>`, and let `D` be
|
| 12 |
`range_difference_t<decltype((E))>`. If `decltype((F))` does not model
|
| 13 |
`convertible_to<D>`, `views::drop(E, F)` is ill-formed. Otherwise, the
|
| 14 |
expression `views::drop(E, F)` is expression-equivalent to:
|
| 15 |
|
| 16 |
+
- If `T` is a specialization of `empty_view` [[range.empty.view]], then
|
| 17 |
+
`((void)F, decay-copy(E))`, except that the evaluations of `E` and `F`
|
| 18 |
+
are indeterminately sequenced.
|
| 19 |
- Otherwise, if `T` models `random_access_range` and `sized_range` and
|
| 20 |
is
|
| 21 |
+
- a specialization of `span` [[views.span]],
|
|
|
|
| 22 |
- a specialization of `basic_string_view` [[string.view]],
|
| 23 |
+
- a specialization of `iota_view` [[range.iota.view]], or
|
| 24 |
+
- a specialization of `subrange` [[range.subrange]] where
|
| 25 |
+
`T::StoreSize` is `false`,
|
| 26 |
|
| 27 |
then
|
| 28 |
+
`U(ranges::begin(E) + std::min<D>(ranges::distance(E), F), ranges::end(E))`,
|
| 29 |
+
except that `E` is evaluated only once, where `U` is
|
| 30 |
+
`span<typename T::element_type>` if `T` is a specialization of `span`
|
| 31 |
+
and `T` otherwise.
|
| 32 |
+
- Otherwise, if `T` is a specialization of `subrange` [[range.subrange]]
|
| 33 |
+
that models `random_access_range` and `sized_range`, then
|
| 34 |
+
`T(ranges::begin(E) + std::min<D>(ranges::distance(E), F), ranges::{}end(E),
|
| 35 |
+
to-unsigned-like(ranges::distance(E) -
|
| 36 |
+
std::min<D>(ranges::distance(E), F)))`, except that `E` and `F` are
|
| 37 |
+
each evaluated only once.
|
| 38 |
+
- Otherwise, if `T` is a specialization of `repeat_view`
|
| 39 |
+
[[range.repeat.view]]:
|
| 40 |
+
- if `T` models `sized_range`, then
|
| 41 |
+
``` cpp
|
| 42 |
+
views::repeat(*E.value_, ranges::distance(E) - std::min<D>(ranges::distance(E), F))
|
| 43 |
+
```
|
| 44 |
+
|
| 45 |
+
except that `E` is evaluated only once;
|
| 46 |
+
- otherwise, `((void)F, decay-copy(E))`, except that the evaluations
|
| 47 |
+
of `E` and `F` are indeterminately sequenced.
|
| 48 |
+
- Otherwise, `drop_view(E, F)`.
|
| 49 |
|
| 50 |
[*Example 1*:
|
| 51 |
|
| 52 |
``` cpp
|
| 53 |
auto ints = views::iota(0) | views::take(10);
|
| 54 |
+
for (auto i : ints | views::drop(5)) {
|
|
|
|
| 55 |
cout << i << ' '; // prints 5 6 7 8 9
|
| 56 |
}
|
| 57 |
```
|
| 58 |
|
| 59 |
— *end example*]
|
|
|
|
| 63 |
``` cpp
|
| 64 |
namespace std::ranges {
|
| 65 |
template<view V>
|
| 66 |
class drop_view : public view_interface<drop_view<V>> {
|
| 67 |
public:
|
| 68 |
+
drop_view() requires default_initializable<V> = default;
|
| 69 |
+
constexpr explicit drop_view(V base, range_difference_t<V> count);
|
| 70 |
|
| 71 |
constexpr V base() const & requires copy_constructible<V> { return base_; }
|
| 72 |
constexpr V base() && { return std::move(base_); }
|
| 73 |
|
| 74 |
constexpr auto begin()
|
| 75 |
+
requires (!(simple-view<V> &&
|
| 76 |
+
random_access_range<const V> && sized_range<const V>));
|
| 77 |
constexpr auto begin() const
|
| 78 |
+
requires random_access_range<const V> && sized_range<const V>;
|
| 79 |
|
| 80 |
+
constexpr auto end() requires (!simple-view<V>)
|
|
|
|
| 81 |
{ return ranges::end(base_); }
|
| 82 |
|
| 83 |
+
constexpr auto end() const requires range<const V>
|
|
|
|
| 84 |
{ return ranges::end(base_); }
|
| 85 |
|
| 86 |
+
constexpr auto size() requires sized_range<V> {
|
|
|
|
|
|
|
| 87 |
const auto s = ranges::size(base_);
|
| 88 |
const auto c = static_cast<decltype(s)>(count_);
|
| 89 |
return s < c ? 0 : s - c;
|
| 90 |
}
|
| 91 |
|
| 92 |
+
constexpr auto size() const requires sized_range<const V> {
|
|
|
|
|
|
|
| 93 |
const auto s = ranges::size(base_);
|
| 94 |
const auto c = static_cast<decltype(s)>(count_);
|
| 95 |
return s < c ? 0 : s - c;
|
| 96 |
}
|
| 97 |
+
|
| 98 |
private:
|
| 99 |
V base_ = V(); // exposition only
|
| 100 |
range_difference_t<V> count_ = 0; // exposition only
|
| 101 |
};
|
| 102 |
|
|
|
|
| 104 |
drop_view(R&&, range_difference_t<R>) -> drop_view<views::all_t<R>>;
|
| 105 |
}
|
| 106 |
```
|
| 107 |
|
| 108 |
``` cpp
|
| 109 |
+
constexpr explicit drop_view(V base, range_difference_t<V> count);
|
| 110 |
```
|
| 111 |
|
| 112 |
*Preconditions:* `count >= 0` is `true`.
|
| 113 |
|
| 114 |
*Effects:* Initializes *base\_* with `std::move(base)` and *count\_*
|
| 115 |
with `count`.
|
| 116 |
|
| 117 |
``` cpp
|
| 118 |
constexpr auto begin()
|
| 119 |
+
requires (!(simple-view<V> &&
|
| 120 |
+
random_access_range<const V> && sized_range<const V>));
|
| 121 |
constexpr auto begin() const
|
| 122 |
+
requires random_access_range<const V> && sized_range<const V>;
|
| 123 |
```
|
| 124 |
|
| 125 |
*Returns:*
|
| 126 |
+
`ranges::next(ranges::begin(`*`base_`*`), `*`count_`*`, ranges::end(`*`base_`*`))`.
|
| 127 |
|
| 128 |
*Remarks:* In order to provide the amortized constant-time complexity
|
| 129 |
required by the `range` concept when `drop_view` models `forward_range`,
|
| 130 |
the first overload caches the result within the `drop_view` for use on
|
| 131 |
subsequent calls.
|