diff --git a/src/history.h b/src/history.h index 17ab3481..2ec2b791 100644 --- a/src/history.h +++ b/src/history.h @@ -76,9 +76,12 @@ class StatsEntry { T entry; public: - void operator=(const T& v) { entry = v; } - T* operator&() { return &entry; } - T* operator->() { return &entry; } + StatsEntry& operator=(const T& v) { + entry = v; + return *this; + } + T* operator&() { return &entry; } + T* operator->() { return &entry; } operator const T&() const { return entry; } void operator<<(int bonus) { @@ -92,28 +95,53 @@ class StatsEntry { } }; +template +struct StatsHelper; + // Stats is a generic N-dimensional array used to store various statistics. // The first template parameter T is the base type of the array, and the second // template parameter D limits the range of updates in [-D, D] when we update // values with the << operator, while the last parameters (Size and Sizes) // encode the dimensions of the array. -template -struct Stats: public std::array, Size> { - using stats = Stats; +template +class Stats { + using child_type = typename StatsHelper::child_type; + using array_type = std::array; + array_type data; + + public: + using size_type = typename array_type::size_type; + + auto& operator[](size_type index) { return data[index]; } + const auto& operator[](size_type index) const { return data[index]; } + + auto begin() { return data.begin(); } + auto end() { return data.end(); } + auto begin() const { return data.cbegin(); } + auto end() const { return data.cend(); } + auto cbegin() const { return data.cbegin(); } + auto cend() const { return data.cend(); } void fill(const T& v) { - - // For standard-layout 'this' points to the first struct member - assert(std::is_standard_layout_v); - - using entry = StatsEntry; - entry* p = reinterpret_cast(this); - std::fill(p, p + sizeof(*this) / sizeof(entry), v); + for (auto& ele : data) + { + if constexpr (sizeof...(Sizes) == 0) + ele = v; + else + ele.fill(v); + } } }; -template -struct Stats: public std::array, Size> {}; +template +struct StatsHelper { + using child_type = Stats; +}; + +template +struct StatsHelper { + using child_type = StatsEntry; +}; // In stats table, D=0 means that the template parameter is not used enum StatsParams { diff --git a/src/movepick.cpp b/src/movepick.cpp index 96f03171..540024b7 100644 --- a/src/movepick.cpp +++ b/src/movepick.cpp @@ -18,7 +18,6 @@ #include "movepick.h" -#include #include #include