A range adaptor that represents a view of underlying
view
with reversed order.
2) RangeAdaptorObject. The expression
views::reverse(e)is
expression-equivalentto one of the following expressions, except that
eis evaluated only once:
e
is a (possibly cv-qualified) specialization of reverse_view
;I
and value K
of type ranges::subrange_kind
:K
is ranges::subrange_kind::sized
;In other words,
views::reverse
unwraps reversed views if possible.
A reverse_view
always models bidirectional_range
and common_range
, and it models borrowed_range
, sized_range
, or random_access_range
if the underlying view type V
models the corresponding concept.
V
base_
(private) the underlying view
cached_end_
(private)
V
does not satisfy common_range
) an object that caches the result of calls to begin()
reverse_view
V
reverse_view
reverse_view
approximately_sized_range
sized_range
or forward_range
std::ranges::view_interface<D>
) [edit] returns a constant iterator to the beginning of the 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::reverse_view::reverse_view (1) (since C++20)
constexpr reverse_view( V r );
(2) (since C++20) 1)Value-initializes
base_
via its default member initializer (
= V()).
2)Initializes
base_
with
std::move(r).
Parameters std::ranges::reverse_view::base (1) (since C++20)constexpr V base() &&;
(2) (since C++20)Returns the underlying view.
1)Copy-constructs the result from the underlying view. Equivalent to
return
base_
;
.
2)Move-constructs the result from the underlying view. Equivalent to
return std::move(base_
);
.
std::ranges::reverse_view::beginIn order to provide the amortized constant time complexity required by the
range
concept, this function caches the result within the cache object for use on subsequent calls.
std::ranges::reverse_view::sizeReturns the size of the view if the view is bounded. Equivalent to return ranges::size(base_
);.
constexpr auto reserve_hint()
requires ranges::approximately_sized_range<V>;
constexpr auto reserve_hint() const
requires ranges::approximately_sized_range<const V>;
Returns ranges::reserve_hint(base_
).
This specialization of std::ranges::enable_borrowed_range makes reverse_view
satisfy borrowed_range
when the underlying view satisfies it.
#include <iostream> #include <ranges> int main() { static constexpr auto il = {3, 1, 4, 1, 5, 9}; std::ranges::reverse_view rv{il}; for (int i : rv) std::cout << i << ' '; std::cout << '\n'; for (int i : il | std::views::reverse) std::cout << i << ' '; std::cout << '\n'; // operator[] is inherited from std::view_interface for (auto i{0U}; i != rv.size(); ++i) std::cout << rv[i] << ' '; std::cout << '\n'; }
Output:
9 5 1 4 1 3 9 5 1 4 1 3 9 5 1 4 1 3[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 LWG 3494 C++20reverse_view
was never a borrowed_range
it is a borrowed_range
if its underlying view is [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