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 template <int Dummy> struct NoCompare {}; 44 45 int main() 46 { 47 { 48 typedef NoCompare<0> T; 49 typedef std::array<T, 3> C; 50 C c1 = {{}}; 51 // expected-error@algorithm:* 2 {{invalid operands to binary expression}} 52 TEST_IGNORE_NODISCARD (c1 == c1); 53 TEST_IGNORE_NODISCARD (c1 < c1); 54 } 55 { 56 typedef NoCompare<1> T; 57 typedef std::array<T, 3> C; 58 C c1 = {{}}; 59 // expected-error@algorithm:* 2 {{invalid operands to binary expression}} 60 TEST_IGNORE_NODISCARD (c1 != c1); 61 TEST_IGNORE_NODISCARD (c1 > c1); 62 } 63 { 64 typedef NoCompare<2> T; 65 typedef std::array<T, 0> C; 66 C c1 = {{}}; 67 // expected-error@algorithm:* 2 {{invalid operands to binary expression}} 68 TEST_IGNORE_NODISCARD (c1 == c1); 69 TEST_IGNORE_NODISCARD (c1 < c1); 70 } 71 } 72