1 //
2 // Tests for
3 //  T& operator[](ptrdiff_t n) const;
4 //
5 
6 #include <libkern/c++/bounded_array_ref.h>
7 #include "test_policy.h"
8 #include <darwintest.h>
9 #include <darwintest_utils.h>
10 
11 struct T { int i; };
12 inline bool
operator ==(T const & a,T const & b)13 operator==(T const& a, T const& b)
14 {
15 	return a.i == b.i;
16 };
17 
18 template <typename T>
19 static void
tests()20 tests()
21 {
22 	{
23 		T array[5] = {T{0}, T{1}, T{2}, T{3}, T{4}};
24 		test_bounded_array_ref<T> view(array);
25 		CHECK(view[0] == T{0});
26 		CHECK(view[1] == T{1});
27 		CHECK(view[2] == T{2});
28 		CHECK(view[3] == T{3});
29 		CHECK(view[4] == T{4});
30 	}
31 }
32 
33 T_DECL(operator_subscript, "bounded_array_ref.operator.subscript", T_META_TAG_VM_PREFERRED) {
34 	tests<T>();
35 }
36