--- nono/lib/fixedqueue.h 2026/04/29 17:05:26 1.1.1.10 +++ nono/lib/fixedqueue.h 2026/04/29 17:05:52 1.1.1.12 @@ -111,6 +111,10 @@ class FixedQueue final : private std::ve // XXX 範囲チェックすべきだがとりあえず return (*this)[(start + idx) % capacity]; } + // 最新の要素を覗き見る。 + T PeekLatest() const { + return Peek(Length() - 1); + } // 要素数を返す constexpr uint Capacity() const { @@ -130,6 +134,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 {}; // 現在有効な長さ