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

◆ for_each_field()

template<typename Function , record_type Tuple, record_type... Tuples>
requires ( compatible_product_types<std::remove_cvref_t<Tuple>, std::remove_cvref_t<Tuples>...> )
constexpr void kumi::for_each_field ( Function  f,
Tuple &&  t,
Tuples &&...  ts 
)
inlineconstexpr

Applies the Callable object f on each element of a kumi::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/or ts and a kumi::field_capture.
Parameters
fCallable object to be invoked
tkumi::record_type whose elements to be used as arguments to f
tsOther kumi::record_type whose elements to be used as arguments to f
See also
kumi::for_each

Example

#include <kumi/kumi.hpp>
#include <string_view>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto t = kumi::record{"a"_f = 1, "b"_f = 2.3, "c"_f = 0.43f };
kumi::for_each_field( [](kumi::str name, auto& m)
{
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, Tuple &&t, Tuples &&... ts)
Applies the Callable object f on each element of a kumi::record_type and its field.
Definition for_each.hpp:129
Fixed-size collection of heterogeneous fields necessarily named, names are unique.
Definition traits.hpp:366
Static string used to create named fields.
Definition str.hpp:25