blob: c05dd19405bff2acaee17d2e9b8625314ab79c3c [file] [log] [blame]
Eric Fiselier59cdf902018-02-07 21:06:13 +00001//===----------------------------------------------------------------------===//
2//
Chandler Carruth57b08b02019-01-19 10:56:40 +00003// 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 Fiselier59cdf902018-02-07 21:06:13 +00006//
7//===----------------------------------------------------------------------===//
8
9// <array>
10
Marshall Clow07d8ac02018-08-02 02:11:06 +000011// These are all constexpr in C++20
Eric Fiselier59cdf902018-02-07 21:06:13 +000012// 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 Clow7c84e382018-08-03 00:47:12 +000025#include "test_comparisons.h"
Eric Fiselier59cdf902018-02-07 21:06:13 +000026
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 Bastien2df59c52019-02-04 20:31:13 +000031int main(int, char**)
Eric Fiselier59cdf902018-02-07 21:06:13 +000032{
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 Clow7c84e382018-08-03 00:47:12 +000040 assert(testComparisons6(c1, c2, true, false));
41 assert(testComparisons6(c1, c3, false, true));
42 assert(testComparisons6(c1, c4, false, false));
Eric Fiselier59cdf902018-02-07 21:06:13 +000043 }
44 {
45 typedef int T;
46 typedef std::array<T, 0> C;
47 C c1 = {};
48 C c2 = {};
Marshall Clow7c84e382018-08-03 00:47:12 +000049 assert(testComparisons6(c1, c2, true, false));
Eric Fiselier59cdf902018-02-07 21:06:13 +000050 }
Marshall Clow07d8ac02018-08-02 02:11:06 +000051
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 Clow7c84e382018-08-03 00:47:12 +000056 static_assert(testComparisons6(a1, a1, true, false), "");
57 static_assert(testComparisons6(a1, a2, false, true), "");
58 static_assert(testComparisons6(a2, a1, false, false), "");
Marshall Clow07d8ac02018-08-02 02:11:06 +000059 }
60#endif
JF Bastien2df59c52019-02-04 20:31:13 +000061
62 return 0;
Eric Fiselier59cdf902018-02-07 21:06:13 +000063}