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 // template <class Key, class T, class Compare, class Allocator>
15 // swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y);
19 #include "test_macros.h"
20 #include "test_allocator.h"
21 #include "../../../test_compare.h"
22 #include "min_allocator.h"
26 typedef std::pair
<const int, double> V
;
28 typedef std::map
<int, double> M
;
35 assert(m1
== m2_save
);
36 assert(m2
== m1_save
);
51 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]));
55 assert(m1
== m2_save
);
56 assert(m2
== m1_save
);
66 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]));
71 assert(m1
== m2_save
);
72 assert(m2
== m1_save
);
93 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]));
94 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]));
98 assert(m1
== m2_save
);
99 assert(m2
== m1_save
);
103 typedef test_allocator
<V
> A
;
104 typedef test_less
<int> C
;
105 typedef std::map
<int, double, C
, A
> M
;
124 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]), C(1), A(1, 1));
125 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]), C(2), A(1, 2));
129 assert(m1
== m2_save
);
130 assert(m2
== m1_save
);
131 assert(m1
.key_comp() == C(2));
132 assert(m1
.get_allocator().get_id() == 1); // not swapped
133 assert(m2
.key_comp() == C(1));
134 assert(m2
.get_allocator().get_id() == 2);
137 typedef other_allocator
<V
> A
;
138 typedef test_less
<int> C
;
139 typedef std::map
<int, double, C
, A
> M
;
158 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]), C(1), A(1));
159 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]), C(2), A(2));
163 assert(m1
== m2_save
);
164 assert(m2
== m1_save
);
165 assert(m1
.key_comp() == C(2));
166 assert(m1
.get_allocator() == A(2));
167 assert(m2
.key_comp() == C(1));
168 assert(m2
.get_allocator() == A(1));
170 #if TEST_STD_VER >= 11
172 typedef std::map
<int, double, std::less
<int>, min_allocator
<V
>> M
;
179 assert(m1
== m2_save
);
180 assert(m2
== m1_save
);
195 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]));
199 assert(m1
== m2_save
);
200 assert(m2
== m1_save
);
210 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]));
215 assert(m1
== m2_save
);
216 assert(m2
== m1_save
);
237 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]));
238 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]));
242 assert(m1
== m2_save
);
243 assert(m2
== m1_save
);
247 typedef min_allocator
<V
> A
;
248 typedef test_less
<int> C
;
249 typedef std::map
<int, double, C
, A
> M
;
268 M
m1(ar1
, ar1
+sizeof(ar1
)/sizeof(ar1
[0]), C(1), A());
269 M
m2(ar2
, ar2
+sizeof(ar2
)/sizeof(ar2
[0]), C(2), A());
273 assert(m1
== m2_save
);
274 assert(m2
== m1_save
);
275 assert(m1
.key_comp() == C(2));
276 assert(m1
.get_allocator() == A());
277 assert(m2
.key_comp() == C(1));
278 assert(m2
.get_allocator() == A());