Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
Chandler Carruth | 57b08b0 | 2019-01-19 10:56:40 +0000 | [diff] [blame] | 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 |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | // <array> |
| 10 | |
Marshall Clow | 07d8ac0 | 2018-08-02 02:11:06 +0000 | [diff] [blame] | 11 | // These are all constexpr in C++20 |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 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" |
Marshall Clow | 7c84e38 | 2018-08-03 00:47:12 +0000 | [diff] [blame] | 25 | #include "test_comparisons.h" |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 26 | |
| 27 | // std::array is explicitly allowed to be initialized with A a = { init-list };. |
| 28 | // Disable the missing braces warning for this reason. |
| 29 | #include "disable_missing_braces_warning.h" |
| 30 | |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 31 | int main(int, char**) |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 32 | { |
| 33 | { |
| 34 | typedef int T; |
| 35 | typedef std::array<T, 3> C; |
| 36 | C c1 = {1, 2, 3}; |
| 37 | C c2 = {1, 2, 3}; |
| 38 | C c3 = {3, 2, 1}; |
| 39 | C c4 = {1, 2, 1}; |
Marshall Clow | 7c84e38 | 2018-08-03 00:47:12 +0000 | [diff] [blame] | 40 | assert(testComparisons6(c1, c2, true, false)); |
| 41 | assert(testComparisons6(c1, c3, false, true)); |
| 42 | assert(testComparisons6(c1, c4, false, false)); |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 43 | } |
| 44 | { |
| 45 | typedef int T; |
| 46 | typedef std::array<T, 0> C; |
| 47 | C c1 = {}; |
| 48 | C c2 = {}; |
Marshall Clow | 7c84e38 | 2018-08-03 00:47:12 +0000 | [diff] [blame] | 49 | assert(testComparisons6(c1, c2, true, false)); |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 50 | } |
Marshall Clow | 07d8ac0 | 2018-08-02 02:11:06 +0000 | [diff] [blame] | 51 | |
| 52 | #if TEST_STD_VER > 17 |
| 53 | { |
| 54 | constexpr std::array<int, 3> a1 = {1, 2, 3}; |
| 55 | constexpr std::array<int, 3> a2 = {2, 3, 4}; |
Marshall Clow | 7c84e38 | 2018-08-03 00:47:12 +0000 | [diff] [blame] | 56 | static_assert(testComparisons6(a1, a1, true, false), ""); |
| 57 | static_assert(testComparisons6(a1, a2, false, true), ""); |
| 58 | static_assert(testComparisons6(a2, a1, false, false), ""); |
Marshall Clow | 07d8ac0 | 2018-08-02 02:11:06 +0000 | [diff] [blame] | 59 | } |
| 60 | #endif |
JF Bastien | 2df59c5 | 2019-02-04 20:31:13 +0000 | [diff] [blame] | 61 | |
| 62 | return 0; |
Eric Fiselier | 59cdf90 | 2018-02-07 21:06:13 +0000 | [diff] [blame] | 63 | } |