diff --git a/legacy/lol/math/arraynd.h b/legacy/lol/math/arraynd.h index fc0f08b8..1aa7d9c9 100644 --- a/legacy/lol/math/arraynd.h +++ b/legacy/lol/math/arraynd.h @@ -24,9 +24,9 @@ // XXX: This file is in lol/math/ instead of lol/base/ because it uses vec_t. // -#include #include // vec_t +#include // std::vector #include // std::min #include // memset #include @@ -96,12 +96,11 @@ private: }; -template -class [[nodiscard]] arraynd : protected array +template +class [[nodiscard]] arraynd { public: - typedef array super; - typedef typename super::element_t element_t; + typedef T element_t; inline arraynd() = default; @@ -131,7 +130,7 @@ public: int pos = 0; for (auto inner_initializer : initializer) - inner_initializer.fill_values(&super::operator[](0), pos++, &m_sizes[N - 2]); + inner_initializer.fill_values(&m_data[0], pos++, &m_sizes[N - 2]); } /* Access elements directly using an vec_t index */ @@ -140,13 +139,13 @@ public: size_t n = pos[N - 1]; for (size_t i = N - 1; i > 0; --i) n = pos[i - 1] + m_sizes[i] * n; - return super::operator[](n); + return m_data[n]; } inline element_t & operator[](vec_t const &pos) { return const_cast( - const_cast const&>(*this)[pos]); + const_cast const&>(*this)[pos]); } /* If int != size_t, access elements directly using an ivec2, @@ -157,14 +156,14 @@ public: size_t n = pos[N - 1]; for (size_t i = N - 1; i > 0; --i) n = pos[i - 1] + m_sizes[i] * n; - return super::operator[](n); + return m_data[n]; } template::value, int>::type> inline element_t & operator[](vec_t const &pos) { return const_cast( - const_cast const&>(*this)[pos]); + const_cast const&>(*this)[pos]); } /* Proxy to access slices */ @@ -194,7 +193,7 @@ public: inline typename std::enable_if::type const & operator[](size_t pos) const { - return m_array.super::operator[](m_index + pos * m_accumulator); + return m_array.m_data[m_index + pos * m_accumulator]; } /* Accessors for the non-const version of the proxy */ @@ -210,7 +209,7 @@ public: inline typename std::enable_if::type & operator[](size_t pos) { - return m_array.super::operator[](m_index + pos * m_accumulator); + return m_array.m_data[m_index + pos * m_accumulator]; } private: @@ -219,14 +218,14 @@ public: }; /* Access addressable slices, allowing for array[i][j][...] syntax. */ - inline slice const> operator[](size_t pos) const + inline slice const> operator[](size_t pos) const { - return slice const>(*this, pos, m_sizes[0]); + return slice const>(*this, pos, m_sizes[0]); } - inline slice> operator[](size_t pos) + inline slice> operator[](size_t pos) { - return slice>(*this, pos, m_sizes[0]); + return slice>(*this, pos, m_sizes[0]); } /* Resize the array. @@ -247,18 +246,11 @@ public: return vec_t(this->m_sizes); } - inline vec_t size_s() const - { - return this->m_sizes; - } - public: - inline element_t *data() { return super::data(); } - inline element_t const *data() const { return super::data(); } - inline int count() const { return super::count(); } - inline int bytes() const { return super::bytes(); } - inline size_t count_s() const { return super::count_s(); } - inline size_t bytes_s() const { return super::bytes_s(); } + inline element_t *data() { return m_data.data(); } + inline element_t const *data() const { return m_data.data(); } + inline int total_size() const { return m_data.size(); } + inline size_t bytes() const { return total_size() * sizeof(element_t); } private: inline void resize_data(element_t e = element_t()) @@ -270,14 +262,15 @@ private: for (int i = 0; i < N; ++i) total_size *= m_sizes[i]; - this->array::resize(total_size, e); + m_data.resize(total_size, e); } + std::vector m_data; vec_t m_sizes { 0 }; }; -template using array2d = arraynd<2, T...>; -template using array3d = arraynd<3, T...>; +template using array2d = arraynd<2, T>; +template using array3d = arraynd<3, T>; } /* namespace lol */