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
-
| f | Callable function to apply |
| t0 | Record to operate on |
| others | Records to operate on |
- Returns
- The record of
f calls results.
Helper type
namespace kumi::result
{
using map_field_t = typename map_field<Function,Tuple>::type;
}
Concept specifying a type follows the Product Type semantic.
Definition concepts.hpp:33
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};
{
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