Skip to content

Commit 3fc5390

Browse files
committed
Merge pull request #103924 from Ivorforce/span-iteration
Add iteration to `Span`.
2 parents 3ade6e2 + 55a7de9 commit 3fc5390

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

core/templates/span.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,7 @@ class Span {
5959
CRASH_COND(p_idx >= _len);
6060
return _ptr[p_idx];
6161
}
62+
63+
_FORCE_INLINE_ constexpr const T *begin() const { return _ptr; }
64+
_FORCE_INLINE_ constexpr const T *end() const { return _ptr + _len; }
6265
};

tests/core/templates/test_span.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ TEST_CASE("[Span] Constexpr Validators") {
5555
static_assert(!span_array.is_empty());
5656
static_assert(span_array[0] == U'1');
5757
static_assert(span_array[span_array.size() - 1] == U'5');
58+
59+
int idx = 0;
60+
for (const char32_t &chr : span_array) {
61+
CHECK_EQ(chr, span_array[idx++]);
62+
}
5863
}
5964

6065
} // namespace TestSpan

0 commit comments

Comments
 (0)