ref_view
is a view
of the elements of some other range
. It wraps a reference to that range
.
R*
r_
a pointer to the underlying range
ref_view
that references to the given range
sized_range
approximately_sized_range
contiguous_range
std::ranges::view_interface<D>
) [edit] returns a sentinel for the constant iterator of the range
std::ranges::view_interface<D>
) [edit] returns whether the derived view is not empty, provided only if ranges::empty is applicable to it
std::ranges::view_interface<D>
) [edit] returns the first element in the derived view, provided if it satisfies forward_range
std::ranges::view_interface<D>
) [edit] returns the last element in the derived view, provided only if it satisfies bidirectional_range
and common_range
std::ranges::view_interface<D>
) [edit] returns the n
th element in the derived view, provided only if it satisfies random_access_range
std::ranges::view_interface<D>
) [edit] std::ranges::ref_view::ref_view (since C++20)
Initializes r_
with std::addressof(static_cast<R&>(std::forward<T>(t))).
/*different-from*/<T, U> is satisfied if and only if std::remove_cvref_t<T> and std::remove_cvref_t<U> are not the same type, and overloads of _FUN
are declared as void _FUN(R&); void _FUN(R&&) = delete;.
constexpr R& base() const;
(since C++20)Returns *r_
.
Returns ranges::empty(*r_
).
constexpr auto size() const
requires ranges::approximately_sized_range<R>;
Returns ranges::reserve_hint(*r_
).
template< class R >
ref_view( R& ) -> ref_view<R>;
template< class T >
constexpr bool enable_borrowed_range<ranges::ref_view<T>> = true;
This specialization of std::ranges::enable_borrowed_range
makes ref_view
satisfy borrowed_range
.
#include <iostream> #include <ranges> int main() { const std::string s{"cosmos"}; const std::ranges::take_view tv{s, 3}; const std::ranges::ref_view rv{tv}; std::cout << std::boolalpha << "call empty(): " << rv.empty() << '\n' << "call size() : " << rv.size() << '\n' << "call begin(): " << *rv.begin() << '\n' << "call end() : " << *(rv.end() - 1) << '\n' << "call data() : " << rv.data() << '\n' << "call base() : " << rv.base().size() << '\n' // ~> tv.size() << "range-for : "; for (const auto c : rv) std::cout << c; std::cout << '\n'; }
Output:
call empty(): false call size() : 3 call begin(): c call end() : s call data() : cosmos call base() : 3 range-for : cos[edit] Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior P2325R3 C++20 default constructor was provided asview
must be default_initializable
removed along with the requirement [edit] See also
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4