xref: /llvm-project/libcxx/test/std/containers/sequences/vector/compare.pass.cpp (revision 98d3d5b5da66e3cf7807c23a0294280bb796466b)
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 // <vector>
10 
11 // bool operator==(const vector& lhs, const vector& rhs);
12 // bool operator!=(const vector& lhs, const vector& rhs);
13 // bool operator< (const vector& lhs, const vector& rhs);
14 // bool operator<=(const vector& lhs, const vector& rhs);
15 // bool operator> (const vector& lhs, const vector& rhs);
16 // bool operator>=(const vector& lhs, const vector& rhs);
17 
18 #include <vector>
19 #include <cassert>
20 
21 #include "test_comparisons.h"
22 
test()23 TEST_CONSTEXPR_CXX20 bool test() {
24     {
25         const std::vector<int> c1, c2;
26         assert(testComparisons(c1, c2, true, false));
27     }
28     {
29         const std::vector<int> c1(1, 1), c2(1, 2);
30         assert(testComparisons(c1, c2, false, true));
31     }
32     {
33         const std::vector<int> c1, c2(1, 2);
34         assert(testComparisons(c1, c2, false, true));
35     }
36     {
37         int items1[3] = {1, 2, 1};
38         int items2[3] = {1, 2, 2};
39         const std::vector<int> c1(items1, items1 + 3);
40         const std::vector<int> c2(items2, items2 + 3);
41         assert(testComparisons(c1, c2, false, true));
42     }
43     {
44         int items1[3] = {3, 2, 3};
45         int items2[3] = {3, 1, 3};
46         const std::vector<int> c1(items1, items1 + 3);
47         const std::vector<int> c2(items2, items2 + 3);
48 
49         assert(testComparisons(c1, c2, false, false));
50     }
51     {
52         int items1[2] = {1, 2};
53         int items2[3] = {1, 2, 0};
54         const std::vector<int> c1(items1, items1 + 2);
55         const std::vector<int> c2(items2, items2 + 3);
56         assert(testComparisons(c1, c2, false, true));
57     }
58     {
59         int items1[3] = {1, 2, 0};
60         const std::vector<int> c1(items1, items1 + 3);
61         const std::vector<int> c2(1, 3);
62         assert(testComparisons(c1, c2, false, true));
63     }
64     {
65         const std::vector<LessAndEqComp> c1, c2;
66         assert(testComparisons(c1, c2, true, false));
67     }
68     {
69         const std::vector<LessAndEqComp> c1(1, LessAndEqComp(1));
70         const std::vector<LessAndEqComp> c2(1, LessAndEqComp(1));
71         assert(testComparisons(c1, c2, true, false));
72     }
73     {
74         const std::vector<LessAndEqComp> c1(1, LessAndEqComp(1));
75         const std::vector<LessAndEqComp> c2(1, LessAndEqComp(2));
76         assert(testComparisons(c1, c2, false, true));
77     }
78     {
79         const std::vector<LessAndEqComp> c1;
80         const std::vector<LessAndEqComp> c2(1, LessAndEqComp(2));
81         assert(testComparisons(c1, c2, false, true));
82     }
83     {
84         LessAndEqComp items1[3] = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(2)};
85         LessAndEqComp items2[3] = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(1)};
86         const std::vector<LessAndEqComp> c1(items1, items1 + 3);
87         const std::vector<LessAndEqComp> c2(items2, items2 + 3);
88         assert(testComparisons(c1, c2, false, false));
89     }
90     {
91         LessAndEqComp items1[3] = {LessAndEqComp(3), LessAndEqComp(3), LessAndEqComp(3)};
92         LessAndEqComp items2[3] = {LessAndEqComp(3), LessAndEqComp(2), LessAndEqComp(3)};
93         const std::vector<LessAndEqComp> c1(items1, items1 + 3);
94         const std::vector<LessAndEqComp> c2(items2, items2 + 3);
95         assert(testComparisons(c1, c2, false, false));
96     }
97     {
98         LessAndEqComp items1[2] = {LessAndEqComp(1), LessAndEqComp(2)};
99         LessAndEqComp items2[3] = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(0)};
100         const std::vector<LessAndEqComp> c1(items1, items1 + 2);
101         const std::vector<LessAndEqComp> c2(items2, items2 + 3);
102         assert(testComparisons(c1, c2, false, true));
103     }
104     {
105         LessAndEqComp items1[3] = {LessAndEqComp(1), LessAndEqComp(2), LessAndEqComp(0)};
106         const std::vector<LessAndEqComp> c1(items1, items1 + 3);
107         const std::vector<LessAndEqComp> c2(1, LessAndEqComp(3));
108         assert(testComparisons(c1, c2, false, true));
109     }
110     {
111         assert((std::vector<int>() == std::vector<int>()));
112         assert(!(std::vector<int>() != std::vector<int>()));
113         assert(!(std::vector<int>() < std::vector<int>()));
114         assert((std::vector<int>() <= std::vector<int>()));
115         assert(!(std::vector<int>() > std::vector<int>()));
116         assert((std::vector<int>() >= std::vector<int>()));
117     }
118 
119     return true;
120 }
121 
main(int,char **)122 int main(int, char**) {
123     test();
124 #if TEST_STD_VER > 17
125     static_assert(test());
126 #endif
127 
128     return 0;
129 }
130