|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
template<ranges::range R> requiresstd::is_object_v<R> | (since C++20) | |
ref_view
is aview
of the elements of some otherrange
. It wraps a reference to thatrange
.
Contents |
Member | Description |
R* r_ | a pointer to the underlying range (exposition-only member object*) |
constructs aref_view that references to the given range(public member function) | |
returns the references to the referenced range (public member function) | |
returns the beginning iterator of the referenced range (public member function) | |
returns the sentinel of the referenced range (public member function) | |
checks whether the referenced range is empty (public member function) | |
returns the size of the referencedsized_range (public member function) | |
(C++26) | returns the approximate size of the referencedapproximately_sized_range (public member function) |
returns the pointer to the beginning of the referencedcontiguous_range (public member function) | |
Inherited fromstd::ranges::view_interface | |
(C++23) | returns a constant iterator to the beginning of the range (public member function of std::ranges::view_interface<D> )[edit] |
(C++23) | returns a sentinel for the constant iterator of the range (public member function of std::ranges::view_interface<D> )[edit] |
returns whether the derived view is not empty, provided only ifranges::empty is applicable to it (public member function of std::ranges::view_interface<D> )[edit] | |
returns the first element in the derived view, provided if it satisfiesforward_range (public member function of std::ranges::view_interface<D> )[edit] | |
returns the last element in the derived view, provided only if it satisfiesbidirectional_range andcommon_range (public member function of std::ranges::view_interface<D> )[edit] | |
returns then th element in the derived view, provided only if it satisfiesrandom_access_range (public member function of std::ranges::view_interface<D> )[edit] |
template</*different-from*/<ref_view> T> requiresstd::convertible_to<T, R&>&& | (since C++20) | |
Initializesr_
withstd::addressof(static_cast<R&>(std::forward<T>(t))).
/*different-from*/<T, U> is satisfied if and only ifstd::remove_cvref_t<T> andstd::remove_cvref_t<U> are not the same type, and overloads of_FUN
are declared asvoid _FUN(R&);void _FUN(R&&)= delete;.
t | - | range to reference |
constexprranges::iterator_t<R> begin()const; | (since C++20) | |
Returnsranges::begin(*r_
).
constexprranges::sentinel_t<R> end()const; | (since C++20) | |
Returnsranges::end(*r_
).
constexprbool empty()const requires requires{ranges::empty(*r_);}; | (since C++20) | |
Returnsranges::empty(*r_
).
constexprauto size()const requiresranges::sized_range<R>; | (since C++20) | |
Returnsranges::size(*r_
).
constexprauto size()const requires ranges::approximately_sized_range<R>; | (since C++26) | |
Returnsranges::reserve_hint(*r_
).
constexprauto data()const requiresranges::contiguous_range<R>; | (since C++20) | |
Returnsranges::data(*r_
).
template<class R> ref_view( R&)-> ref_view<R>; | (since C++20) | |
template<class T> constexprbool enable_borrowed_range<ranges::ref_view<T>>=true; | (since C++20) | |
This specialization ofstd::ranges::enable_borrowed_range
makesref_view
satisfyborrowed_range
.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_reserve_hint | 202502L | (C++26) | ranges::approximately_sized_range andreserve_hint |
#include <iostream>#include <ranges> int main(){conststd::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(constauto c: rv)std::cout<< c;std::cout<<'\n';}
Output:
call empty(): falsecall size() : 3call begin(): ccall end() : scall data() : cosmoscall base() : 3range-for : cos
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 bedefault_initializable | removed along with the requirement |
(C++11) | CopyConstructible andCopyAssignable reference wrapper (class template)[edit] |
(C++20) | aview with unique ownership of somerange (class template)[edit] |
(C++20) | aview that includes all elements of arange (alias template)(range adaptor object)[edit] |