diff --git a/core/templates/span.h b/core/templates/span.h index 872fc7b6585..c8f85913473 100644 --- a/core/templates/span.h +++ b/core/templates/span.h @@ -59,4 +59,7 @@ public: CRASH_COND(p_idx >= _len); return _ptr[p_idx]; } + + _FORCE_INLINE_ constexpr const T *begin() const { return _ptr; } + _FORCE_INLINE_ constexpr const T *end() const { return _ptr + _len; } }; diff --git a/tests/core/templates/test_span.h b/tests/core/templates/test_span.h index e3b4f469484..94ce8183fa2 100644 --- a/tests/core/templates/test_span.h +++ b/tests/core/templates/test_span.h @@ -55,6 +55,11 @@ TEST_CASE("[Span] Constexpr Validators") { static_assert(!span_array.is_empty()); static_assert(span_array[0] == U'1'); 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