Skip to content

Commit

Permalink
Add static assert to pre c++11 subspan
Browse files Browse the repository at this point in the history
  • Loading branch information
mike919192 committed Feb 15, 2024
1 parent f35ebfa commit 8bad0ea
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 @@ -354,6 +354,12 @@ namespace etl
template <size_t OFFSET, size_t COUNT>
etl::span<element_type, COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET> 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<element_type, (COUNT != etl::dynamic_extent ? COUNT : Extent - OFFSET)>(pbegin + OFFSET, (pbegin + Extent));
Expand Down

0 comments on commit 8bad0ea

Please sign in to comment.