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 //===----------------------------------------------------------------------===//
13 // vector(vector&& c);
17 #include "test_macros.h"
18 #include "test_allocator.h"
19 #include "min_allocator.h"
21 TEST_CONSTEXPR_CXX20
bool tests()
23 test_allocator_statistics alloc_stats
;
25 std::vector
<bool, test_allocator
<bool> > l(test_allocator
<bool>(5, &alloc_stats
));
26 std::vector
<bool, test_allocator
<bool> > lo(test_allocator
<bool>(5, &alloc_stats
));
27 for (int i
= 1; i
<= 3; ++i
)
32 std::vector
<bool, test_allocator
<bool> > l2
= std::move(l
);
35 assert(l2
.get_allocator() == lo
.get_allocator());
38 std::vector
<bool, other_allocator
<bool> > l(other_allocator
<bool>(5));
39 std::vector
<bool, other_allocator
<bool> > lo(other_allocator
<bool>(5));
40 for (int i
= 1; i
<= 3; ++i
)
45 std::vector
<bool, other_allocator
<bool> > l2
= std::move(l
);
48 assert(l2
.get_allocator() == lo
.get_allocator());
51 std::vector
<bool, min_allocator
<bool> > l(min_allocator
<bool>{});
52 std::vector
<bool, min_allocator
<bool> > lo(min_allocator
<bool>{});
53 for (int i
= 1; i
<= 3; ++i
)
58 std::vector
<bool, min_allocator
<bool> > l2
= std::move(l
);
61 assert(l2
.get_allocator() == lo
.get_allocator());
65 using Vect
= std::vector
<bool, test_allocator
<bool> >;
66 using AllocT
= Vect::allocator_type
;
67 Vect
v(test_allocator
<bool>(42, 101, &alloc_stats
));
68 assert(alloc_stats
.count
== 1);
70 const AllocT
& a
= v
.get_allocator();
71 assert(alloc_stats
.count
== 2);
72 assert(a
.get_data() == 42);
73 assert(a
.get_id() == 101);
75 assert(alloc_stats
.count
== 1);
76 alloc_stats
.clear_ctor_counters();
78 Vect v2
= std::move(v
);
79 assert(alloc_stats
.count
== 2);
80 assert(alloc_stats
.copied
== 0);
81 assert(alloc_stats
.moved
== 1);
83 const AllocT
& a
= v
.get_allocator();
84 assert(a
.get_id() == test_alloc_base::moved_value
);
85 assert(a
.get_data() == test_alloc_base::moved_value
);
88 const AllocT
& a
= v2
.get_allocator();
89 assert(a
.get_id() == 101);
90 assert(a
.get_data() == 42);
100 #if TEST_STD_VER > 17
101 static_assert(tests());