From 63a130204c829c5c81631cfa8c579d78048fdb6e Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 26 May 2019 12:05:43 -0700 Subject: [PATCH] Add a few more methods to the span class --- common/alspan.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/common/alspan.h b/common/alspan.h index 0c15b93c..98da1a44 100644 --- a/common/alspan.h +++ b/common/alspan.h @@ -97,6 +97,17 @@ public: constexpr const_reverse_iterator crbegin() const noexcept { return cend(); } constexpr const_reverse_iterator crend() const noexcept { return cbegin(); } + constexpr span first(size_t count) const + { return (count >= size()) ? *this : span{mData, mData+count}; } + constexpr span last(size_t count) const + { return (count >= size()) ? *this : span{mDataEnd-count, mDataEnd}; } + constexpr span subspan(size_t offset, size_t count=static_cast(-1)) const + { + return (offset >= size()) ? span{} : + (count >= size()-offset) ? last(count) : + span{mData+offset, mData+offset+count}; + } + private: pointer mData{nullptr}; pointer mDataEnd{nullptr};