Namespaces
Variants
Views
Actions

std::ranges::chunk_view<V>::chunk_view

From cppreference.com
< cpp‎ | ranges‎ | chunk view
 
 
Ranges library
Range access
Range conversions
(C++23)
Range primitives



Dangling iterator handling
Range concepts
Views

Factories




Adaptors
Range adaptor objects
Range adaptor closure objects
Helper items
 
std::ranges::chunk_view
Member functions
chunk_view::chunk_view
(C++23)
For input_ranges only
Deduction guides
outer_iterator
outer_iterator::value_type
inner_iterator
For forward_ranges
iterator
 
constexpr explicit chunk_view( V base, ranges::range_difference_t<V> n );
(since C++23)

Constructs a chunk_view, initializing the underlying data members:

  • move constructs the base_ with std::move(base),
  • initializes the "chunk size" n_ with n.

In addition, if V models exactly the input_range, the constructor initializes the following exposition-only data members:

The behavior is undefined if n is less than or equal to 0.

[edit] Parameters

base - the adapted view
n - the chunk size

[edit] Example

A link to evaluate the example: Compiler Explorer.

#include <algorithm>
#include <iostream>
#include <ranges>
 
int main()
{
    auto i = std::views::iota(0, 10);
    auto w = std::ranges::chunk_view(i, 4);
 
    std::ranges::for_each(w, [](auto const v)
    {
        for (auto e : v)
            std::cout << e << ' ';
        std::cout << '\n';
    });
}

Output:

0 1 2 3
4 5 6 7
8 9