KUMI v4.0.0
Flawless Fluorite
Loading...
Searching...
No Matches

◆ chunks

template<std::size_t N>
tiles_t<N, N> kumi::chunks {}
inlineconstexprnodiscard

Callable object creating a tuple of product types, each containing N consecutive elements from t. Chunks starts at 0 and advance by N element each time.

On record types, this function operates on elements as if they were ordered. The considered order is the order of declaration.

Note
Chunks behaves like paving tiles: each inner product_type is a tile over t starting at index chunk_size * tile_number + 1. The last chunk will be smaller if the size of the product_type is not a multiple of the chunk size.

Header file

#include <kumi/algorithm/apply.hpp>

Call Signature

template<std::size_t N, product_type T>
constexpr auto windows<N>(T && t);
constexpr tiles_t< N, 1 > windows
Callable object creating a tuple of product types, each containing N consecutive elements from t....
Definition tiler.hpp:157

Template Parameters

  • N: Size of the chunks to generate

Parameters

  • t: Product Type from which to extract the chunks

Return value

  • A tuple of product types, each containing N consecutive elements of t

Helper type

template<std::size_t N, kumi::concepts::product_type T> struct chunks
{
using type = decltype(kumi::chunks<N>(std::declval<T>()));
};
template<std::size_t N, kumi::concepts::product_type T> using chunks_t = typename kumi::result::chunks<N, T>::type;

Computes the return type of a call to kumi::chunks

Examples

Tuple

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto t = kumi::tuple{1, 'y', 3.f, short{55}, -8, 66., "Pete"};
auto c = kumi::chunks<2>(t);
std::cout << " Standard Chunks " << "\n";
std::cout << c << "\n";
kumi::for_each([&](auto tile)
{
get<0>(tile)++;
},c);
std::cout << t << "\n";
std::cout << " Chunks with references " << "\n";
std::cout << c2 << "\n";
kumi::for_each([&](auto tile)
{
get<0>(tile)++;
},c2);
std::cout << t << "\n";
}
constexpr tiles_t< N, N > chunks
Callable object creating a tuple of product types, each containing N consecutive elements from t....
Definition tiler.hpp:217
constexpr for_each_t for_each
Callable object applying the Callable object f on each element of a product type.
Definition for_each.hpp:126
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto t = kumi::record{"a"_id = 1, "b"_id = 'y', "c"_id = 3.f, "d"_id = short{55}
, "e"_id = -8, "f"_id = 66., "g"_id = "Pete"};
auto c = kumi::chunks<2>(t);
std::cout << " Standard Chunks " << "\n";
std::cout << c << "\n";
kumi::for_each([&](auto tile)
{
},c);
std::cout << t << "\n";
std::cout << " Chunks with references " << "\n";
std::cout << c2 << "\n";
kumi::for_each([&](auto tile)
{
},c2);
std::cout << t << "\n";
}
decltype(auto) constexpr get(record< Ts... > &r) noexcept
Extracts the Ith field from a kumi::record.
Definition record.hpp:618
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36
constexpr auto values_of(T &&t) noexcept
Extracts the values of the fields of a kumi::product_type.
Definition tuple.hpp:772