| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// <array> |
| 10 |
|
| 11 |
// template <class T, size_t N> |
| 12 |
// bool operator==(const array<T,N>& x, const array<T,N>& y); // constexpr in C++20 |
| 13 |
// template <class T, size_t N> |
| 14 |
// bool operator!=(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 15 |
// template <class T, size_t N> |
| 16 |
// bool operator<(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 17 |
// template <class T, size_t N> |
| 18 |
// bool operator>(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 19 |
// template <class T, size_t N> |
| 20 |
// bool operator<=(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 21 |
// template <class T, size_t N> |
| 22 |
// bool operator>=(const array<T,N>& x, const array<T,N>& y); // removed in C++20 |
| 23 |
|
| 24 |
#include <array> |
| 25 |
#include <cassert> |
| 26 |
|
| 27 |
#include "test_macros.h" |
| 28 |
#include "test_comparisons.h" |
| 29 |
|
| 30 |
TEST_CONSTEXPR_CXX20 bool tests() { |
| 31 |
// Arrays where the elements support all comparison operators |
| 32 |
AssertComparisonsReturnBool<std::array<int, 3> >(); |
| 33 |
{ |
| 34 |
typedef std::array<int, 3> C; |
| 35 |
const C c1 = {1, 2, 3}; |
| 36 |
const C c2 = {1, 2, 3}; |
| 37 |
const C c3 = {3, 2, 1}; |
| 38 |
const C c4 = {1, 2, 1}; |
| 39 |
assert(testComparisons(c1, c2, true, false)); |
| 40 |
assert(testComparisons(c1, c3, false, true)); |
| 41 |
assert(testComparisons(c1, c4, false, false)); |
| 42 |
} |
| 43 |
// Empty array |
| 44 |
{ |
| 45 |
typedef std::array<int, 0> C; |
| 46 |
const C c1 = {}; |
| 47 |
const C c2 = {}; |
| 48 |
assert(testComparisons(c1, c2, true, false)); |
| 49 |
} |
| 50 |
// Arrays where the elements support only less and equality comparisons |
| 51 |
AssertComparisonsReturnBool<std::array<LessAndEqComp, 3> >(); |
| 52 |
{ |
| 53 |
typedef std::array<LessAndEqComp, 3> C; |
| 54 |
const C c1 = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(3)}; |
| 55 |
const C c2 = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(3)}; |
| 56 |
const C c3 = {LessAndEqComp(3), LessAndEqComp(2), LessAndEqComp(1)}; |
| 57 |
const C c4 = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(1)}; |
| 58 |
assert(testComparisons(c1, c2, true, false)); |
| 59 |
assert(testComparisons(c1, c3, false, true)); |
| 60 |
assert(testComparisons(c1, c4, false, false)); |
| 61 |
} |
| 62 |
// Empty array where the elements support only less and equality comparisons |
| 63 |
{ |
| 64 |
typedef std::array<LessAndEqComp, 0> C; |
| 65 |
const C c1 = {}; |
| 66 |
const C c2 = {}; |
| 67 |
assert(testComparisons(c1, c2, true, false)); |
| 68 |
} |
| 69 |
|
| 70 |
return true; |
| 71 |
} |
| 72 |
|
| 73 |
int main(int, char**) { |
| 74 |
tests(); |
| 75 |
#if TEST_STD_VER >= 20 |
| 76 |
static_assert(tests()); |
| 77 |
#endif |
| 78 |
return 0; |
| 79 |
} |