Add iteration to Span.

This commit is contained in:
Lukas Tenbrink 2025-03-10 19:04:12 +01:00
parent 78c9f8ddd9
commit 55a7de93c7
2 changed files with 8 additions and 0 deletions

View file

@ -59,4 +59,7 @@ public:
CRASH_COND(p_idx >= _len); CRASH_COND(p_idx >= _len);
return _ptr[p_idx]; return _ptr[p_idx];
} }
_FORCE_INLINE_ constexpr const T *begin() const { return _ptr; }
_FORCE_INLINE_ constexpr const T *end() const { return _ptr + _len; }
}; };

View file

@ -55,6 +55,11 @@ TEST_CASE("[Span] Constexpr Validators") {
static_assert(!span_array.is_empty()); static_assert(!span_array.is_empty());
static_assert(span_array[0] == U'1'); static_assert(span_array[0] == U'1');
static_assert(span_array[span_array.size() - 1] == U'5'); static_assert(span_array[span_array.size() - 1] == U'5');
int idx = 0;
for (const char32_t &chr : span_array) {
CHECK_EQ(chr, span_array[idx++]);
}
} }
} // namespace TestSpan } // namespace TestSpan