aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-05-26 12:05:43 -0700
committerChris Robinson <[email protected]>2019-05-26 12:05:43 -0700
commit63a130204c829c5c81631cfa8c579d78048fdb6e (patch)
tree6feae50a872ab03f856bfaf83424dc95864caca0 /common
parent7cbf82afe4999addde6630fda2cc91614a264772 (diff)
Add a few more methods to the span class
Diffstat (limited to 'common')
-rw-r--r--common/alspan.h11
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};