template <typename ValueType, typename Impl = impl::default_accumulator<ValueType>::type>
muu::accumulator class

Determines min, max and sum of an interderminate number of values.

Template parameters
ValueType Type being accumulated.
Impl Implementation type.

For integral types the accumulator is a simple bookkeeping helper, but for floating-point types the default implementation uses Kahan summation to reduce numerical error.

Public types

using value_param = typename Impl::value_param
value_type or const value_type&, depending on size, triviality, etc.
using value_type = ValueType
The type being accumulated.

Constructors, destructors, conversion operators

accumulator() constexpr noexcept(…)
Constructs an empty accumulator.
accumulator(const value_type& sample) constexpr noexcept(…)
Constructs an accumulator with one sample.
template <typename Iter>
accumulator(Iter begin, Iter end) constexpr noexcept(…)
Constructs an accumulator with an initial range of samples.

Public functions

auto add(value_param sample) -> accumulator& constexpr noexcept(…)
Adds a new sample to the accumulator.
template <typename Iter>
auto add(Iter begin, Iter end) -> accumulator& constexpr noexcept(…)
Adds a range of values to the accumulator.
auto add(const accumulator& other) -> accumulator& constexpr noexcept
Adds the entire sample set of another Accumulator to this one.
auto empty() const -> bool constexpr noexcept
Returns true if no samples have been added to the accumulator.
auto max() const -> decltype(auto) constexpr noexcept(…)
Returns the maximum value added to the accumulator.
auto min() const -> decltype(auto) constexpr noexcept(…)
Returns the minimum value added to the accumulator.
auto operator()(value_param sample) -> accumulator& constexpr noexcept(…)
Adds a new sample to the accumulator.
auto operator()(const accumulator& other) -> accumulator& constexpr noexcept(…)
Adds the entire sample set of another Accumulator to this one.
auto sample_count() const -> size_t constexpr noexcept
Returns the number of samples added to the accumulator.
auto sum() const -> decltype(auto) constexpr noexcept(…)
Returns the sum of all values added to the accumulator.

Function documentation

template <typename ValueType, typename Impl>
template <typename Iter>
muu::accumulator::accumulator(Iter begin, Iter end) constexpr noexcept(…)

Constructs an accumulator with an initial range of samples.

Template parameters
Iter Iterator type.
Parameters
begin The beginning iterator.
end The end iterator.

template <typename ValueType, typename Impl>
accumulator& muu::accumulator::add(value_param sample) constexpr noexcept(…)

Adds a new sample to the accumulator.

Parameters
sample The sample to add.
Returns A reference to the accumulator.

template <typename ValueType, typename Impl>
template <typename Iter>
accumulator& muu::accumulator::add(Iter begin, Iter end) constexpr noexcept(…)

Adds a range of values to the accumulator.

Template parameters
Iter Iterator type.
Parameters
begin The beginning iterator.
end The end iterator.
Returns A reference to the accumulator.

template <typename ValueType, typename Impl>
accumulator& muu::accumulator::add(const accumulator& other) constexpr noexcept

Adds the entire sample set of another Accumulator to this one.

Parameters
other The other accumulator.
Returns A reference to this Accumulator.

template <typename ValueType, typename Impl>
accumulator& muu::accumulator::operator()(value_param sample) constexpr noexcept(…)

Adds a new sample to the accumulator.

Parameters
sample The sample to add.
Returns A reference to the accumulator.

template <typename ValueType, typename Impl>
accumulator& muu::accumulator::operator()(const accumulator& other) constexpr noexcept(…)

Adds the entire sample set of another Accumulator to this one.

Parameters
other The other accumulator.
Returns A reference to this accumulator.