std::ranges::view::all,std::ranges::all_view (3) - Linux Manuals

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

NAME

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

Synopsis


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


// 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::view::all(v) | std::view::take(2) ) {
      std::cout << n << ' ';
    }
  }

Output:


  0 1