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