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