xref: /llvm-project/libcxx/test/std/containers/sequences/vector.bool/copy.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 // vector<bool>
11 
12 // vector(const vector& v);
13 
14 #include <vector>
15 #include <cassert>
16 
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
20 
21 template <class C>
test(const C & x)22 TEST_CONSTEXPR_CXX20 void test(const C& x)
23 {
24     typename C::size_type s = x.size();
25     C c(x);
26     LIBCPP_ASSERT(c.__invariants());
27     assert(c.size() == s);
28     assert(c == x);
29 }
30 
tests()31 TEST_CONSTEXPR_CXX20 bool tests()
32 {
33     {
34         bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
35         bool* an = a + sizeof(a)/sizeof(a[0]);
36         test(std::vector<bool>(a, an));
37     }
38     {
39         std::vector<bool, test_allocator<bool> > v(3, true, test_allocator<bool>(5));
40         std::vector<bool, test_allocator<bool> > v2 = v;
41         assert(v2 == v);
42         assert(v2.get_allocator() == v.get_allocator());
43     }
44 #if TEST_STD_VER >= 11
45     {
46         std::vector<bool, other_allocator<bool> > v(3, true, other_allocator<bool>(5));
47         std::vector<bool, other_allocator<bool> > v2 = v;
48         assert(v2 == v);
49         assert(v2.get_allocator() == other_allocator<bool>(-2));
50     }
51     {
52         bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
53         bool* an = a + sizeof(a)/sizeof(a[0]);
54         test(std::vector<bool, min_allocator<bool>>(a, an));
55     }
56     {
57         std::vector<bool, min_allocator<bool> > v(3, true, min_allocator<bool>());
58         std::vector<bool, min_allocator<bool> > v2 = v;
59         assert(v2 == v);
60         assert(v2.get_allocator() == v.get_allocator());
61     }
62 #endif
63 
64     return true;
65 }
66 
main(int,char **)67 int main(int, char**)
68 {
69     tests();
70 #if TEST_STD_VER > 17
71     static_assert(tests());
72 #endif
73     return 0;
74 }
75