std::ranges::views::as_rvalue, std::ranges::as_rvalue_view
Min standard notice:
Header: <ranges>
- A range adaptor that represents a view of underlying view whose elements are rvalues.
# Declarations
template< ranges::view V >
requires ranges::input_range<V>
class as_rvalue_view
: public ranges::view_interface<as_rvalue_view<V>>
(since C++23)
namespace views {
inline constexpr /* unspecified */ as_rvalue = /* unspecified */;
}
(since C++23)
Call signature
template< ranges::viewable_range R >
requires /* see below */
constexpr ranges::view auto as_rvalue( R&& r );
(since C++23)
# Parameters
base: a view
# Notes
Feature-test macro Value Std Feature __cpp_lib_ranges_as_rvalue 202207L (C++23) std::ranges::as_rvalue_view
# Example
#include <algorithm>
#include <iostream>
#include <ranges>
#include <string>
#include <vector>
int main()
{
std::vector<std::string> words =
{"the", "quick", "brown", "\N{FOX FACE}", "ate", "an", "archeopteryx"};
std::vector<std::string> new_words;
std::ranges::copy(
words | std::views::as_rvalue,
std::back_inserter(new_words)); // move string from words into new_words
auto quoted = std::views::transform([](auto&& s) { return "“" + s + "”"; });
std::cout << "Words: ";
for (auto&& word : words | std::views::as_rvalue | quoted)
std::cout << word << ' ';
std::cout << "\nNew words: ";
for (auto&& word : new_words | std::views::as_rvalue | quoted)
std::cout << word << ' ';
}
# Defect reports
| DR | Applied to | Behavior as published | Correct behavior |
|---|---|---|---|
| LWG 4083 | C++23 | views::as_rvalue used to accept non-input ranges | made rejected |