Computes the generalized combination of all elements using a tail recursive call.
- Parameters
-
| f | Binary callable function to apply |
| t | Product type to operate on |
| init | Optional initial value of the fold |
- Returns
- The value of
f( f( f(init, get<0>(t)), ...), get<N-1>(t))
Helper type
namespace kumi::result
{
template<
typename Function, product_type T,
typename Value>
struct fold_left;
template<typename Function, product_type T, typename Value>
using fold_left_t = typename fold_left<Function,T,Value>::type;
}
constexpr auto fold_left(Function f, T &&t, Value init)
Computes the generalized combination of all elements using a tail recursive call.
Definition fold.hpp:39
Computes the return type of a call to kumi::fold_left
Examples:
#include <kumi/kumi.hpp>
#include <iostream>
#include <vector>
int main()
{
auto output =
kumi::fold_left( [](
auto a,
auto m) { a.push_back(
sizeof(m));
return a; }
, t
, std::vector<std::size_t>{}
);
for(auto s : output) std::cout << s << " ";
std::cout << "\n";
{
std::cout << '(' << acc << ',' << e << ")\n";
return (e <acc) ? e : acc;
}
, u
)
<< "\n";
}
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:37
#include <kumi/kumi.hpp>
#include <iostream>
#include <vector>
int main()
{
using namespace kumi::literals;
auto t =
kumi::record{
"a"_f = 2.,
"b"_f = 1,
"c"_f =
short{55},
"d"_f =
'z'};
auto output =
kumi::fold_left( [](
auto a,
auto m) { a.push_back(
sizeof(m));
return a; }
, t
, std::vector<std::size_t>{}
);
for(auto s : output) std::cout << s << " ";
std::cout << "\n";
auto u =
kumi::record{
"a"_f = 1,
"b"_f = 3,
"c"_f = 2,
"d"_f = 4,
"e"_f = 0,
"f"_f = 5,"g"_f = 9,"h"_f = 6,"i"_f = 7};
{
std::cout << '(' << acc << ',' << e << ")\n";
return (e <acc) ? e : acc;
}
, u
)
<< "\n";
}
Fixed-size collection of heterogeneous fields necessarily named, names are unique.
Definition traits.hpp:366