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

◆ map_field()

template<concepts::record_type T, typename Function, concepts::sized_product_type< size_v< T > >... Ts>
requires (concepts::compatible_product_types<T, Ts...>)
auto kumi::map_field ( Function f,
T && t0,
Ts &&... others )
inlinenodiscardconstexpr

Applies the Callable object f on each records' fields and their associated names.

Applies the given function to all the records passed as arguments along with their names and stores the result in another records, keeping the original elements order.

Note
Does not participate in overload resolution if records' size are not equal or if f can't be called on each record's fields and their names.
Parameters
fCallable function to apply
t0Record to operate on
othersRecords to operate on
Returns
The record of f calls results.

Helper type

namespace kumi::result
{
template<typename Function, product_type T, product_type... Ts> struct map_field;
template<typename Function, product_type T, product_type... Ts>
using map_field_t = typename map_field<Function,T>::type;
}
constexpr auto map_field(Function f, T &&t0, Ts &&... others)
Applies the Callable object f on each records' fields and their associated names.
Definition map.hpp:163

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

See also
kumi::map
kumi::map_index

Example:

#include <kumi/kumi.hpp>
#include <iostream>
using namespace kumi::literals;
int main()
{
auto lhs = kumi::record{"a"_id = 1 , "b"_id = 2 , "c"_id = 3 };
auto rhs = kumi::record{"a"_id = 2.4, "b"_id = 4.6, "c"_id = 6.8};
auto res = kumi::map_field( [](auto name, auto l, auto r)
{
if (name == "a") return l + r;
else return 1000*+(l*r);
}
, lhs, rhs
);
std::cout << res << "\n";
}
Compile-time text based identifier.
Definition identifier.hpp:162
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36