std::ranges::views::all, std::ranges::views::all_t
From cppreference.com
Defined in header <ranges>
|
||
inline constexpr /* unspecified */ all = /* unspecified */; |
(1) | (since C++20) |
template< ranges::viewable_range R > using all_t = decltype(views::all(std::declval<R>())); |
(2) | (since C++20) |
1) A RangeAdaptorObject (also a RangeAdaptorClosureObject) that returns a
view
that includes all elements of its range
argument. Given an expression e of type
R
, the expression views::all(e) is expression-equivalent to:
- If std::decay_t<R> models
view
, implicitly converting e to a std::decay_t<R> prvalue. - Otherwise, std::ranges::ref_view{e} if that expression is well-formed.
- Otherwise, std::ranges::owning_view{e}.
[edit] Example
Run this code
#include <iostream> #include <ranges> #include <type_traits> #include <vector> int main() { std::vector<int> v{0, 1, 2, 3, 4, 5}; for (int n : std::views::all(v) | std::views::take(2))