libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

compare.pass.cpp (1827B)


      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 //  These are all constexpr in C++20
     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 // bool operator>=(array<T, N> const&, array<T, N> const&);
     19 
     20 
     21 #include <array>
     22 #include <vector>
     23 #include <cassert>
     24 
     25 #include "test_macros.h"
     26 #include "test_comparisons.h"
     27 
     28 // std::array is explicitly allowed to be initialized with A a = { init-list };.
     29 // Disable the missing braces warning for this reason.
     30 #include "disable_missing_braces_warning.h"
     31 
     32 int main()
     33 {
     34   {
     35     typedef int T;
     36     typedef std::array<T, 3> C;
     37     C c1 = {1, 2, 3};
     38     C c2 = {1, 2, 3};
     39     C c3 = {3, 2, 1};
     40     C c4 = {1, 2, 1};
     41     assert(testComparisons6(c1, c2, true, false));
     42     assert(testComparisons6(c1, c3, false, true));
     43     assert(testComparisons6(c1, c4, false, false));
     44   }
     45   {
     46     typedef int T;
     47     typedef std::array<T, 0> C;
     48     C c1 = {};
     49     C c2 = {};
     50     assert(testComparisons6(c1, c2, true, false));
     51   }
     52 
     53 #if TEST_STD_VER > 17
     54   {
     55   constexpr std::array<int, 3> a1 = {1, 2, 3};
     56   constexpr std::array<int, 3> a2 = {2, 3, 4};
     57   static_assert(testComparisons6(a1, a1, true, false), "");
     58   static_assert(testComparisons6(a1, a2, false, true), "");
     59   static_assert(testComparisons6(a2, a1, false, false), "");
     60   }
     61 #endif
     62 }