--- nono/lib/fixedqueue.h 2026/04/29 17:05:26 1.1.1.10 +++ nono/lib/fixedqueue.h 2026/04/29 17:05:47 1.1.1.11 @@ -130,6 +130,21 @@ class FixedQueue final : private std::ve } } + // 移動平均値を返す。(T が数値型のときに限る) + T GetMovingAverage() const + { + static_assert(std::is_arithmetic::value, "T must be arithmetic"); + + if (Empty()) { + return 0; + } + T sum = 0; + for (uint i = 0; i < length; i++) { + sum += Peek(i); + } + return sum / length; + } + private: uint start {}; // 開始位置 uint length {}; // 現在有効な長さ