diff options
author | Chris Robinson <[email protected]> | 2019-05-26 12:05:43 -0700 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2019-05-26 12:05:43 -0700 |
commit | 63a130204c829c5c81631cfa8c579d78048fdb6e (patch) | |
tree | 6feae50a872ab03f856bfaf83424dc95864caca0 /common | |
parent | 7cbf82afe4999addde6630fda2cc91614a264772 (diff) |
Add a few more methods to the span class
Diffstat (limited to 'common')
-rw-r--r-- | common/alspan.h | 11 |
1 files changed, 11 insertions, 0 deletions
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<size_t>(-1)) const + { + return (offset >= size()) ? span{} : + (count >= size()-offset) ? last(count) : + span{mData+offset, mData+offset+count}; + } + private: pointer mData{nullptr}; pointer mDataEnd{nullptr}; |