|
Range primitives | |||||||
|
Range concepts | |||||||||||||||||||
|
Range factories | |||||||||
|
Range adaptors | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
Helper items | |||||||||||||||||
|
Defined in header <ranges> | ||
template<ranges::view V> requiresranges::input_range<V> | (1) | (since C++23) |
namespace views{ inlineconstexpr/* unspecified */ as_const=/* unspecified */; | (2) | (since C++23) |
Call signature | ||
template<ranges::viewable_range R> requires/* see below */ | (since C++23) | |
view
that is also aconstant_range
. Anas_const_view
always has read-only elements (if not empty).T
bedecltype((e)), and letU
bestd::remove_cvref_t<T>. Then the expressionviews::as_const(e) isexpression-equivalent to:constant_range
;X
and some extentExtent
ifU
denotesstd::span<X, Extent>;U
denotesranges::ref_view<X> for some typeX
andconst X modelsconstant_range
;e
is an lvalue,const U modelsconstant_range
, andU
does not modelview
.as_const_view
always modelsconstant_range
, and it models thecontiguous_range
,random_access_range
,bidirectional_range
,forward_range
,borrowed_range
,common_range
, andsized_range
when the underlying viewV
models respective concepts.
Contents |
Member | Description |
V base_ (private) | the underlying view (exposition-only member object*) |
constructs anas_const_view (public member function) | |
returns the underlying viewV (public member function) | |
returns the beginning iterator of theas_const_view (public member function) | |
returns the end iterator of theas_const_view (public member function) | |
returns the size of the view if it is bounded (public member function) | |
(C++26) | returns the approximate size of the underlyingapproximately_sized_range (public member function) |
Inherited fromstd::ranges::view_interface | |
returns whether the derived view is empty, provided only if it satisfiessized_range orforward_range (public member function of std::ranges::view_interface<D> )[edit] | |
(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] | |
gets the address of derived view's data, provided only if its iterator type satisfiescontiguous_iterator (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] |
as_const_view() requiresstd::default_initializable<V>=default; | (1) | (since C++23) |
constexprexplicit as_const_view( V base); | (2) | (since C++23) |
base | - | a view |
constexpr V base()const& requiresstd::copy_constructible<V>; | (1) | (since C++23) |
constexpr V base()&&; | (2) | (since C++23) |
Returns the underlying view.
base_
;.base_
);.constexprauto begin() requires(!/*simple_view*/<V>); | (1) | (since C++23) |
constexprauto begin()const requiresranges::range<const V>; | (2) | (since C++23) |
Returns the constant iterator of the view. Equivalent toreturnranges::cbegin(base_
);.
constexprauto end() requires(!/*simple_view*/<V>); | (1) | (since C++23) |
constexprauto end()const requiresranges::range<const V>; | (2) | (since C++23) |
Returns the constant sentinel of the view. Equivalent toreturnranges::cend(base_
);.
constexprauto size() requiresranges::sized_range<V>; | (1) | (since C++23) |
constexprauto size()const requiresranges::sized_range<const V>; | (2) | (since C++23) |
Returns the size of the view if the view is bounded. Equivalent toreturnranges::size(base_
);.
constexprauto reserve_hint() requires ranges::approximately_sized_range<V>; | (1) | (since C++26) |
constexprauto reserve_hint()const requires ranges::approximately_sized_range<const V>; | (2) | (since C++26) |
Returnsranges::reserve_hint(base_
).
template<class R> as_const_view( R&&)-> as_const_view<views::all_t<R>>; | (since C++23) | |
template<class T> constexprbool enable_borrowed_range<std::ranges::as_const_view<T>>= | (since C++23) | |
This specialization ofranges::enable_borrowed_range makesas_const_view
satisfyborrowed_range
when the underlying view satisfies it.
Feature-test macro | Value | Std | Feature |
---|---|---|---|
__cpp_lib_ranges_as_const | 202207L | (C++23) | ranges::as_const_view ,std::const_iterator |
__cpp_lib_ranges_reserve_hint | 202502L | (C++26) | ranges::approximately_sized_range andreserve_hint |
#include <cassert>#include <ranges> int main(){int x[]{1,2,3,4,5}; auto v1= x| std::views::drop(2);assert(v1.back()==5); v1[0]++;// OK, can modify non-const element auto v2= x| std::views::drop(2)| std::views::as_const;assert(v2.back()==5);// v2[0]++; // Compile-time error, cannot modify read-only element}
aview of a sequence that casts each element to an rvalue(class template)(range adaptor object)[edit] | |
(C++20) | returns an iterator to the beginning of a read-only range (customization point object)[edit] |
(C++20) | returns a sentinel indicating the end of a read-only range (customization point object)[edit] |
(C++17) | obtains a reference toconst to its argument (function template)[edit] |
(C++23) | iterator adaptor that converts an iterator into a constant iterator (class template)[edit] |