tmp/tmpj_g4te_a/{from.md → to.md}
RENAMED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
### As rvalue view <a id="range.as.rvalue">[[range.as.rvalue]]</a>
|
| 2 |
+
|
| 3 |
+
#### Overview <a id="range.as.rvalue.overview">[[range.as.rvalue.overview]]</a>
|
| 4 |
+
|
| 5 |
+
`as_rvalue_view` presents a view of an underlying sequence with the same
|
| 6 |
+
behavior as the underlying sequence except that its elements are
|
| 7 |
+
rvalues. Some generic algorithms can be called with an `as_rvalue_view`
|
| 8 |
+
to replace copying with moving.
|
| 9 |
+
|
| 10 |
+
The name `views::as_rvalue` denotes a range adaptor object
|
| 11 |
+
[[range.adaptor.object]]. Let `E` be an expression and let `T` be
|
| 12 |
+
`decltype((E))`. The expression `views::as_rvalue(E)` is
|
| 13 |
+
expression-equivalent to:
|
| 14 |
+
|
| 15 |
+
- `views::all(E)` if
|
| 16 |
+
`same_as<range_rvalue_reference_t<T>, range_reference_t<T>>` is
|
| 17 |
+
`true`.
|
| 18 |
+
- Otherwise, `as_rvalue_view(E)`.
|
| 19 |
+
|
| 20 |
+
[*Example 1*:
|
| 21 |
+
|
| 22 |
+
``` cpp
|
| 23 |
+
vector<string> words = {"the", "quick", "brown", "fox", "ate", "a", "pterodactyl"};
|
| 24 |
+
vector<string> new_words;
|
| 25 |
+
ranges::copy(words | views::as_rvalue, back_inserter(new_words));
|
| 26 |
+
// moves each string from words into new_words
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
— *end example*]
|
| 30 |
+
|
| 31 |
+
#### Class template `as_rvalue_view` <a id="range.as.rvalue.view">[[range.as.rvalue.view]]</a>
|
| 32 |
+
|
| 33 |
+
``` cpp
|
| 34 |
+
namespace std::ranges {
|
| 35 |
+
template<view V>
|
| 36 |
+
requires input_range<V>
|
| 37 |
+
class as_rvalue_view : public view_interface<as_rvalue_view<V>> {
|
| 38 |
+
V base_ = V(); // exposition only
|
| 39 |
+
|
| 40 |
+
public:
|
| 41 |
+
as_rvalue_view() requires default_initializable<V> = default;
|
| 42 |
+
constexpr explicit as_rvalue_view(V base);
|
| 43 |
+
|
| 44 |
+
constexpr V base() const & requires copy_constructible<V> { return base_; }
|
| 45 |
+
constexpr V base() && { return std::move(base_); }
|
| 46 |
+
|
| 47 |
+
constexpr auto begin() requires (!simple-view<V>)
|
| 48 |
+
{ return move_iterator(ranges::begin(base_)); }
|
| 49 |
+
constexpr auto begin() const requires range<const V>
|
| 50 |
+
{ return move_iterator(ranges::begin(base_)); }
|
| 51 |
+
|
| 52 |
+
constexpr auto end() requires (!simple-view<V>) {
|
| 53 |
+
if constexpr (common_range<V>) {
|
| 54 |
+
return move_iterator(ranges::end(base_));
|
| 55 |
+
} else {
|
| 56 |
+
return move_sentinel(ranges::end(base_));
|
| 57 |
+
}
|
| 58 |
+
}
|
| 59 |
+
constexpr auto end() const requires range<const V> {
|
| 60 |
+
if constexpr (common_range<const V>) {
|
| 61 |
+
return move_iterator(ranges::end(base_));
|
| 62 |
+
} else {
|
| 63 |
+
return move_sentinel(ranges::end(base_));
|
| 64 |
+
}
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
constexpr auto size() requires sized_range<V> { return ranges::size(base_); }
|
| 68 |
+
constexpr auto size() const requires sized_range<const V> { return ranges::size(base_); }
|
| 69 |
+
};
|
| 70 |
+
|
| 71 |
+
template<class R>
|
| 72 |
+
as_rvalue_view(R&&) -> as_rvalue_view<views::all_t<R>>;
|
| 73 |
+
}
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
``` cpp
|
| 77 |
+
constexpr explicit as_rvalue_view(V base);
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
*Effects:* Initializes *base\_* with `std::move(base)`.
|
| 81 |
+
|