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& operator=(const vector& c);
15 #include "test_macros.h"
16 #include "test_allocator.h"
17 #include "min_allocator.h"
18 #include "allocators.h"
20 TEST_CONSTEXPR_CXX20
bool tests() {
22 std::vector
<int, test_allocator
<int> > l(3, 2, test_allocator
<int>(5));
23 std::vector
<int, test_allocator
<int> > l2(l
, test_allocator
<int>(3));
26 assert(l2
.get_allocator() == test_allocator
<int>(3));
29 std::vector
<int, other_allocator
<int> > l(3, 2, other_allocator
<int>(5));
30 std::vector
<int, other_allocator
<int> > l2(l
, other_allocator
<int>(3));
33 assert(l2
.get_allocator() == other_allocator
<int>(5));
35 #if TEST_STD_VER >= 11
37 // Test with Allocator::propagate_on_container_copy_assignment == false_type
38 using Alloc
= NonPOCCAAllocator
<int>;
39 bool copy_assigned_into
= false;
40 std::vector
<int, Alloc
> l(3, 2, Alloc(5, nullptr));
41 std::vector
<int, Alloc
> l2(l
, Alloc(3, ©_assigned_into
));
42 assert(!copy_assigned_into
);
44 assert(!copy_assigned_into
);
46 assert(l2
.get_allocator() == Alloc(3, nullptr));
49 // Test with Allocator::propagate_on_container_copy_assignment == true_type
50 // and equal allocators
51 using Alloc
= POCCAAllocator
<int>;
52 bool copy_assigned_into
= false;
53 std::vector
<int, Alloc
> l(3, 2, Alloc(5, nullptr));
54 std::vector
<int, Alloc
> l2(l
, Alloc(5, ©_assigned_into
));
55 assert(!copy_assigned_into
);
57 assert(copy_assigned_into
);
59 assert(l2
.get_allocator() == Alloc(5, nullptr));
62 // Test with Allocator::propagate_on_container_copy_assignment == true_type
63 // and unequal allocators
64 using Alloc
= POCCAAllocator
<int>;
65 bool copy_assigned_into
= false;
66 std::vector
<int, Alloc
> l(3, 2, Alloc(5, nullptr));
67 std::vector
<int, Alloc
> l2(l
, Alloc(3, ©_assigned_into
));
68 assert(!copy_assigned_into
);
70 assert(copy_assigned_into
);
72 assert(l2
.get_allocator() == Alloc(5, nullptr));
75 std::vector
<int, min_allocator
<int> > l(3, 2, min_allocator
<int>());
76 std::vector
<int, min_allocator
<int> > l2(l
, min_allocator
<int>());
79 assert(l2
.get_allocator() == min_allocator
<int>());
82 std::vector
<int, safe_allocator
<int> > l(3, 2, safe_allocator
<int>());
83 std::vector
<int, safe_allocator
<int> > l2(l
, safe_allocator
<int>());
86 assert(l2
.get_allocator() == safe_allocator
<int>());
97 static_assert(tests());