Callable object performing a tree-like reduction of all elements of a product type.
On record types, this function operates on the underlying values, not on the fields themselves.
- Note
- For associative operations, this produces the same result as a left or right fold, but have different intermediate evaluation order.
inline constexpr
#include <kumi/algorithm/reduce.hpp>
template<monoid M, product_type T>
constexpr auto reduce(M && m, T && t);
constexpr reduce_t reduce
Callable object performing a tree-like reduction of all elements of a product type.
Definition reduce.hpp:232
template<monoid M, product_type T, typename V>
constexpr auto reduce(M && m, T && t, V init);
- m: Monoid callable function to apply
- t: Product Type to reduce
- init: Optional initial value of the reduction.
The result of reducing the elements of `t` by `m`, recursively combining elements in a tree structure.
namespace kumi::result
{
template<mono
id M, product_type T>
struct reduce;
template<monoid M, product_type T>
template<mono
id M, product_type T,
typename Value>
struct reduce;
template<monoid M, product_type T, typename Value>
}
Computes the return type of a call to kumi::reduce
#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
}
constexpr kumi::function::boolean_and bit_and
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the logical and oper...
Definition monoid.hpp:152
constexpr kumi::function::boolean_or bit_or
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the logical or opera...
Definition monoid.hpp:161
constexpr kumi::function::numeric_add plus
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the addition.
Definition monoid.hpp:134
constexpr kumi::function::numeric_prod multiplies
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the multiplication.
Definition monoid.hpp:143
constexpr kumi::function::boolean_xor bit_xor
Forms a binary monoid callable that can be used in kumi::algoritm. It represents the logical xor oper...
Definition monoid.hpp:170
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33
#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto r1 =
kumi::record{
"a"_id = 14,
"b"_id =
short{7},
"c"_id = 255ULL};
auto r2 =
kumi::record{
"a"_id = 1 ,
"b"_id =
short{8},
"c"_id =
' ',
"d"_id = 4ULL};
auto r3 =
kumi::record{
"a"_id = 3,
"b"_id =
short{23},
"c"_id =
'\t'};
auto r4 =
kumi::record{
"a"_id = 2.,
"b"_id = 5,
"c"_id =
short{3},
"d"_id =
'\4'};
auto r5 =
kumi::record{
"a"_id = 2.,
"b"_id = 1,
"c"_id =
short{55},
"d"_id =
' '};
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36