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 //===----------------------------------------------------------------------===//
15 // map(map&& m, const allocator_type& a);
21 #include "test_macros.h"
23 #include "../../../test_compare.h"
24 #include "test_allocator.h"
25 #include "min_allocator.h"
31 typedef std::pair
<MoveOnly
, MoveOnly
> V
;
32 typedef std::pair
<const MoveOnly
, MoveOnly
> VC
;
33 typedef test_less
<MoveOnly
> C
;
34 typedef test_allocator
<VC
> A
;
35 typedef std::map
<MoveOnly
, MoveOnly
, C
, A
> M
;
36 typedef std::move_iterator
<V
*> I
;
49 M
m1(I(a1
), I(a1
+sizeof(a1
)/sizeof(a1
[0])), C(5), A(7));
62 M
m2(I(a2
), I(a2
+sizeof(a2
)/sizeof(a2
[0])), C(5), A(7));
63 M
m3(std::move(m1
), A(7));
65 assert(m3
.get_allocator() == A(7));
66 assert(m3
.key_comp() == C(5));
67 LIBCPP_ASSERT(m1
.empty());
70 typedef std::pair
<MoveOnly
, MoveOnly
> V
;
71 typedef std::pair
<const MoveOnly
, MoveOnly
> VC
;
72 typedef test_less
<MoveOnly
> C
;
73 typedef test_allocator
<VC
> A
;
74 typedef std::map
<MoveOnly
, MoveOnly
, C
, A
> M
;
75 typedef std::move_iterator
<V
*> I
;
88 M
m1(I(a1
), I(a1
+sizeof(a1
)/sizeof(a1
[0])), C(5), A(7));
101 M
m2(I(a2
), I(a2
+sizeof(a2
)/sizeof(a2
[0])), C(5), A(7));
102 M
m3(std::move(m1
), A(5));
104 assert(m3
.get_allocator() == A(5));
105 assert(m3
.key_comp() == C(5));
106 LIBCPP_ASSERT(m1
.empty());
109 typedef std::pair
<MoveOnly
, MoveOnly
> V
;
110 typedef std::pair
<const MoveOnly
, MoveOnly
> VC
;
111 typedef test_less
<MoveOnly
> C
;
112 typedef other_allocator
<VC
> A
;
113 typedef std::map
<MoveOnly
, MoveOnly
, C
, A
> M
;
114 typedef std::move_iterator
<V
*> I
;
127 M
m1(I(a1
), I(a1
+sizeof(a1
)/sizeof(a1
[0])), C(5), A(7));
140 M
m2(I(a2
), I(a2
+sizeof(a2
)/sizeof(a2
[0])), C(5), A(7));
141 M
m3(std::move(m1
), A(5));
143 assert(m3
.get_allocator() == A(5));
144 assert(m3
.key_comp() == C(5));
145 LIBCPP_ASSERT(m1
.empty());
148 typedef Counter
<int> T
;
149 typedef std::pair
<int, T
> V
;
150 typedef std::pair
<const int, T
> VC
;
151 typedef test_allocator
<VC
> A
;
152 typedef std::less
<int> C
;
153 typedef std::map
<const int, T
, C
, A
> M
;
155 Counter_base::gConstructed
= 0;
169 const std::size_t num
= sizeof(a1
)/sizeof(a1
[0]);
170 assert(Counter_base::gConstructed
== num
);
172 M
m1(I(a1
), I(a1
+num
), C(), A());
173 assert(Counter_base::gConstructed
== num
+3);
177 assert(Counter_base::gConstructed
== num
+6);
179 M
m3(std::move(m1
), A());
181 LIBCPP_ASSERT(m1
.empty());
182 assert(Counter_base::gConstructed
>= (int)(num
+6));
183 assert(Counter_base::gConstructed
<= (int)(num
+6+m1
.size()));
186 M
m4(std::move(m2
), A(5));
187 assert(Counter_base::gConstructed
>= (int)(num
+6));
188 assert(Counter_base::gConstructed
<= (int)(num
+6+m1
.size()+m2
.size()));
190 LIBCPP_ASSERT(m2
.empty());
192 assert(Counter_base::gConstructed
>= (int)(num
+3));
193 assert(Counter_base::gConstructed
<= (int)(num
+3+m1
.size()+m2
.size()));
195 assert(Counter_base::gConstructed
== 0);
198 typedef std::pair
<MoveOnly
, MoveOnly
> V
;
199 typedef std::pair
<const MoveOnly
, MoveOnly
> VC
;
200 typedef test_less
<MoveOnly
> C
;
201 typedef min_allocator
<VC
> A
;
202 typedef std::map
<MoveOnly
, MoveOnly
, C
, A
> M
;
203 typedef std::move_iterator
<V
*> I
;
216 M
m1(I(a1
), I(a1
+sizeof(a1
)/sizeof(a1
[0])), C(5), A());
229 M
m2(I(a2
), I(a2
+sizeof(a2
)/sizeof(a2
[0])), C(5), A());
230 M
m3(std::move(m1
), A());
232 assert(m3
.get_allocator() == A());
233 assert(m3
.key_comp() == C(5));
234 LIBCPP_ASSERT(m1
.empty());
237 typedef std::pair
<MoveOnly
, MoveOnly
> V
;
238 typedef std::pair
<const MoveOnly
, MoveOnly
> VC
;
239 typedef test_less
<MoveOnly
> C
;
240 typedef explicit_allocator
<VC
> A
;
241 typedef std::map
<MoveOnly
, MoveOnly
, C
, A
> M
;
242 typedef std::move_iterator
<V
*> I
;
255 M
m1(I(a1
), I(a1
+sizeof(a1
)/sizeof(a1
[0])), C(5), A
{});
268 M
m2(I(a2
), I(a2
+sizeof(a2
)/sizeof(a2
[0])), C(5), A
{});
269 M
m3(std::move(m1
), A
{});
271 assert(m3
.get_allocator() == A
{});
272 assert(m3
.key_comp() == C(5));
273 LIBCPP_ASSERT(m1
.empty());