From 357d9c3f9dd209b1833c571333efa6417a43c8f9 Mon Sep 17 00:00:00 2001 From: Ryan Hill Date: Wed, 14 Feb 2024 12:16:03 -0800 Subject: [PATCH] Update span.h --- src/span.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/span.h b/src/span.h index 5b63cc39d..2cddabea6 100644 --- a/src/span.h +++ b/src/span.h @@ -3,6 +3,7 @@ #ifndef USE_CXX17 #include #else +#include namespace std { template @@ -12,6 +13,8 @@ struct span { span(const span >& s) : p_{const_cast(s.data())}, length_{s.size()} {} span(std::vector >& s) : p_{const_cast(s.data())}, length_{s.size()} {} + template + span(std::array, N> s) : p_{const_cast(s.data())}, length_{s.size()} {} bool empty() const { return length_ == 0; } @@ -21,16 +24,14 @@ struct span { T* data() { return p_; } const T* data() const { return p_; } - T& operator[](size_t index) { return p_[index]; } + T& operator[](size_t index) const { return p_[index]; } - T& back() { return p_[length_ - 1]; } - T back() const { return p_[length_ - 1]; } + T& back() const { return p_[length_ - 1]; } - T* begin() { return p_; } - T* end() { return p_ + length_; } + T* begin() const { return p_; } + T* end() const { return p_ + length_; } - span subspan(size_t index, size_t length) { return span(p_ + index, length); } - span subspan(size_t index, size_t length) const { return span(p_ + index, length); } + span subspan(size_t index, size_t length) const { return span(p_ + index, length); } private: T* p_{};