]> git.saurik.com Git - apple/xnu.git/blob - tests/bounded_array_ref_src/for_loop.cpp
xnu-7195.50.7.100.1.tar.gz
[apple/xnu.git] / tests / bounded_array_ref_src / for_loop.cpp
1 //
2 // Make sure `bounded_array_ref` works nicely with the range-based for-loop.
3 //
4
5 #include <libkern/c++/bounded_array_ref.h>
6 #include <darwintest.h>
7 #include "test_policy.h"
8
9 struct T {
10 int i;
11 };
12
13 template <typename T>
14 static void
15 tests()
16 {
17 T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
18 test_bounded_array_ref<T> view(array);
19 for (T& element : view) {
20 element = T{3};
21 }
22
23 for (T const& element : view) {
24 CHECK(element.i == 3);
25 }
26 }
27
28 T_DECL(for_loop, "bounded_array_ref.for_loop") {
29 tests<T>();
30 }