xref: /xnu-8020.140.41/tests/bounded_array_src/for_loop.cpp (revision 27b03b360a988dfd3dfdf34262bb0042026747cc)
1*27b03b36SApple OSS Distributions //
2*27b03b36SApple OSS Distributions // Make sure `bounded_array` works nicely with the range-based for-loop.
3*27b03b36SApple OSS Distributions //
4*27b03b36SApple OSS Distributions 
5*27b03b36SApple OSS Distributions #include <libkern/c++/bounded_array.h>
6*27b03b36SApple OSS Distributions #include <darwintest.h>
7*27b03b36SApple OSS Distributions #include "test_policy.h"
8*27b03b36SApple OSS Distributions 
9*27b03b36SApple OSS Distributions struct T {
10*27b03b36SApple OSS Distributions 	int i;
11*27b03b36SApple OSS Distributions };
12*27b03b36SApple OSS Distributions 
13*27b03b36SApple OSS Distributions template <typename T>
14*27b03b36SApple OSS Distributions static void
tests()15*27b03b36SApple OSS Distributions tests()
16*27b03b36SApple OSS Distributions {
17*27b03b36SApple OSS Distributions 	test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}};
18*27b03b36SApple OSS Distributions 	for (T& element : array) {
19*27b03b36SApple OSS Distributions 		element = T{3};
20*27b03b36SApple OSS Distributions 	}
21*27b03b36SApple OSS Distributions 
22*27b03b36SApple OSS Distributions 	for (T const& element : array) {
23*27b03b36SApple OSS Distributions 		CHECK(element.i == 3);
24*27b03b36SApple OSS Distributions 	}
25*27b03b36SApple OSS Distributions }
26*27b03b36SApple OSS Distributions 
27*27b03b36SApple OSS Distributions T_DECL(for_loop, "bounded_array.for_loop") {
28*27b03b36SApple OSS Distributions 	tests<T>();
29*27b03b36SApple OSS Distributions }
30