Skip to content

strata::reducer_forΒΆ

Part of Reductions.

concept

template<typename R, typename T>
concept strata::reducer_for = requires { typename detail::accumulator_t<R, T>; } &&
 (detail::identity_reducer<R, T> || detail::seeded_reducer<R, T>) &&
 requires(const R& reducer, const T& value, detail::accumulator_t<R, T> acc) {
 { reducer.accumulate(acc, value) } -> std::same_as<detail::accumulator_t<R, T>>;
 { reducer.combine(acc, acc) } -> std::same_as<detail::accumulator_t<R, T>>;
 reducer.finalize(acc, std::size_t{});
 }

A reducer R that can reduce values of type T.

A reduction is described by a reducer: a type with these members, over values of type T.

  • accumulator<T>: the alias of what it keeps while values come in.
  • identity<T>(): where it starts, the result of no values at all.
  • init(first): instead of an identity, where it starts from the first value. That value is then accumulated once more, which only an idempotent reducer may allow (min(x, x) is x), and no values at all are a precondition violation.
  • accumulate(acc, value): the accumulator with one value more.
  • combine(acc, acc): two accumulators of separate values as one, for walks that keep several.
  • finalize(acc, n): the result, once the number of values n is known.

The reducers provided are Sum, Product, Min, Max, Mean, All, Any and Count.