#ifndef AVERAGE_H #define AVERAGE_H #include "../../Assertions.h" namespace Stats { template class Average { private: int cnt; Scalar sum; public: /** ctor */ Average() : cnt(0), sum() { ; } /** contains a valid average? */ bool isValid() const { return cnt > 0; } /** add a new value */ void add(const Scalar val) { sum += val; ++cnt; } /** get the current value */ Scalar get() const { Assert::isNot0(cnt, "add() values first!"); return sum / cnt; } }; } #endif // AVERAGE_H