#pragma once
#include "macro.hpp"
#include "error.hpp"
#include <array>
template <class T, uint SIZE>
class Average {
protected:
  std::array<T, SIZE> values = {};
  uint current_insertion = 0;
public:
  Average() { IFERROR( !SIZE, "Average SIZE is null"); }
  void add(T val) {
    values[current_insertion] = val;
    ++current_insertion;
    current_insertion %= values.size();
  }
  float get() const
    { return std::accumulate(values.cbegin(), values.cend(), 0.0f)
      / float(SIZE); }
};