std::ranges::views::all, std::ranges::all_view
From cppreference.com
template <ranges::viewable_range R> using all_view = decltype(views::all(std::declval<R>())); |
(1) | (since C++20) |
namespace views { inline constexpr /*unspecified*/ all = /*unspecified*/; |
(2) | (since C++20) |
A range adaptor that returns a view that includes all elements of its range argument.
The expression views::all(E) is expression-equivalent (has the same effect) to:
- decay-copy(E) if the decayed type of E models view.
- Otherwise, std::ranges::ref_view{E} if that expression is well-formed
- Otherwise, std::ranges::subrange{E}
Expression-equivalent
Expression e is expression-equivalent to expression f, if e and f have the same effects, either are both potentially-throwing or are both not potentially-throwing (i.e. noexcept(e) == noexcept(f)), and either are both constant subexpressions or are both not constant subexpressions.
Example
Run this code
#include <ranges> #include <vector> #include <iostream> int main() { std::vector<int> v{0,1,2,3,4,5}; for(int n : std::views::all(v) | std::views::take(2) ) { std::cout << n << ' '; } }
Output:
0 1