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