1 //===----------------------------------------------------------------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 // <array>
11 
12 // bool operator==(array<T, N> const&, array<T, N> const&);
13 // bool operator!=(array<T, N> const&, array<T, N> const&);
14 // bool operator<(array<T, N> const&, array<T, N> const&);
15 // bool operator<=(array<T, N> const&, array<T, N> const&);
16 // bool operator>(array<T, N> const&, array<T, N> const&);
17 // bool operator>=(array<T, N> const&, array<T, N> const&);
18 
19 
20 #include <array>
21 #include <vector>
22 #include <cassert>
23 
24 #include "test_macros.h"
25 
26 // std::array is explicitly allowed to be initialized with A a = { init-list };.
27 // Disable the missing braces warning for this reason.
28 #include "disable_missing_braces_warning.h"
29 
30 template <class Array>
31 void test_compare(const Array& LHS, const Array& RHS) {
32   typedef std::vector<typename Array::value_type> Vector;
33   const Vector LHSV(LHS.begin(), LHS.end());
34   const Vector RHSV(RHS.begin(), RHS.end());
35   assert((LHS == RHS) == (LHSV == RHSV));
36   assert((LHS != RHS) == (LHSV != RHSV));
37   assert((LHS < RHS) == (LHSV < RHSV));
38   assert((LHS <= RHS) == (LHSV <= RHSV));
39   assert((LHS > RHS) == (LHSV > RHSV));
40   assert((LHS >= RHS) == (LHSV >= RHSV));
41 }
42 
43 int main()
44 {
45   {
46     typedef int T;
47     typedef std::array<T, 3> C;
48     C c1 = {1, 2, 3};
49     C c2 = {1, 2, 3};
50     C c3 = {3, 2, 1};
51     C c4 = {1, 2, 1};
52     test_compare(c1, c2);
53     test_compare(c1, c3);
54     test_compare(c1, c4);
55   }
56   {
57     typedef int T;
58     typedef std::array<T, 0> C;
59     C c1 = {};
60     C c2 = {};
61     test_compare(c1, c2);
62   }
63 }
64