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