diff --git a/include/lol/private/base/narray.h b/include/lol/private/base/narray.h index eebe06d6..0ac52600 100644 --- a/include/lol/private/base/narray.h +++ b/include/lol/private/base/narray.h @@ -25,6 +25,10 @@ namespace lol { +// +// Common base class for narray and narray_view +// + template class [[nodiscard]] narray_base { @@ -77,6 +81,17 @@ public: return data()[offset_helper(indices, std::make_index_sequence{})]; } + // Use CRTP to access data() from the child class + inline value_type *data() + { + return static_cast(this)->data(); + } + + inline value_type const *data() const + { + return static_cast(this)->data(); + } + protected: template inline size_t size_helper(std::index_sequence) const @@ -99,20 +114,28 @@ protected: } vec_t m_sizes { 0 }; +}; -private: - // Use CRTP to access data() from the child class - inline value_type *data() - { - return static_cast(this)->data(); - } - inline value_type const *data() const - { - return static_cast(this)->data(); - } -}; +// +// C++11 iterators +// +template +T *begin(narray_base &a) { return a.data(); } + +template +T *end(narray_base &a) { return a.data() + a.size(); } + +template +T const *begin(narray_base const &a) { return a.data(); } + +template +T const *end(narray_base const &a) { return a.data() + a.size(); } + +// +// Array view +// template class [[nodiscard]] narray : public narray_base> @@ -166,6 +189,10 @@ private: template using array2d = narray; template using array3d = narray; +// +// Array view +// + template class [[nodiscard]] narray_view : public narray_base> { @@ -174,7 +201,7 @@ public: template inline narray_view(narray_base &other) - : m_data(&other[0]) + : m_data(other.data()) { this->m_sizes = vec_t(other.sizes()); }