KUMI v5.0.0
Gorgeous Garnet
Loading...
Searching...
No Matches

Callable object applying the Callable object f on each product types' elements. More...

Variables

constexpr map_t kumi::map {}

Detailed Description

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

Variable Documentation

◆ map

map_t kumi::map {}
inlineconstexprnodiscard

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.

Header file

#include <kumi/kumi.hpp>

Call Signature

namespace kumi
{
template<typename Function, concepts::product_type T, concepts::product_type... Ts>
constexpr auto map(Function && f, T && t, Ts &&... ts);
}
Concept specifying a type follows the Product Type semantic.
Definition concepts.hpp:77
constexpr map_t map
Definition map.hpp:156
Main KUMI namespace.
Definition algorithm.hpp:11

Parameters

  • f: Callable object to apply
  • t: Product Type to operate on
  • ts: Other Product Types to operate on

Return value

Helper type

template<typename Function,
kumi::concepts::product_type T,
kumi::concepts::sized_product_type<kumi::size_v<T>>... Ts>
template<typename Function,
kumi::concepts::product_type T,
kumi::concepts::sized_product_type<kumi::size_v<T>>... Ts>
struct map
{
using type = kumi::result::map_t<Function, T, Ts...>;
};

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

See also
kumi::map_index
kumi::map_field

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:35
  • 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 fields with distinct labels.
    Definition record.hpp:36