xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/compare.three_way.pass.cpp (revision 55ec808a889726e0547b7e2f0aa12bc197f6d163)
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 // UNSUPPORTED: c++03, c++11, c++14, c++17
9 
10 // <vector>
11 
12 // class vector<bool, Allocator>
13 
14 // template<class T, class Allocator>
15 //   constexpr synth-three-way-result<T> operator<=>(const vector<T, Allocator>& x,
16 //                                                   const vector<T, Allocator>& y);
17 
18 #include <cassert>
19 #include <vector>
20 
21 #include "test_comparisons.h"
22 
test_sequence_container_spaceship_vectorbool()23 constexpr bool test_sequence_container_spaceship_vectorbool() {
24   // Empty containers
25   {
26     std::vector<bool> l1;
27     std::vector<bool> l2;
28     assert(testOrder(l1, l2, std::strong_ordering::equivalent));
29   }
30   // Identical contents
31   {
32     std::vector<bool> t1{true, true};
33     std::vector<bool> t2{true, true};
34     assert(testOrder(t1, t2, std::strong_ordering::equivalent));
35 
36     std::vector<bool> f1{false, false};
37     std::vector<bool> f2{false, false};
38     assert(testOrder(f1, f2, std::strong_ordering::equivalent));
39   }
40   // Less, due to contained values
41   {
42     std::vector<bool> l1{true, false};
43     std::vector<bool> l2{true, true};
44     assert(testOrder(l1, l2, std::strong_ordering::less));
45   }
46   // Greater, due to contained values
47   {
48     std::vector<bool> l1{true, true};
49     std::vector<bool> l2{true, false};
50     assert(testOrder(l1, l2, std::strong_ordering::greater));
51   }
52   // Shorter list
53   {
54     std::vector<bool> l1{true};
55     std::vector<bool> l2{true, false};
56     assert(testOrder(l1, l2, std::strong_ordering::less));
57 
58     std::vector<bool> t1{true};
59     std::vector<bool> t2{true, true};
60     assert(testOrder(t1, t2, std::strong_ordering::less));
61 
62     std::vector<bool> f1{false};
63     std::vector<bool> f2{false, false};
64     assert(testOrder(f1, f2, std::strong_ordering::less));
65 
66     std::vector<bool> e;
67     assert(testOrder(e, t1, std::strong_ordering::less));
68     assert(testOrder(e, f1, std::strong_ordering::less));
69   }
70   // Longer list
71   {
72     std::vector<bool> l1{true, false};
73     std::vector<bool> l2{true};
74     assert(testOrder(l1, l2, std::strong_ordering::greater));
75 
76     std::vector<bool> t1{true, true};
77     std::vector<bool> t2{true};
78     assert(testOrder(t1, t2, std::strong_ordering::greater));
79 
80     std::vector<bool> f1{false, false};
81     std::vector<bool> f2{false};
82     assert(testOrder(f1, f2, std::strong_ordering::greater));
83 
84     std::vector<bool> e;
85     assert(testOrder(t2, e, std::strong_ordering::greater));
86     assert(testOrder(f2, e, std::strong_ordering::greater));
87   }
88 
89   return true;
90 }
91 
main(int,char **)92 int main(int, char**) {
93   assert(test_sequence_container_spaceship_vectorbool());
94   static_assert(test_sequence_container_spaceship_vectorbool());
95   return 0;
96 }
97