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

◆ map_index()

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

Applies the Callable object f on each tuples' elements and their indexes.

Applies the given function to all the tuples passed as arguments along with their indexes and stores the result in another tuple, keeping the original elements order.

Note
Does not participate in overload resolution if tuples' size are not equal or if f can't be called on each tuple's elements and their indexes.
Parameters
fCallable function to apply
t0Product type to operate on
othersProduct types to operate on
Returns
The tuple of f calls results.

Helper type

namespace kumi::result
{
template<typename Function, product_type T, product_type... Ts> struct map_index;
template<typename Function, product_type T, product_type... Ts>
using map_index_t = typename map_index<Function,T>::type;
}
constexpr auto map_index(Function f, T &&t0, Ts &&... others)
Applies the Callable object f on each tuples' elements and their indexes.
Definition map.hpp:112

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

See also
kumi::map
kumi::map_field

Example:

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