Callable object computing the generalized combination of all elements using a non-tail recursive call.
On record types, this function operates on the underlying values, not on the fields themselves.
#include <kumi/algorithm/fold.hpp>
template<typename Function, product_type T, typename Value>
constexpr auto fold_right(Function && f, T && t, Value init);
constexpr fold_right_t fold_right
Callable object computing the generalized combination of all elements using a non-tail recursive call...
Definition fold.hpp:181
template<typename Function, product_type T>
- f: Binary callable function to apply
- t: Product type to operate on
- v: Optional initial value of the fold, last element is used otherwise
- The resulting value of the application of the function f(get<0>(t), f(... , f(get<N-1>(t), init))
template<
typename Function, kumi::concepts::product_type T,
typename Value =
void>
struct fold_right
{
using type =
decltype(
kumi::fold_right(std::declval<Function>(), std::declval<T>(), std::declval<Value>()));
};
template<
typename Function, kumi::concepts::product_type T>
struct fold_right<Function, T>
{
using type =
decltype(
kumi::fold_right(std::declval<Function>(), std::declval<T>()));
};
template<typename Function, kumi::concepts::product_type T, typename Value = void>
using fold_right_t = typename kumi::result::fold_right<Function, T, Value>::type;
Computes the return type of a call to kumi::fold_right
#include <kumi/kumi.hpp>
#include <iostream>
#include <vector>
int main()
{
auto output =
kumi::fold_right( [](
auto m,
auto a) { 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:33
#include <kumi/kumi.hpp>
#include <iostream>
#include <vector>
int main()
{
using namespace kumi::literals;
auto t =
kumi::record{
"a"_id = 2.,
"b"_id = 1,
"c"_id =
short{55},
"d"_id =
'z'};
auto output =
kumi::fold_right( [](
auto m,
auto a) { 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"_id = 1,
"b"_id = 3,
"c"_id = 2,
"d"_id = 4,
"e"_id = 0,
"f"_id = 5,"g"_id = 9,"h"_id = 6,"i"_id = 7};
{
std::cout << '(' << acc << ',' << e << ")\n";
return (e <acc) ? e : acc;
}
, u
)
<< "\n";
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36