From 5da4fc096b32a606608987b53f6cfcd752c13205 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 2 Oct 2022 17:53:28 -0400 Subject: [PATCH] Add missing TAverage.hpp Former-commit-id: e8133e9476fa9f827987674d6217604bb7766e7b --- include/Kyoto/TAverage.hpp | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 include/Kyoto/TAverage.hpp diff --git a/include/Kyoto/TAverage.hpp b/include/Kyoto/TAverage.hpp new file mode 100644 index 00000000..71f92258 --- /dev/null +++ b/include/Kyoto/TAverage.hpp @@ -0,0 +1,29 @@ +#ifndef _TAVERAGE_HPP +#define _TAVERAGE_HPP + +#include "types.h" + +#include "rstl/optional_object.hpp" +#include "rstl/vector.hpp" + +template < typename T > +class TAverage : rstl::vector< T > { +public: + TAverage() {} + TAverage(int capacity, const T& value); + void AddValue(const T& value) { + push_back(value); + for (int i = size() - 1; i > 0; --i) { + operator[](i) = operator[](i - 1); + } + operator[](0) = value; + } + rstl::optional_object< T > GetAverage() const; +}; + +template < typename T > +TAverage< T >::TAverage(int capacity, const T& value) { + resize(capacity, value); +} + +#endif