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