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

◆ map_field()

template<record_type Tuple, typename Function , sized_product_type< size< Tuple >::value >... Tuples>
requires ( compatible_product_types<Tuple, Tuples...> )
constexpr auto kumi::map_field ( Function  f,
Tuple &&  t0,
Tuples &&...  others 
)
constexpr

Apply the Callable object f on each records' elements and their field 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 elements 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,Tuple>::type;
}
Concept specifying a type follows the Product Type semantic.
Definition concepts.hpp:33
constexpr auto map_field(Function f, Tuple &&t0, Tuples &&...others)
Apply the Callable object f on each records' elements and their field names.
Definition map.hpp:185

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

Example

#include <kumi/kumi.hpp>
#include <iostream>
using namespace kumi::literals;
int main()
{
auto lhs = kumi::record{"a"_f = 1 , "b"_f = 2 , "c"_f = 3 };
auto rhs = kumi::record{"a"_f = 2.4, "b"_f = 4.6, "c"_f = 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";
}
Fixed-size collection of heterogeneous fields necessarily named, names are unique.
Definition traits.hpp:366