std::ranges::chunk_view<V>::chunk_view
From cppreference.com
< cpp | ranges | chunk view
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Ranges library
(C++23)(C++23)
(C++26)(C++26)
(C++23)(C++23)
(C++26)(C++26)
(C++26)(C++26)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
(C++23)(C++23)
std::ranges::chunk_view
constexpr explicit chunk_view( V base, ranges::range_difference_t <V> n );
(since C++23)
Constructs a chunk_view
, initializing the underlying data members:
In addition, if V
models exactly the input_range
, the constructor initializes the following exposition-only data members:
- initializes the
remainder_
with 0, - default-initializes the
current_
.
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
Run this code
#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