1bb611c8fSApple OSS Distributions //
2bb611c8fSApple OSS Distributions // Make sure `bounded_array_ref` works nicely with the range-based for-loop.
3bb611c8fSApple OSS Distributions //
4bb611c8fSApple OSS Distributions 
5bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array_ref.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 	T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
18bb611c8fSApple OSS Distributions 	test_bounded_array_ref<T> view(array);
19bb611c8fSApple OSS Distributions 	for (T& element : view) {
20bb611c8fSApple OSS Distributions 		element = T{3};
21bb611c8fSApple OSS Distributions 	}
22bb611c8fSApple OSS Distributions 
23bb611c8fSApple OSS Distributions 	for (T const& element : view) {
24bb611c8fSApple OSS Distributions 		CHECK(element.i == 3);
25bb611c8fSApple OSS Distributions 	}
26bb611c8fSApple OSS Distributions }
27bb611c8fSApple OSS Distributions 
28*8d741a5dSApple OSS Distributions T_DECL(for_loop, "bounded_array_ref.for_loop", T_META_TAG_VM_PREFERRED) {
29bb611c8fSApple OSS Distributions 	tests<T>();
30bb611c8fSApple OSS Distributions }
31