std::ranges::ref_view (3) - Linux Manuals

std::ranges::ref_view: std::ranges::ref_view


std::ranges::ref_view - std::ranges::ref_view


Defined in header <ranges>
template<Range R>
requires std::is_object_v<R> (since C++20)
class ref_view : public ranges::view_interface<ref_view<R>>

ref_­view is a View of the elements of some other Range. It wraps a reference to that Range.

Data members


R* r_ = nullptr; /* exposition-only */

pointer to the referenced range

Member functions


constexpr ref_view() noexcept = default; (1)
template<__NotSameAs<ref_view> T>
requires /* see below */ (2)
constexpr ref_view(T&& t);

1) Initializes r_ with nullptr. A default-initialized ref_view references no Range.
2) Initializes r_ with std::addressof(static_­cast<R&>(std::forward<T>(t))).
__NotSameAs is an exposition-only_helper_concept.
The expression in the requires-clause of (2) is equivalent to ConvertibleTo<T, R&> && requires { FUN(declval<T>()); }, where the exposition-only functions FUN are declared as void FUN(R&); void FUN(R&&) = delete;.


t - range to reference


constexpr R& base() const;

Equivalent to return *r_;


constexpr iterator_t<R> begin() const;

Equivalent to return ranges::begin(*r_);


constexpr sentinel_t<R> end() const;

Equivalent to return ranges::end(*r_);


constexpr bool empty() const
requires requires { ranges::empty(*r_); };

Equivalent to return ranges::empty(*r_);


constexpr auto size() const
requires SizedRange<R>
{ return ranges::size(*r_); }


constexpr auto data() const
requires ContiguousRange<R>
{ return ranges::data(*r_); }

Non-member functions

 begin, end(std::ranges::ref_view)

friend constexpr iterator_t<R> begin(ref_view r); (1)
friend constexpr sentinel_t<R> end(ref_view r); (2)

1) Equivalent to return r.begin();
2) Equivalent to return r.end();
These functions are not visible to ordinary unqualified or qualified_lookup, and can only be found by argument-dependent_lookup when std::ranges::ref_view<R> is an associated class of the arguments.

Deduction guides

template<class R>
ref_view(R&) -> ref_view<R>;


 This section is incomplete
 Reason: no example

See also

reference_wrapper CopyConstructible and CopyAssignable reference wrapper
                  (class template)
                  a View that includes all elements of a Range
all_view (alias template) (range adaptor object)