BAN: Update ByteSpan API

Add ByteSpan::as_span<T> and const versions of as() and as_span()
require T to be const.
This commit is contained in:
Bananymous 2023-10-28 22:10:33 +03:00
parent 240a687d8f
commit d98f84f9d3
1 changed files with 18 additions and 1 deletions

View File

@ -80,13 +80,30 @@ namespace BAN
}
template<typename S>
const S& as() const
requires(is_const_v<S>)
S& as() const
{
ASSERT(m_data);
ASSERT(m_size >= sizeof(S));
return *reinterpret_cast<S*>(m_data);
}
template<typename S>
requires(!CONST && !is_const_v<S>)
Span<S> as_span()
{
ASSERT(m_data);
return Span<S>(reinterpret_cast<S*>(m_data), m_size / sizeof(S));
}
template<typename S>
requires(is_const_v<S>)
Span<S> as_span() const
{
ASSERT(m_data);
return Span<S>(reinterpret_cast<S*>(m_data), m_size / sizeof(S));
}
ByteSpanGeneral slice(size_type offset, size_type length = size_type(-1))
{
ASSERT(m_data);