Namespaces
Variants
Views
Actions

std::ranges::views::all, std::ranges::views::all_t

From cppreference.com
< cpp‎ | ranges
 
 
 
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 range adaptor object (also a range adaptor closure object) 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:

2) Calculates the suitable view type of a viewable_range type.

[edit] 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.

[edit] Example

#include <ranges>
#include <vector>
#include <iostream>
#include <type_traits>
 
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 << ' ';
    }
 
    static_assert(std::is_same<
        decltype(std::views::single(42)),
        std::ranges::single_view<int>
        >{});
 
    static_assert(std::is_same<
        decltype(std::views::all(v)),
        std::ranges::ref_view<std::vector<int, std::allocator<int>>>
        >{});
 
    int a[]{1,2,3,4};
    static_assert(std::is_same<
        decltype(std::views::all(a)),
        std::ranges::ref_view<int [4]>
        >{});
 
    static_assert(std::is_same<
        decltype(std::ranges::subrange{std::begin(a)+1, std::end(a)-1}),
        std::ranges::subrange<int*, int*, std::ranges::subrange_kind(1)>
        >{});
}

Output:

0 1

[edit] See also

an empty view with no elements
(class template) (variable template) [edit]
a view that contains a single element of a specified value
(class template) (customization point object) [edit]