From 3308b4dd72e2fda6aceab080ec6525d4a701d2c8 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Wed, 27 Nov 2024 00:17:37 -0600 Subject: [PATCH] [ox/std] Add missing + and += operators to Span --- deps/ox/src/ox/std/span.hpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/deps/ox/src/ox/std/span.hpp b/deps/ox/src/ox/std/span.hpp index a5def89e..67a47c48 100644 --- a/deps/ox/src/ox/std/span.hpp +++ b/deps/ox/src/ox/std/span.hpp @@ -116,6 +116,7 @@ class SpanView { } constexpr SpanView operator+=(size_t i) noexcept { + ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow"); m_items += i; m_size -= i; return *this; @@ -143,7 +144,7 @@ class Span { private: T *m_items{}; - const std::size_t m_size{}; + std::size_t m_size{}; public: using value_type = T; @@ -243,6 +244,18 @@ class Span { return m_items[i]; } + constexpr Span operator+(size_t i) const noexcept { + ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow"); + return {m_items + i, m_size - i}; + } + + constexpr Span operator+=(size_t i) noexcept { + ox::primitiveAssert(__FILE__, __LINE__, i < size(), "Span access overflow"); + m_items += i; + m_size -= i; + return *this; + } + [[nodiscard]] constexpr auto data() const noexcept { return m_items;