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>
22 void
23 test(const C& x)
24 {
25     typename C::size_type s = x.size();
26     C c(x);
27     LIBCPP_ASSERT(c.__invariants());
28     assert(c.size() == s);
29     assert(c == x);
30 }
31 
32 int main(int, char**)
33 {
34     {
35         bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
36         bool* an = a + sizeof(a)/sizeof(a[0]);
37         test(std::vector<bool>(a, an));
38     }
39     {
40         std::vector<bool, test_allocator<bool> > v(3, true, test_allocator<bool>(5));
41         std::vector<bool, test_allocator<bool> > v2 = v;
42         assert(v2 == v);
43         assert(v2.get_allocator() == v.get_allocator());
44     }
45 #if TEST_STD_VER >= 11
46     {
47         std::vector<bool, other_allocator<bool> > v(3, true, other_allocator<bool>(5));
48         std::vector<bool, other_allocator<bool> > v2 = v;
49         assert(v2 == v);
50         assert(v2.get_allocator() == other_allocator<bool>(-2));
51     }
52     {
53         bool a[] = {0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 0};
54         bool* an = a + sizeof(a)/sizeof(a[0]);
55         test(std::vector<bool, min_allocator<bool>>(a, an));
56     }
57     {
58         std::vector<bool, min_allocator<bool> > v(3, true, min_allocator<bool>());
59         std::vector<bool, min_allocator<bool> > v2 = v;
60         assert(v2 == v);
61         assert(v2.get_allocator() == v.get_allocator());
62     }
63 #endif
64 
65   return 0;
66 }
67