1bb611c8fSApple OSS Distributions //
2bb611c8fSApple OSS Distributions // Tests for
3bb611c8fSApple OSS Distributions //  T& operator[](ptrdiff_t n);
4bb611c8fSApple OSS Distributions //  T const& operator[](ptrdiff_t n) const;
5bb611c8fSApple OSS Distributions //
6bb611c8fSApple OSS Distributions 
7bb611c8fSApple OSS Distributions #include <libkern/c++/bounded_array.h>
8bb611c8fSApple OSS Distributions #include "test_policy.h"
9bb611c8fSApple OSS Distributions #include <darwintest.h>
10bb611c8fSApple OSS Distributions #include <type_traits>
11bb611c8fSApple OSS Distributions 
12bb611c8fSApple OSS Distributions struct T { int i; };
13bb611c8fSApple OSS Distributions inline bool
operator ==(T const & a,T const & b)14bb611c8fSApple OSS Distributions operator==(T const& a, T const& b)
15bb611c8fSApple OSS Distributions {
16bb611c8fSApple OSS Distributions 	return a.i == b.i;
17bb611c8fSApple OSS Distributions }
18bb611c8fSApple OSS Distributions 
19bb611c8fSApple OSS Distributions template <typename T>
20bb611c8fSApple OSS Distributions static void
tests()21bb611c8fSApple OSS Distributions tests()
22bb611c8fSApple OSS Distributions {
23bb611c8fSApple OSS Distributions 	{
24bb611c8fSApple OSS Distributions 		test_bounded_array<T, 5> array = {T{0}, T{1}, T{2}, T{3}, T{4}};
25bb611c8fSApple OSS Distributions 		T& a0 = array[0];
26bb611c8fSApple OSS Distributions 		CHECK(&a0 == array.data());
27bb611c8fSApple OSS Distributions 		CHECK(a0 == T{0});
28bb611c8fSApple OSS Distributions 		T& a1 = array[1];
29bb611c8fSApple OSS Distributions 		CHECK(a1 == T{1});
30bb611c8fSApple OSS Distributions 		T& a2 = array[2];
31bb611c8fSApple OSS Distributions 		CHECK(a2 == T{2});
32bb611c8fSApple OSS Distributions 		T& a3 = array[3];
33bb611c8fSApple OSS Distributions 		CHECK(a3 == T{3});
34bb611c8fSApple OSS Distributions 		T& a4 = array[4];
35bb611c8fSApple OSS Distributions 		CHECK(a4 == T{4});
36bb611c8fSApple OSS Distributions 	}
37bb611c8fSApple OSS Distributions 
38bb611c8fSApple OSS Distributions 	{
39bb611c8fSApple OSS Distributions 		test_bounded_array<T, 5> const array = {T{0}, T{1}, T{2}, T{3}, T{4}};
40bb611c8fSApple OSS Distributions 		T const& a0 = array[0];
41bb611c8fSApple OSS Distributions 		CHECK(&a0 == array.data());
42bb611c8fSApple OSS Distributions 		CHECK(a0 == T{0});
43bb611c8fSApple OSS Distributions 		T const& a1 = array[1];
44bb611c8fSApple OSS Distributions 		CHECK(a1 == T{1});
45bb611c8fSApple OSS Distributions 		T const& a2 = array[2];
46bb611c8fSApple OSS Distributions 		CHECK(a2 == T{2});
47bb611c8fSApple OSS Distributions 		T const& a3 = array[3];
48bb611c8fSApple OSS Distributions 		CHECK(a3 == T{3});
49bb611c8fSApple OSS Distributions 		T const& a4 = array[4];
50bb611c8fSApple OSS Distributions 		CHECK(a4 == T{4});
51bb611c8fSApple OSS Distributions 	}
52bb611c8fSApple OSS Distributions }
53bb611c8fSApple OSS Distributions 
54*8d741a5dSApple OSS Distributions T_DECL(operator_subscript, "bounded_array.operator.subscript", T_META_TAG_VM_PREFERRED) {
55bb611c8fSApple OSS Distributions 	tests<T>();
56bb611c8fSApple OSS Distributions }
57