Add a few more methods to the span class

This commit is contained in:
Chris Robinson
2019-05-26 12:05:43 -07:00
parent 7cbf82afe4
commit 63a130204c
+11
View File
@@ -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};