Skip to content

Commit

Permalink
In subspan function, add static checks on extents
Browse files Browse the repository at this point in the history
  • Loading branch information
mike919192 committed Feb 14, 2024
1 parent 8403165 commit 5275598
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/etl/span.h
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,12 @@ namespace etl
ETL_NODISCARD ETL_CONSTEXPR
etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET> subspan() const ETL_NOEXCEPT
{
//if extent is static, check that OFFSET is within the original span
static_assert((extent != etl::dynamic_extent) ? OFFSET <= extent : true);

//if count is also static, check that OFFSET + COUNT is within the original span
static_assert((extent != etl::dynamic_extent) && (COUNT != etl::dynamic_extent) ? COUNT <= (extent - OFFSET) : true);

return (COUNT == etl::dynamic_extent) ? etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET>(pbegin + OFFSET, (pbegin + Extent))
: etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET>(pbegin + OFFSET, pbegin + OFFSET + COUNT);
}
Expand Down

0 comments on commit 5275598

Please sign in to comment.