std::ranges::views::as_rvalue, std::ranges::as_rvalue_view

From cppreference.com
< cpp‎ | ranges
 
 
Ranges library
Range access
Range conversions
(C++23)
Range primitives



Dangling iterator handling
Range concepts
Views

Factories






Adaptors
Range adaptor objects
Range adaptor closure objects
Helper items
 
Defined in header <ranges>
template< ranges::view V >

    requires ranges::input_range<V>

class as_rvalue_view : public ranges::view_interface<as_rvalue_view<V>>
(1) (since C++23)
namespace views {

    inline constexpr /* unspecified */ as_rvalue = /* unspecified */;

}
(2) (since C++23)
Call signature
template< ranges::viewable_range R >

    requires /* see below */

constexpr ranges::view auto as_rvalue( R&& r );
(since C++23)
1) A range adaptor that represents a view of underlying view whose elements are rvalues.
2) Range adaptor object. Let e be a subexpression and let T be decltype((e)). Then the expression views::as_rvalue(e) is expression-equivalent to:

Expression-equivalent

Expression e is expression-equivalent to expression f, if

  • e and f have the same effects, and
  • either both are constant subexpressions or else neither is a constant subexpression, and
  • either both are potentially-throwing or else neither is potentially-throwing (i.e. noexcept(e) == noexcept(f)).

Data members

Typical implementations of as_rvalue_view only hold one non-static data member:

  • the underlying view of type V (shown here as base_, the name is exposition only).

Member functions

(constructor)
(C++23)
constructs an as_rvalue_view
(public member function)
base
(C++23)
returns the underlying view V
(public member function)
begin
(C++23)
returns the beginning iterator of the as_rvalue_view
(public member function)
end
(C++23)
returns the end iterator of the as_rvalue_view
(public member function)
size
(C++23)
returns the size of the view if it is bounded
(public member function)
Inherited from std::ranges::view_interface
(C++20)
Returns whether the derived view is empty. Provided if it satisfies sized_range or forward_range.
(public member function of std::ranges::view_interface<D>)
Returns whether the derived view is not empty. Provided if ranges::empty is applicable to it.
(public member function of std::ranges::view_interface<D>)
(C++20)
Returns the first element in the derived view. Provided if it satisfies forward_range.
(public member function of std::ranges::view_interface<D>)
(C++20)
Returns the last element in the derived view. Provided if it satisfies bidirectional_range and common_range.
(public member function of std::ranges::view_interface<D>)
Returns the nth element in the derived view. Provided if it satisfies random_access_range.
(public member function of std::ranges::view_interface<D>)

std::ranges::as_rvalue_view::as_rvalue_view

as_rvalue_view() requires std::default_initializable<V> = default;
(1) (since C++23)
constexpr explicit as_rvalue_view(V base);
(2) (since C++23)
1) Value-initializes base_ via its default member initializer (= V()).
2) Initializes base_ with std::move(base).

Parameters

base - a view

std::ranges::as_rvalue_view::base

constexpr V base() const& requires std::copy_constructible<V>;
(1) (since C++23)
constexpr V base() &&;
(2) (since C++23)

Returns the underlying view.

1) Copy-constructs the result from the underlying view. Equivalent to return base_;.
2) Move-constructs the result from the underlying view. Equivalent to return std::move(base_);.

std::ranges::as_rvalue_view::begin

constexpr auto begin() requires (!/*simple-view*/<V>);
(1) (since C++23)
constexpr auto begin() const requires ranges::range<const V>;
(2) (since C++23)
1-2) Returns std::move_iterator(ranges::begin(base_)).

std::ranges::as_rvalue_view::end

constexpr auto end() requires (!/*simple-view*/<V>);
(1) (since C++23)
constexpr auto end() const requires ranges::range<const V>;
(2) (since C++23)
1) Returns std::move_iterator(ranges::end(base_)) if V models common_range, otherwise std::move_sentinel(ranges::end(base_)).
2) Returns std::move_iterator(ranges::end(base_)) if const V models common_range, otherwise std::move_sentinel(ranges::end(base_)).

std::ranges::as_rvalue_view::size

constexpr auto size() requires ranges::sized_range<V> {

    return ranges::size(base_);

}
(1) (since C++23)
constexpr auto size() const requires ranges::sized_range<const V> {

    return ranges::size(base_);

}
(2) (since C++23)

Returns the size of the view if the view is bounded.

Deduction guides

template<class R>
as_rvalue_view(R&&) -> as_rvalue_view<views::all_t<R>>;
(since C++23)

Helper templates

template<class T>

inline constexpr bool enable_borrowed_range<std::ranges::as_rvalue_view<T>> =

    std::ranges::enable_borrowed_range<T>;
(since C++23)

This specialization of std::ranges::enable_borrowed_range makes as_rvalue_view satisfy borrowed_range when the underlying view satisfies it.

Example

See also

iterator adaptor which dereferences to an rvalue reference
(class template)
sentinel adaptor for use with std::move_iterator
(class template)