Revert "[libc] Use best-fit binary trie to make malloc logarithmic" (#117065)
[llvm-project.git] / libcxx / test / std / containers / associative / map / map.special / non_member_swap.pass.cpp
blob18d991c15e4aca70b49f7a0e690ac9dbe75b7d12
1 //===----------------------------------------------------------------------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
9 // <map>
11 // class map
13 // template <class Key, class T, class Compare, class Allocator>
14 // void
15 // swap(map<Key, T, Compare, Allocator>& x, map<Key, T, Compare, Allocator>& y);
17 #include <map>
18 #include <cassert>
19 #include "test_macros.h"
20 #include "test_allocator.h"
21 #include "../../../test_compare.h"
22 #include "min_allocator.h"
24 int main(int, char**)
26 typedef std::pair<const int, double> V;
28 typedef std::map<int, double> M;
30 M m1;
31 M m2;
32 M m1_save = m1;
33 M m2_save = m2;
34 swap(m1, m2);
35 assert(m1 == m2_save);
36 assert(m2 == m1_save);
39 V ar2[] =
41 V(5, 5),
42 V(6, 6),
43 V(7, 7),
44 V(8, 8),
45 V(9, 9),
46 V(10, 10),
47 V(11, 11),
48 V(12, 12)
50 M m1;
51 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
52 M m1_save = m1;
53 M m2_save = m2;
54 swap(m1, m2);
55 assert(m1 == m2_save);
56 assert(m2 == m1_save);
59 V ar1[] =
61 V(1, 1),
62 V(2, 2),
63 V(3, 3),
64 V(4, 4)
66 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
67 M m2;
68 M m1_save = m1;
69 M m2_save = m2;
70 swap(m1, m2);
71 assert(m1 == m2_save);
72 assert(m2 == m1_save);
75 V ar1[] =
77 V(1, 1),
78 V(2, 2),
79 V(3, 3),
80 V(4, 4)
82 V ar2[] =
84 V(5, 5),
85 V(6, 6),
86 V(7, 7),
87 V(8, 8),
88 V(9, 9),
89 V(10, 10),
90 V(11, 11),
91 V(12, 12)
93 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
94 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
95 M m1_save = m1;
96 M m2_save = m2;
97 swap(m1, m2);
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;
106 V ar1[] =
108 V(1, 1),
109 V(2, 2),
110 V(3, 3),
111 V(4, 4)
113 V ar2[] =
115 V(5, 5),
116 V(6, 6),
117 V(7, 7),
118 V(8, 8),
119 V(9, 9),
120 V(10, 10),
121 V(11, 11),
122 V(12, 12)
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));
126 M m1_save = m1;
127 M m2_save = m2;
128 swap(m1, m2);
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;
140 V ar1[] =
142 V(1, 1),
143 V(2, 2),
144 V(3, 3),
145 V(4, 4)
147 V ar2[] =
149 V(5, 5),
150 V(6, 6),
151 V(7, 7),
152 V(8, 8),
153 V(9, 9),
154 V(10, 10),
155 V(11, 11),
156 V(12, 12)
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));
160 M m1_save = m1;
161 M m2_save = m2;
162 swap(m1, m2);
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;
174 M m1;
175 M m2;
176 M m1_save = m1;
177 M m2_save = m2;
178 swap(m1, m2);
179 assert(m1 == m2_save);
180 assert(m2 == m1_save);
183 V ar2[] =
185 V(5, 5),
186 V(6, 6),
187 V(7, 7),
188 V(8, 8),
189 V(9, 9),
190 V(10, 10),
191 V(11, 11),
192 V(12, 12)
194 M m1;
195 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
196 M m1_save = m1;
197 M m2_save = m2;
198 swap(m1, m2);
199 assert(m1 == m2_save);
200 assert(m2 == m1_save);
203 V ar1[] =
205 V(1, 1),
206 V(2, 2),
207 V(3, 3),
208 V(4, 4)
210 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
211 M m2;
212 M m1_save = m1;
213 M m2_save = m2;
214 swap(m1, m2);
215 assert(m1 == m2_save);
216 assert(m2 == m1_save);
219 V ar1[] =
221 V(1, 1),
222 V(2, 2),
223 V(3, 3),
224 V(4, 4)
226 V ar2[] =
228 V(5, 5),
229 V(6, 6),
230 V(7, 7),
231 V(8, 8),
232 V(9, 9),
233 V(10, 10),
234 V(11, 11),
235 V(12, 12)
237 M m1(ar1, ar1+sizeof(ar1)/sizeof(ar1[0]));
238 M m2(ar2, ar2+sizeof(ar2)/sizeof(ar2[0]));
239 M m1_save = m1;
240 M m2_save = m2;
241 swap(m1, m2);
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;
250 V ar1[] =
252 V(1, 1),
253 V(2, 2),
254 V(3, 3),
255 V(4, 4)
257 V ar2[] =
259 V(5, 5),
260 V(6, 6),
261 V(7, 7),
262 V(8, 8),
263 V(9, 9),
264 V(10, 10),
265 V(11, 11),
266 V(12, 12)
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());
270 M m1_save = m1;
271 M m2_save = m2;
272 swap(m1, m2);
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());
280 #endif
282 return 0;