diff --git a/include/libimp/span.h b/include/libimp/span.h index 36e43f5..d4065b9 100644 --- a/include/libimp/span.h +++ b/include/libimp/span.h @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #ifdef LIBIMP_CPP_20 #include #endif // LIBIMP_CPP_20 @@ -182,6 +185,27 @@ public: constexpr reverse_iterator rend() const noexcept { return reverse_iterator(this->begin()); } + + constexpr span first(size_type count) const noexcept { + return span(begin(), count); + } + + constexpr span last(size_type count) const noexcept { + return span(end() - count, count); + } + + constexpr span subspan(size_type offset, size_type count = (std::numeric_limits::max)()) const noexcept { + if (offset >= size()) { + return {}; + } + return span(begin() + offset, (std::min)(size() - offset, count)); + } }; +template ::value, std::uint8_t const, std::uint8_t>::type> +auto as_bytes(span s) noexcept -> span { + return {reinterpret_cast(s.data()), s.size_bytes()}; +} + LIBIMP_NAMESPACE_END_