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
-
| 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
{
template<
typename Function, product_type T, product_type... Ts>
struct map_field;
template<typename Function, product_type T, product_type... Ts>
}
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};
{
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