[range.as.rvalue]

# 25 Ranges library [[ranges]](./#ranges)

## 25.7 Range adaptors [[range.adaptors]](range.adaptors#range.as.rvalue)

### 25.7.7 As rvalue view [range.as.rvalue]

#### [25.7.7.1](#overview) Overview [[range.as.rvalue.overview]](range.as.rvalue.overview)

[1](#overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4654)

as_rvalue_view presents a view of an underlying sequence
with the same behavior as the underlying sequence
except that its elements are rvalues[.](#overview-1.sentence-1)

Some generic algorithms can be called with an as_rvalue_view to replace copying with moving[.](#overview-1.sentence-2)

[2](#overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4661)

The name views​::​as_rvalue denotes
a range adaptor object ([[range.adaptor.object]](range.adaptor.object "25.7.2 Range adaptor objects"))[.](#overview-2.sentence-1)

Let E be an expression and let T be decltype((E))[.](#overview-2.sentence-2)

The expression views​::​as_rvalue(E) is expression-equivalent to:

- [(2.1)](#overview-2.1)

  views​::​all(E) ifT models [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]") and[same_as](concept.same#concept:same_as "18.4.2 Concept same_­as [concept.same]")<range_rvalue_reference_t<T>, range_reference_t<T>> is true[.](#overview-2.1.sentence-1)

- [(2.2)](#overview-2.2)

  Otherwise, as_rvalue_view(E)[.](#overview-2.2.sentence-1)

[3](#overview-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4676)

[*Example [1](#overview-example-1)*: vector<string> words = {"the", "quick", "brown", "fox", "ate", "a", "pterodactyl"};
vector<string> new_words;
ranges::copy(words | views::as_rvalue, back_inserter(new_words)); // moves each string from words into new_words â *end example*]

#### [25.7.7.2](#view) Class template as_rvalue_view [[range.as.rvalue.view]](range.as.rvalue.view)

namespace std::ranges {template<[view](range.view#concept:view "25.4.5 Views [range.view]") V>requires [input_range](range.refinements#concept:input_range "25.4.6 Other range refinements [range.refinements]")<V>class [as_rvalue_view](#lib:as_rvalue_view "25.7.7.2 Class template as_­rvalue_­view [range.as.rvalue.view]") : public view_interface<as_rvalue_view<V>> { V *base_* = V(); // *exposition only*public: as_rvalue_view() requires [default_initializable](concept.default.init#concept:default_initializable "18.4.12 Concept default_­initializable [concept.default.init]")<V> = default; constexpr explicit as_rvalue_view(V base); constexpr V base() const & requires [copy_constructible](concept.copyconstructible#concept:copy_constructible "18.4.14 Concept copy_­constructible [concept.copyconstructible]")<V> { return *base_*; }constexpr V base() && { return std::move(*base_*); }constexpr auto begin() requires (![*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V>){ return move_iterator(ranges::begin(*base_*)); }constexpr auto begin() const requires [range](range.range#concept:range "25.4.2 Ranges [range.range]")<const V>{ return move_iterator(ranges::begin(*base_*)); }constexpr auto end() requires (![*simple-view*](range.utility.helpers#concept:simple-view "25.5.2 Helper concepts [range.utility.helpers]")<V>) {if constexpr ([common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]")<V>) {return move_iterator(ranges::end(*base_*)); } else {return move_sentinel(ranges::end(*base_*)); }}constexpr auto end() const requires [range](range.range#concept:range "25.4.2 Ranges [range.range]")<const V> {if constexpr ([common_range](range.refinements#concept:common_range "25.4.6 Other range refinements [range.refinements]")<const V>) {return move_iterator(ranges::end(*base_*)); } else {return move_sentinel(ranges::end(*base_*)); }}constexpr auto size() requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<V> { return ranges::size(*base_*); }constexpr auto size() const requires [sized_range](range.sized#concept:sized_range "25.4.4 Sized ranges [range.sized]")<const V> { return ranges::size(*base_*); }constexpr auto reserve_hint() requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<V>{ return ranges::reserve_hint(*base_*); }constexpr auto reserve_hint() const requires [approximately_sized_range](range.approximately.sized#concept:approximately_sized_range "25.4.3 Approximately sized ranges [range.approximately.sized]")<const V>{ return ranges::reserve_hint(*base_*); }}; template<class R> as_rvalue_view(R&&) -> as_rvalue_view<views::all_t<R>>;}

[ð](#lib:as_rvalue_view,constructor)

`constexpr explicit as_rvalue_view(V base);
`

[1](#view-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/ranges.tex#L4742)

*Effects*: Initializes *base_* with std​::​move(base)[.](#view-1.sentence-1)
