std::ranges...::chunk_view(3)
π NAME π
std::ranges::chunk_view::chunk_view β okay bestie, this is the constructor for std::ranges::chunk_view::chunk_view, straight outta the C++ Standard Libary man pages. Yes, the name is doubled, itβs giving βI have two names and Iβm using both,β but we respect it. π
β¨ Synopsis β¨
The signature is literally this, no cap:
constexpr explicit chunk_view( V base, ranges::range_difference_t<V> n );
(since C++23) β we love a modern era.
So what does it do? It constructs a chunk_view, and it initializes the underlying data members like the good little constructor it is:
- move constructs
base_withstd::move(base), - initializes the
"chunk size"n_withn.
And plot twist π«’ β in addition, if V models exactly the input_range, the constructor also initializes these exposition-only data members:
- initializes
remainder_with0, - default-initializes
current_.
π© Behavior check, bestie: the behavior is undefined ifnis less than or equal to0. That is not a vibe. Do not do it.
πΈ Parameters πΈ
baseβ the adapted view. The thing being adapted, the main character of this operation.nβ the chunk size. How many elements per chunk, periodt.
π» Example π»
Run this code, itβs cute:
// 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 π
It prints this, slay:
0 1 2 3
4 5 6 7
8 9
Thatβs the whole page, bestie π«Ά β source: http://cppreference.com, dated 2024.06.10, for std::ranges...::chunk_view(3). mwah πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms