1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
11 // vector(const vector& v, const allocator_type& a);
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
19 #include "asan_testing.h"
22 TEST_CONSTEXPR_CXX20
void
23 test(const C
& x
, const typename
C::allocator_type
& a
)
25 typename
C::size_type s
= x
.size();
27 LIBCPP_ASSERT(c
.__invariants());
28 assert(c
.size() == s
);
30 LIBCPP_ASSERT(is_contiguous_container_asan_correct(c
));
33 TEST_CONSTEXPR_CXX20
bool tests() {
35 int a
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
36 int* an
= a
+ sizeof(a
)/sizeof(a
[0]);
37 test(std::vector
<int>(a
, an
), std::allocator
<int>());
40 std::vector
<int, test_allocator
<int> > l(3, 2, test_allocator
<int>(5));
41 std::vector
<int, test_allocator
<int> > l2(l
, test_allocator
<int>(3));
43 assert(l2
.get_allocator() == test_allocator
<int>(3));
46 std::vector
<int, other_allocator
<int> > l(3, 2, other_allocator
<int>(5));
47 std::vector
<int, other_allocator
<int> > l2(l
, other_allocator
<int>(3));
49 assert(l2
.get_allocator() == other_allocator
<int>(3));
52 // Test copy ctor with allocator and empty source
53 std::vector
<int, other_allocator
<int> > l(other_allocator
<int>(5));
54 std::vector
<int, other_allocator
<int> > l2(l
, other_allocator
<int>(3));
56 assert(l2
.get_allocator() == other_allocator
<int>(3));
59 #if TEST_STD_VER >= 11
61 int a
[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 8, 7, 6, 5, 4, 3, 1, 0};
62 int* an
= a
+ sizeof(a
)/sizeof(a
[0]);
63 test(std::vector
<int, min_allocator
<int>>(a
, an
), min_allocator
<int>());
64 test(std::vector
<int, safe_allocator
<int>>(a
, an
), safe_allocator
<int>());
67 std::vector
<int, min_allocator
<int> > l(3, 2, min_allocator
<int>());
68 std::vector
<int, min_allocator
<int> > l2(l
, min_allocator
<int>());
70 assert(l2
.get_allocator() == min_allocator
<int>());
73 std::vector
<int, safe_allocator
<int> > l(3, 2, safe_allocator
<int>());
74 std::vector
<int, safe_allocator
<int> > l2(l
, safe_allocator
<int>());
76 assert(l2
.get_allocator() == safe_allocator
<int>());
87 static_assert(tests());