|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
template<ranges::range R> requiresstd::movable<R>&&(!/*is-initializer-list*/<R>) | (since C++20) | |
owning_view
is aview
that has unique ownership of arange
. It is move-only and stores thatrange
within it.
The constant/*is-initializer-list*/<R> in therequires clause istrue if and only ifstd::remove_cvref_t<R> is a specialization ofstd::initializer_list.
Member | Description |
R r_ | the underlying range (exposition-only member object*) |
constructs anowning_view by value-initializing or move-constructing the stored range(public member function) | |
move-assigns the stored range (public member function) | |
returns a reference to the stored range (public member function) | |
returns the beginning iterator of the stored range (public member function) | |
returns the sentinel of the stored range (public member function) | |
checks whether the stored range is empty (public member function) | |
returns the size of the storedsized_range (public member function) | |
(C++26) | returns the approximate size of the storedapproximately_sized_range (public member function) |
returns the pointer to the beginning of the storedcontiguous_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] |
owning_view() requiresstd::default_initializable<R>=default; | (1) | (since C++20) |
owning_view( owning_view&& other)=default; | (2) | (since C++20) |
constexpr owning_view( R&& t); | (3) | (since C++20) |
other | - | anotherowning_view to move from |
t | - | range to move from |
owning_view
does not explicitly define a copy constructor.owning_view
is move-only.
owning_view& operator=( owning_view&& other)=default; | (since C++20) | |
Move assignment operator. Move assignsr_
from that ofother.
other | - | anotherowning_view to move from |
*this
owning_view
does not explicitly define a copy assignment operator.owning_view
is move-only.
constexpr R& base()&noexcept; | (1) | (since C++20) |
constexprconst R& base()const&noexcept; | (2) | (since C++20) |
constexpr R&& base()&&noexcept; | (3) | (since C++20) |
constexprconst R&& base()const&&noexcept; | (4) | (since C++20) |
Returns a reference to the stored range, keeping value category and const-qualification.
r_
r_
)constexprranges::iterator_t<R> begin(); | (1) | (since C++20) |
constexprauto begin()const requiresranges::range<const R>; | (2) | (since C++20) |
Returnsranges::begin(r_
).
constexprranges::sentinel_t<R> end(); | (1) | (since C++20) |
constexprauto end()const requiresranges::range<const R>; | (2) | (since C++20) |
Returnsranges::end(r_
).
constexprbool empty() requires requires{ranges::empty(r_);}; | (1) | (since C++20) |
constexprbool empty()const requires requires{ranges::empty(r_);}; | (2) | (since C++20) |
Returnsranges::empty(r_
).
constexprauto size() requiresranges::sized_range<R>; | (1) | (since C++20) |
constexprauto size()const requiresranges::sized_range<const R>; | (2) | (since C++20) |
Returnsranges::size(r_
).
constexprauto reserve_hint() requires ranges::approximately_sized_range<R>; | (1) | (since C++26) |
constexprauto reserve_hint()const requires ranges::approximately_sized_range<const R>; | (2) | (since C++26) |
Returnsranges::reserve_hint(r_
).
constexprauto data() requiresranges::contiguous_range<R>; | (1) | (since C++20) |
constexprauto data()const requiresranges::contiguous_range<const R>; | (2) | (since C++20) |
Returnsranges::data(r_
).
template<class T> constexprbool enable_borrowed_range<std::ranges::owning_view<T>>= | (since C++20) | |
This specialization ofranges::enable_borrowed_range makesowning_view
satisfyborrowed_range
when the underlying range satisfies it.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_reserve_hint | 202502L | (C++26) | ranges::approximately_sized_range andreserve_hint |
#include <cassert>#include <iostream>#include <ranges>#include <string> int main(){usingnamespace std::literals; std::ranges::owning_view ov{"cosmos"s};// the deduced type of R is std::string;// “ov” is the only owner of this stringassert( ov.empty()==false&& ov.size()==6&& ov.size()== ov.base().size()&& ov.front()=='c'&& ov.front()==*ov.begin()&& ov.back()=='s'&& ov.back()==*(ov.end()-1)&& ov.data()== ov.base()); std::cout<<"sizeof(ov): "<< sizeof ov<<'\n'// typically equal to sizeof(R)<<"range-for: ";for(constchar ch: ov)std::cout<< ch;std::cout<<'\n'; std::ranges::owning_view<std::string> ov2;assert(ov2.empty());// ov2 = ov; // compile-time error: copy assignment operator is deleted ov2= std::move(ov);// OKassert(ov2.size()==6);}
Possible output:
sizeof(ov): 32range-for: cosmos
(C++20) | aview of the elements of some otherrange (class template)[edit] |
(C++20) | aview that includes all elements of arange (alias template)(range adaptor object)[edit] |