std::ranges::view::all, std::ranges::all_view

template <ViewableRange R>
using all_view = decltype(view::all(std::declval<R>()));
(1) (since C++20)
namespace view {
    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 view::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}

Example

#include <ranges>
#include <vector>
#include <iostream>
 
int main()
{
  std::vector<int> v{0,1,2,3,4,5};
  for(int n : std::view::all(v) | std::view::take(2) ) {
    std::cout << n << ' ';
  }
}

Output:

0 1

© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/ranges/all_view