From 3566ddab0065e902db99efc75d6de9a9cc30d5b5 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 25 Oct 2023 21:40:11 +0300 Subject: [PATCH] BAN: ByteSpan can be sliced without specified size This will give span with all remaining size after offset --- BAN/include/BAN/ByteSpan.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/BAN/include/BAN/ByteSpan.h b/BAN/include/BAN/ByteSpan.h index 589b988e55..b920f6db30 100644 --- a/BAN/include/BAN/ByteSpan.h +++ b/BAN/include/BAN/ByteSpan.h @@ -87,9 +87,12 @@ namespace BAN return *reinterpret_cast(m_data); } - ByteSpanGeneral slice(size_type offset, size_type length) + ByteSpanGeneral slice(size_type offset, size_type length = size_type(-1)) { ASSERT(m_data); + ASSERT(m_size >= offset); + if (length == size_type(-1)) + length = m_size - offset; ASSERT(m_size >= offset + length); return ByteSpanGeneral(m_data + offset, length); }