KUMI v3.1.0
Exquisite Epidote
Loading...
Searching...
No Matches

◆ for_each()

template<typename Function, concepts::product_type T, concepts::product_type... Ts>
requires (concepts::compatible_product_types<T, Ts...>)
void kumi::for_each ( Function f,
T && t,
Ts &&... ts )
inlineconstexpr

Applies the Callable object f on each element of a product type. f is applied on the values if the given product_type is a record type.

Note
This function does not take part in overload resolution if f can't be applied to the elements of t and/or ts, or if the product type are not compatible.
See also
compatible_product_types.
Parameters
fCallable object to be invoked
tProduct type whose elements are used as arguments to f
tsOther product types whose elements are used as arguments to f
See also
kumi::for_each_index
kumi::for_each_field

Examples:

Tuple:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto t = kumi::tuple{ 1, 2.3, 0.43f };
kumi::for_each( [](auto& m) { m *= 10; }
, t
);
std::cout << t << "\n";
}
constexpr void for_each(Function f, T &&t, Ts &&... ts)
Applies the Callable object f on each element of a product type. f is applied on the values if the gi...
Definition for_each.hpp:36
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 = 2.3, "c"_id = 0.43f };
kumi::for_each( [](auto& m) { m *= 10; }
, t
);
std::cout << t << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36