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 // vector(const vector& v, const allocator_type& a);
12 
13 #include <vector>
14 #include <cassert>
15 
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19 
20 template <class C>
21 void
22 test(const C& x, const typename C::allocator_type& a)
23 {
24     typename C::size_type s = x.size();
25     C c(x, a);
26     LIBCPP_ASSERT(c.__invariants());
27     assert(c.size() == s);
28     assert(c == x);
29 }
30 
31 int main(int, char**)
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), std::allocator<bool>());
37     }
38     {
39         std::vector<bool, test_allocator<bool> > l(3, true, test_allocator<bool>(5));
40         std::vector<bool, test_allocator<bool> > l2(l, test_allocator<bool>(3));
41         assert(l2 == l);
42         assert(l2.get_allocator() == test_allocator<bool>(3));
43     }
44     {
45         std::vector<bool, other_allocator<bool> > l(3, true, other_allocator<bool>(5));
46         std::vector<bool, other_allocator<bool> > l2(l, other_allocator<bool>(3));
47         assert(l2 == l);
48         assert(l2.get_allocator() == other_allocator<bool>(3));
49     }
50 #if TEST_STD_VER >= 11
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), min_allocator<bool>());
55     }
56     {
57         std::vector<bool, min_allocator<bool> > l(3, true, min_allocator<bool>());
58         std::vector<bool, min_allocator<bool> > l2(l, min_allocator<bool>());
59         assert(l2 == l);
60         assert(l2.get_allocator() == min_allocator<bool>());
61     }
62 #endif
63 
64   return 0;
65 }
66