faunus
Public Member Functions | Protected Attributes | Friends | List of all members
Faunus::Average< value_type, counter_type > Class Template Reference

Class to collect averages. More...

#include <average.h>

Inheritance diagram for Faunus::Average< value_type, counter_type >:
Inheritance graph
[legend]
Collaboration diagram for Faunus::Average< value_type, counter_type >:
Collaboration graph
[legend]

Public Member Functions

void clear ()
 Clear all data.
 
bool empty () const
 True if empty.
 
auto size () const
 Number of samples.
 
auto avg () const
 Average.
 
 operator value_type () const
 Static cast operator.
 
bool operator< (const Average &other) const
 Compare means.
 
 operator bool () const
 Check if not empty.
 
void add (const value_type value)
 Add value to average. More...
 
Averageoperator+= (const value_type value)
 Add value to average. More...
 
bool operator== (const Average &other) const
 
Averageoperator= (const value_type value)
 Clear and assign a new value.
 
auto operator+ (const Average &other) const
 Merge two averages with correct weights. More...
 
Averageoperator<< (std::istream &stream)
 
template<class Archive >
void serialize (Archive &archive)
 

Protected Attributes

counter_type number_of_samples = 0
 number of values in average
 
value_type value_sum = 0.0
 Sum of all recorded values.
 

Friends

std::ostream & operator<< (std::ostream &stream, const Average &average)
 

Detailed Description

template<std::floating_point value_type = double, std::unsigned_integral counter_type = unsigned long int>
class Faunus::Average< value_type, counter_type >

Class to collect averages.

Todo:
replace static assert w.

concept in c++20

Member Function Documentation

◆ add()

template<std::floating_point value_type = double, std::unsigned_integral counter_type = unsigned long int>
void Faunus::Average< value_type, counter_type >::add ( const value_type  value)
inline

Add value to average.

Parameters
valueValue to add
Exceptions
Ifoverflow in either the counter, or sum of squared values

◆ operator+()

template<std::floating_point value_type = double, std::unsigned_integral counter_type = unsigned long int>
auto Faunus::Average< value_type, counter_type >::operator+ ( const Average< value_type, counter_type > &  other) const
inline

Merge two averages with correct weights.

Parameters
otherOther average
Returns
Merged average
Exceptions
ifnumeric overflow

◆ operator+=()

template<std::floating_point value_type = double, std::unsigned_integral counter_type = unsigned long int>
Average& Faunus::Average< value_type, counter_type >::operator+= ( const value_type  value)
inline

Add value to average.

Parameters
valueValue to add
Exceptions
Ifoverflow in either the counter, or sum of squared values

The documentation for this class was generated from the following file: