std::ranges::views::as_const, std::ranges::as_const_view
Defined in header <ranges>
|
||
template< ranges::view V > requires ranges::input_range<V> |
(1) | (since C++23) |
namespace views { inline constexpr /* 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 a constant_range
. An as_const_view
always has read-only elements (if not empty).- views::all(e), if it is a well-formed expression and views::all_t<T> models
constant_range
; - otherwise, std::span<const X, Extent>(e) for some type
X
and some extentExtent
ifU
denotes std::span<X, Extent>; - otherwise, ranges::ref_view(static_cast<const U&>(e)) if
e
is an lvalue, const U modelsconstant_range
, and U does not modelview
. - otherwise, as_const_view{e}.
as_const_view
always models constant_range
, and it models the contiguous_range
, random_access_range
, bidirectional_range
, forward_range
, borrowed_range
, common_range
, and sized_range
when the underlying view V
models respective concepts.
Expression-equivalent
Expression e is expression-equivalent to expression f, if
- e and f have the same effects, and
- either both are constant subexpressions or else neither is a constant subexpression, and
- either both are potentially-throwing or else neither is potentially-throwing (i.e. noexcept(e) == noexcept(f)).
Data members
Typical implementations of as_const_view
only hold one non-static data member:
- the underlying view of type
V
(shown here asbase_
, the name is exposition only).
Member functions
(constructor) (C++23) |
constructs an as_const_view (public member function) |
base (C++23) |
returns the underlying view V (public member function) |
begin (C++23) |
returns the beginning iterator of the as_const_view (public member function) |
end (C++23) |
returns the end iterator of the as_const_view (public member function) |
size (C++23) |
returns the size of the view if it is bounded (public member function) |
Inherited from std::ranges::view_interface | |
(C++20) |
Returns whether the derived view is empty. Provided if it satisfies sized_range or forward_range . (public member function of std::ranges::view_interface<D> ) |
(C++20) |
Returns whether the derived view is not empty. Provided if ranges::empty is applicable to it. (public member function of std::ranges::view_interface<D> ) |
(C++20) |
Gets the address of derived view's data. Provided if its iterator type satisfies contiguous_iterator . (public member function of std::ranges::view_interface<D> ) |
(C++20) |
Returns the first element in the derived view. Provided if it satisfies forward_range . (public member function of std::ranges::view_interface<D> ) |
(C++20) |
Returns the last element in the derived view. Provided if it satisfies bidirectional_range and common_range . (public member function of std::ranges::view_interface<D> ) |
(C++20) |
Returns the nth element in the derived view. Provided if it satisfies random_access_range . (public member function of std::ranges::view_interface<D> ) |
std::ranges::as_const_view::as_const_view
as_const_view() requires std::default_initializable<V> = default; |
(1) | (since C++23) |
constexpr explicit as_const_view(V base); |
(2) | (since C++23) |
base_
via its default member initializer (= V()).base_
with std::move(base).Parameters
base | - | a view |
std::ranges::as_const_view::base
constexpr V base() const& requires std::copy_constructible<V>; |
(1) | (since C++23) |
constexpr V base() &&; |
(2) | (since C++23) |
Returns the underlying view.
std::ranges::as_const_view::begin
constexpr auto begin() requires (!/*simple-view*/<V>) { return ranges::cbegin(base_); |
(1) | (since C++23) |
constexpr auto begin() const requires ranges::range<const V> { return ranges::cbegin(base_); |
(2) | (since C++23) |
Returns the constant iterator of the view.
std::ranges::as_const_view::end
constexpr auto end() requires (!/*simple-view*/<V>) { return ranges::cend(base_); |
(1) | (since C++23) |
constexpr auto end() const requires ranges::range<const V> { return ranges::cend(base_); |
(2) | (since C++23) |
Returns the constant sentinel of the view.
std::ranges::as_const_view::size
constexpr auto size() requires ranges::sized_range<V> { return ranges::size(base_); |
(1) | (since C++23) |
constexpr auto size() const requires ranges::sized_range<const V> { return ranges::size(base_); |
(2) | (since C++23) |
Returns the size of the view if the view is bounded.
Deduction guides
template<class R> as_const_view(R&&) -> as_const_view<views::all_t<R>>; |
(since C++23) | |
Helper templates
template<class T> inline constexpr bool enable_borrowed_range<std::ranges::as_const_view<T>> = |
(since C++23) | |
This specialization of std::ranges::enable_borrowed_range makes as_const_view
satisfy borrowed_range
when the underlying view satisfies it.
Example
This section is incomplete Reason: example |
See also
(C++20) |
returns an iterator to the beginning of a read-only range (customization point object) |
(C++20) |
returns a sentinel indicating the end of a read-only range (customization point object) |