From 8bad0ea19097644434d78976b3cb4ee8c5d81b51 Mon Sep 17 00:00:00 2001 From: Michael Bloom Date: Thu, 15 Feb 2024 12:47:52 -0500 Subject: [PATCH] Add static assert to pre c++11 subspan --- include/etl/span.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/etl/span.h b/include/etl/span.h index 1c40d4f1f..0bd3f1c1b 100644 --- a/include/etl/span.h +++ b/include/etl/span.h @@ -354,6 +354,12 @@ namespace etl template etl::span subspan() const { + //if extent is static, check that OFFSET is within the original span + ETL_STATIC_ASSERT((extent != etl::dynamic_extent) ? OFFSET <= extent : true, "OFFSET is not within the original span"); + + //if count is also static, check that OFFSET + COUNT is within the original span + ETL_STATIC_ASSERT((extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (extent - OFFSET) : true, "OFFSET + COUNT is not within the original span"); + if (COUNT == etl::dynamic_extent) { return etl::span(pbegin + OFFSET, (pbegin + Extent));