From d98f84f9d3bfa5ef69e6741e4e36663142ad5642 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sat, 28 Oct 2023 22:10:33 +0300 Subject: [PATCH] BAN: Update ByteSpan API Add ByteSpan::as_span and const versions of as() and as_span() require T to be const. --- BAN/include/BAN/ByteSpan.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/BAN/include/BAN/ByteSpan.h b/BAN/include/BAN/ByteSpan.h index b920f6db..e86ba8f8 100644 --- a/BAN/include/BAN/ByteSpan.h +++ b/BAN/include/BAN/ByteSpan.h @@ -80,13 +80,30 @@ namespace BAN } template - const S& as() const + requires(is_const_v) + S& as() const { ASSERT(m_data); ASSERT(m_size >= sizeof(S)); return *reinterpret_cast(m_data); } + template + requires(!CONST && !is_const_v) + Span as_span() + { + ASSERT(m_data); + return Span(reinterpret_cast(m_data), m_size / sizeof(S)); + } + + template + requires(is_const_v) + Span as_span() const + { + ASSERT(m_data); + return Span(reinterpret_cast(m_data), m_size / sizeof(S)); + } + ByteSpanGeneral slice(size_type offset, size_type length = size_type(-1)) { ASSERT(m_data);