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

◆ map()

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

Applies the Callable object f on each product types' elements.

Applies the given function to all the product types passed as arguments and stores the result in another product type, keeping the original elements order. On records, the order is determined via the order of definition of the fields.

Note
Does not participate in overload resolution if product types' size are not equal or if f can't be called on each product type's elements. All product type must either be record types or product types, mixing is not supported.
Parameters
fCallable function to apply
t0Product Type to operate on
othersProduct Types to operate on
Returns
The product type of f calls results.

Helper type

namespace kumi::result
{
template<typename Function, product_type T, product_type... Ts> struct map;
template<typename Function, product_type T, product_type... Ts>
using map_t = typename map<Function,T>::type;
}
constexpr auto map(Function f, T &&t0, Ts &&... others)
Applies the Callable object f on each product types' elements.
Definition map.hpp:51

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

Examples:

Tuple:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto lhs = kumi::tuple{1,2,3};
auto rhs = kumi::tuple{2.5,3.6,4.7};
auto res = kumi::map( [](auto l, auto r) { return l*r; }, lhs, rhs);
std::cout << res << "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record:

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto lhs = kumi::record{"a"_id = 1,"b"_id = 2,"c"_id = 3};
auto rhs = kumi::record{"a"_id = 2.5,"b"_id = 3.6,"c"_id = 4.7};
auto res = kumi::map( [](auto l, auto r) { return l*r; }, lhs, rhs);
std::cout << res << "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36