KUMI v4.0.0
Flawless Fluorite
Loading...
Searching...
No Matches

◆ exclusive_scan_left

exclusive_scan_left_t kumi::exclusive_scan_left {}
inlineconstexprnodiscard

Callable object computing the exclusive prefix scan of all elements of a product type using a tail recursive call.

On record types, this function operates on the underlying values, not on the fields themselves.

Note
The first stored value is the result of the application of the function to the provided initial value and the first element of the product_type.

Header file

#include <kumi/algorithm/scan.hpp>

Call Signature

template<typename Function, product_type T, typename Value>
constexpr auto exclusive_scan_left(Function f, T && t, Value init);
constexpr exclusive_scan_left_t exclusive_scan_left
Callable object computing the exclusive prefix scan of all elements of a product type using a tail re...
Definition scan.hpp:264
template<monoid M, typename Function, product_type T, typename Value>
constexpr auto exclusive_scan_left(M && m, T && t);

Parameters

  • m: Monoid callable function to apply
  • f: Binary callable function to apply
  • t: Product Type to operate on
  • init: Optional initial value of the scan

Return value

  • A tuple of prefix partial accumulations where each element 'I' equals f( f( f(init, get<0>(t)), ...), get<I-1>(t))

Helper type

template<typename Function, kumi::concepts::product_type T, typename Value = void> struct exclusive_scan_left
{
using type =
decltype(kumi::exclusive_scan_left(std::declval<Function>(), std::declval<T>(), std::declval<Value>()));
};
template<typename Function, kumi::concepts::product_type T> struct exclusive_scan_left<Function, T>
{
using type = decltype(kumi::exclusive_scan_left(std::declval<Function>(), std::declval<T>()));
};
template<typename Function, kumi::concepts::product_type T, typename Value = void>
using exclusive_scan_left_t = typename kumi::result::exclusive_scan_left<Function, T, Value>::type;

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

Examples

Tuple

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
auto t = kumi::tuple{2.,1,short{55},'z'};
auto output = kumi::exclusive_scan_left( [](auto acc, auto elt)
{
return acc + sizeof(elt);
}
, t
, std::size_t{42}
);
std::cout << output << "\n";
auto u = kumi::tuple{1,3,2,4,0,5,9,6,7};
}
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
Fixed-size collection of heterogeneous values.
Definition tuple.hpp:33

Record

#include <kumi/kumi.hpp>
#include <iostream>
int main()
{
using namespace kumi::literals;
auto r = kumi::record{"a"_id = 2.,"b"_id = 1,"c"_id = short{55},"d"_id = 'z'};
auto output = kumi::exclusive_scan_left( [](auto acc, auto elt)
{
return acc + sizeof(elt);
}
, r
, std::size_t{42}
);
std::cout << output << "\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};
}
Fixed-size collection of heterogeneous tagged fields, tags are unique.
Definition record.hpp:36