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

◆ for_each_field()

template<typename Function, concepts::record_type R, concepts::record_type... Rs>
requires (concepts::compatible_product_types<R, Rs...>)
void kumi::for_each_field ( Function f,
R && r,
Rs &&... rs )
inlineconstexpr

Applies the Callable object f on each element of a record type and its field.

Note
This function does not take part in overload resolution if f can't be applied to the elements of t and those of ts, or if the product types are not compatible.
See also
compatible_product_types

This function can only be applied to record types. The function needs to be defined to handle types modeling kumi::concepts::field.

Parameters
fCallable object to be invoked
rRecord type whose fields are used as arguments to f
rsOther record types whose elements are used as arguments to f
See also
kumi::for_each
kumi::for_each_index

Example:

#include <kumi/kumi.hpp>
#include <string_view>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto t = kumi::record{"a"_id = 1, "b"_id = 2.3, "c"_id = 0.43f };
{
if(name.as<std::string_view>().ends_with("a"))
m += 10;
else if (name == "c")
m = (m * 100) -1;
else
m *= 10;
}
, t
);
std::cout << t << "\n";
}
constexpr void for_each_field(Function f, R &&r, Rs &&... rs)
Applies the Callable object f on each element of a record type and its field.
Definition for_each.hpp:119
Compile-time text based identifier.
Definition identifier.hpp:162
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36
Static string used to create named fields.
Definition str.hpp:24