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