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

◆ apply()

template<typename Function , product_type Tuple>
requires _::supports_apply<Function, Tuple>
constexpr decltype(auto) kumi::apply ( Function &&  f,
Tuple &&  t 
)
inlineconstexprnoexcept

Invoke the Callable object f with a product_type of arguments. f is applied on the values if the given product_type is a kumi::record.

Parameters
fCallable object to be invoked
tkumi::product_type whose elements to be used as arguments to f
Returns
The value returned by f.

Helper type

namespace kumi::result
{
template<typename Function, product_type Tuple> struct apply;
template<typename Function, product_type Tuple>
using apply_t = typename apply<Function,Tuple>::type;
}
constexpr decltype(auto) apply(Function &&f, Tuple &&t) noexcept(_::supports_nothrow_apply< Function &&, Tuple && >)
Invoke the Callable object f with a product_type of arguments. f is applied on the values if the give...
Definition apply.hpp:65

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

Example

#include <kumi/kumi.hpp>
#include <iostream>
template<kumi::product_type Tuple>
void print(std::ostream& os, Tuple const& t)
{
(
[&os](auto const&... args)
{
os << '[';
std::size_t n{0};
((os << args << (++n != kumi::size<Tuple>::value ? ", " : "")), ...);
os << ']';
}, t
);
os << '\n';
}
int main()
{
auto t = kumi::tuple{1,2.,3.f};
// Simple operation: sum all values
std::cout << kumi::apply( [](auto... m) { return (m + ...); }, t) << "\n";
// Advanced usage
print(std::cout, t);
}
Computes the number of elements of a kumi::product_type.
Definition traits.hpp:80
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:37
#include <kumi/kumi.hpp>
#include <iostream>
template<kumi::record_type Record>
void print(std::ostream& os, Record const& t)
{
(
[&os](auto const&... args)
{
os << '[';
std::size_t n{0};
((os << args << (++n != kumi::size<Record>::value ? ", " : "")), ...);
os << ']';
}, t
);
os << '\n';
}
int main()
{
using namespace kumi::literals;
auto r = kumi::record{"x"_f = 1, "y"_f = 2., "z"_f = 3.f};
// Simple operation: sum all values
std::cout << kumi::apply( [](auto... m) { return (m + ...); }, r) << "\n";
// Advanced usage
print(std::cout, r);
}
Fixed-size collection of heterogeneous fields necessarily named, names are unique.
Definition traits.hpp:366