[PowerPC] Collect some CallLowering arguments into a struct. [NFC]
[llvm-project.git] / libcxx / test / std / containers / map_allocator_requirement_test_templates.h
blob7dc220f9367b7f3ce7cbc97bd021cfba67332d85
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 //===----------------------------------------------------------------------===//
8 #ifndef MAP_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
9 #define MAP_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
11 // <map>
12 // <unordered_map>
14 // class map
15 // class unordered_map
17 // insert(...);
18 // emplace(...);
19 // emplace_hint(...);
21 // UNSUPPORTED: c++98, c++03
23 #include <cassert>
25 #include "test_macros.h"
26 #include "count_new.h"
27 #include "container_test_types.h"
28 #include "assert_checkpoint.h"
31 template <class Container>
32 void testMapInsert()
34 typedef typename Container::value_type ValueTp;
35 ConstructController* cc = getConstructController();
36 cc->reset();
38 CHECKPOINT("Testing C::insert(const value_type&)");
39 Container c;
40 const ValueTp v(42, 1);
41 cc->expect<const ValueTp&>();
42 assert(c.insert(v).second);
43 assert(!cc->unchecked());
45 DisableAllocationGuard g;
46 const ValueTp v2(42, 1);
47 assert(c.insert(v2).second == false);
51 CHECKPOINT("Testing C::insert(value_type&)");
52 Container c;
53 ValueTp v(42, 1);
54 cc->expect<const ValueTp&>();
55 assert(c.insert(v).second);
56 assert(!cc->unchecked());
58 DisableAllocationGuard g;
59 ValueTp v2(42, 1);
60 assert(c.insert(v2).second == false);
64 CHECKPOINT("Testing C::insert(value_type&&)");
65 Container c;
66 ValueTp v(42, 1);
67 cc->expect<ValueTp&&>();
68 assert(c.insert(std::move(v)).second);
69 assert(!cc->unchecked());
71 DisableAllocationGuard g;
72 ValueTp v2(42, 1);
73 assert(c.insert(std::move(v2)).second == false);
77 CHECKPOINT("Testing C::insert(const value_type&&)");
78 Container c;
79 const ValueTp v(42, 1);
80 cc->expect<const ValueTp&>();
81 assert(c.insert(std::move(v)).second);
82 assert(!cc->unchecked());
84 DisableAllocationGuard g;
85 const ValueTp v2(42, 1);
86 assert(c.insert(std::move(v2)).second == false);
90 CHECKPOINT("Testing C::insert({key, value})");
91 Container c;
92 cc->expect<ValueTp&&>();
93 assert(c.insert({42, 1}).second);
94 assert(!cc->unchecked());
96 DisableAllocationGuard g;
97 const ValueTp v2(42, 1);
98 assert(c.insert(std::move(v2)).second == false);
102 CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
103 Container c;
104 std::initializer_list<ValueTp> il = { ValueTp(1, 1), ValueTp(2, 1) };
105 cc->expect<ValueTp const&>(2);
106 c.insert(il);
107 assert(!cc->unchecked());
109 DisableAllocationGuard g;
110 c.insert(il);
114 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
115 Container c;
116 const ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1) };
117 cc->expect<ValueTp const&>(3);
118 c.insert(std::begin(ValueList), std::end(ValueList));
119 assert(!cc->unchecked());
121 DisableAllocationGuard g;
122 c.insert(std::begin(ValueList), std::end(ValueList));
126 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
127 Container c;
128 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
129 cc->expect<ValueTp&&>(3);
130 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
131 std::move_iterator<ValueTp*>(std::end(ValueList)));
132 assert(!cc->unchecked());
134 DisableAllocationGuard g;
135 ValueTp ValueList2[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
136 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList2)),
137 std::move_iterator<ValueTp*>(std::end(ValueList2)));
141 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
142 Container c;
143 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
144 cc->expect<ValueTp const&>(3);
145 c.insert(std::begin(ValueList), std::end(ValueList));
146 assert(!cc->unchecked());
148 DisableAllocationGuard g;
149 c.insert(std::begin(ValueList), std::end(ValueList));
155 template <class Container>
156 void testMapInsertHint()
158 typedef typename Container::value_type ValueTp;
159 typedef typename Container::key_type Key;
160 typedef typename Container::mapped_type Mapped;
161 typedef typename std::pair<Key, Mapped> NonConstKeyPair;
162 typedef Container C;
163 typedef typename C::iterator It;
164 ConstructController* cc = getConstructController();
165 cc->reset();
167 CHECKPOINT("Testing C::insert(p, const value_type&)");
168 Container c;
169 const ValueTp v(42, 1);
170 cc->expect<const ValueTp&>();
171 It ret = c.insert(c.end(), v);
172 assert(ret != c.end());
173 assert(c.size() == 1);
174 assert(!cc->unchecked());
176 DisableAllocationGuard g;
177 const ValueTp v2(42, 1);
178 It ret2 = c.insert(c.begin(), v2);
179 assert(&(*ret2) == &(*ret));
180 assert(c.size() == 1);
184 CHECKPOINT("Testing C::insert(p, value_type&)");
185 Container c;
186 ValueTp v(42, 1);
187 cc->expect<ValueTp const&>();
188 It ret = c.insert(c.end(), v);
189 assert(ret != c.end());
190 assert(c.size() == 1);
191 assert(!cc->unchecked());
193 DisableAllocationGuard g;
194 ValueTp v2(42, 1);
195 It ret2 = c.insert(c.begin(), v2);
196 assert(&(*ret2) == &(*ret));
197 assert(c.size() == 1);
201 CHECKPOINT("Testing C::insert(p, value_type&&)");
202 Container c;
203 ValueTp v(42, 1);
204 cc->expect<ValueTp&&>();
205 It ret = c.insert(c.end(), std::move(v));
206 assert(ret != c.end());
207 assert(c.size() == 1);
208 assert(!cc->unchecked());
210 DisableAllocationGuard g;
211 ValueTp v2(42, 1);
212 It ret2 = c.insert(c.begin(), std::move(v2));
213 assert(&(*ret2) == &(*ret));
214 assert(c.size() == 1);
218 CHECKPOINT("Testing C::insert(p, {key, value})");
219 Container c;
220 cc->expect<ValueTp&&>();
221 It ret = c.insert(c.end(), {42, 1});
222 assert(ret != c.end());
223 assert(c.size() == 1);
224 assert(!cc->unchecked());
226 DisableAllocationGuard g;
227 It ret2 = c.insert(c.begin(), {42, 1});
228 assert(&(*ret2) == &(*ret));
229 assert(c.size() == 1);
233 CHECKPOINT("Testing C::insert(p, const value_type&&)");
234 Container c;
235 const ValueTp v(42, 1);
236 cc->expect<const ValueTp&>();
237 It ret = c.insert(c.end(), std::move(v));
238 assert(ret != c.end());
239 assert(c.size() == 1);
240 assert(!cc->unchecked());
242 DisableAllocationGuard g;
243 const ValueTp v2(42, 1);
244 It ret2 = c.insert(c.begin(), std::move(v2));
245 assert(&(*ret2) == &(*ret));
246 assert(c.size() == 1);
250 CHECKPOINT("Testing C::insert(p, pair<Key, Mapped> const&)");
251 Container c;
252 const NonConstKeyPair v(42, 1);
253 cc->expect<const NonConstKeyPair&>();
254 It ret = c.insert(c.end(), v);
255 assert(ret != c.end());
256 assert(c.size() == 1);
257 assert(!cc->unchecked());
259 DisableAllocationGuard g;
260 const NonConstKeyPair v2(42, 1);
261 It ret2 = c.insert(c.begin(), v2);
262 assert(&(*ret2) == &(*ret));
263 assert(c.size() == 1);
267 CHECKPOINT("Testing C::insert(p, pair<Key, Mapped>&&)");
268 Container c;
269 NonConstKeyPair v(42, 1);
270 cc->expect<NonConstKeyPair&&>();
271 It ret = c.insert(c.end(), std::move(v));
272 assert(ret != c.end());
273 assert(c.size() == 1);
274 assert(!cc->unchecked());
276 DisableAllocationGuard g;
277 NonConstKeyPair v2(42, 1);
278 It ret2 = c.insert(c.begin(), std::move(v2));
279 assert(&(*ret2) == &(*ret));
280 assert(c.size() == 1);
288 template <class Container>
289 void testMapEmplace()
291 typedef typename Container::value_type ValueTp;
292 typedef typename Container::key_type Key;
293 typedef typename Container::mapped_type Mapped;
294 typedef typename std::pair<Key, Mapped> NonConstKeyPair;
295 ConstructController* cc = getConstructController();
296 cc->reset();
298 CHECKPOINT("Testing C::emplace(const value_type&)");
299 Container c;
300 const ValueTp v(42, 1);
301 cc->expect<const ValueTp&>();
302 assert(c.emplace(v).second);
303 assert(!cc->unchecked());
305 DisableAllocationGuard g;
306 const ValueTp v2(42, 1);
307 assert(c.emplace(v2).second == false);
311 CHECKPOINT("Testing C::emplace(value_type&)");
312 Container c;
313 ValueTp v(42, 1);
314 cc->expect<ValueTp&>();
315 assert(c.emplace(v).second);
316 assert(!cc->unchecked());
318 DisableAllocationGuard g;
319 ValueTp v2(42, 1);
320 assert(c.emplace(v2).second == false);
324 CHECKPOINT("Testing C::emplace(value_type&&)");
325 Container c;
326 ValueTp v(42, 1);
327 cc->expect<ValueTp&&>();
328 assert(c.emplace(std::move(v)).second);
329 assert(!cc->unchecked());
331 DisableAllocationGuard g;
332 ValueTp v2(42, 1);
333 assert(c.emplace(std::move(v2)).second == false);
337 CHECKPOINT("Testing C::emplace(const value_type&&)");
338 Container c;
339 const ValueTp v(42, 1);
340 cc->expect<const ValueTp&&>();
341 assert(c.emplace(std::move(v)).second);
342 assert(!cc->unchecked());
344 DisableAllocationGuard g;
345 const ValueTp v2(42, 1);
346 assert(c.emplace(std::move(v2)).second == false);
350 CHECKPOINT("Testing C::emplace(pair<Key, Mapped> const&)");
351 Container c;
352 const NonConstKeyPair v(42, 1);
353 cc->expect<const NonConstKeyPair&>();
354 assert(c.emplace(v).second);
355 assert(!cc->unchecked());
357 DisableAllocationGuard g;
358 const NonConstKeyPair v2(42, 1);
359 assert(c.emplace(v2).second == false);
363 CHECKPOINT("Testing C::emplace(pair<Key, Mapped> &&)");
364 Container c;
365 NonConstKeyPair v(42, 1);
366 cc->expect<NonConstKeyPair&&>();
367 assert(c.emplace(std::move(v)).second);
368 assert(!cc->unchecked());
370 DisableAllocationGuard g;
371 NonConstKeyPair v2(42, 1);
372 assert(c.emplace(std::move(v2)).second == false);
376 CHECKPOINT("Testing C::emplace(const Key&, ConvertibleToMapped&&)");
377 Container c;
378 const Key k(42);
379 cc->expect<Key const&, int&&>();
380 assert(c.emplace(k, 1).second);
381 assert(!cc->unchecked());
383 DisableAllocationGuard g;
384 const Key k2(42);
385 assert(c.emplace(k2, 2).second == false);
389 CHECKPOINT("Testing C::emplace(Key&, Mapped&)");
390 Container c;
391 Key k(42);
392 Mapped m(1);
393 cc->expect<Key&, Mapped&>();
394 assert(c.emplace(k, m).second);
395 assert(!cc->unchecked());
397 DisableAllocationGuard g;
398 Key k2(42);
399 assert(c.emplace(k2, m).second == false);
403 CHECKPOINT("Testing C::emplace(Key&&, Mapped&&)");
404 Container c;
405 Key k(42);
406 Mapped m(1);
407 cc->expect<Key&&, Mapped&&>();
408 assert(c.emplace(std::move(k), std::move(m)).second);
409 assert(!cc->unchecked());
411 DisableAllocationGuard g;
412 Key k2(42);
413 Mapped m2(2);
414 assert(c.emplace(std::move(k2), std::move(m2)).second == false);
418 CHECKPOINT("Testing C::emplace(ConvertibleToKey&&, ConvertibleToMapped&&)");
419 Container c;
420 cc->expect<int&&, int&&>();
421 assert(c.emplace(42, 1).second);
422 assert(!cc->unchecked());
424 // test that emplacing a duplicate item allocates. We cannot optimize
425 // this case because int&& does not match the type of key exactly.
426 cc->expect<int&&, int&&>();
427 assert(c.emplace(42, 1).second == false);
428 assert(!cc->unchecked());
434 template <class Container>
435 void testMapEmplaceHint()
437 typedef typename Container::value_type ValueTp;
438 typedef typename Container::key_type Key;
439 typedef typename Container::mapped_type Mapped;
440 typedef typename std::pair<Key, Mapped> NonConstKeyPair;
441 typedef Container C;
442 typedef typename C::iterator It;
443 ConstructController* cc = getConstructController();
444 cc->reset();
446 CHECKPOINT("Testing C::emplace_hint(p, const value_type&)");
447 Container c;
448 const ValueTp v(42, 1);
449 cc->expect<const ValueTp&>();
450 It ret = c.emplace_hint(c.end(), v);
451 assert(ret != c.end());
452 assert(c.size() == 1);
453 assert(!cc->unchecked());
455 DisableAllocationGuard g;
456 const ValueTp v2(42, 1);
457 It ret2 = c.emplace_hint(c.begin(), v2);
458 assert(&(*ret2) == &(*ret));
459 assert(c.size() == 1);
463 CHECKPOINT("Testing C::emplace_hint(p, value_type&)");
464 Container c;
465 ValueTp v(42, 1);
466 cc->expect<ValueTp&>();
467 It ret = c.emplace_hint(c.end(), v);
468 assert(ret != c.end());
469 assert(c.size() == 1);
470 assert(!cc->unchecked());
472 DisableAllocationGuard g;
473 ValueTp v2(42, 1);
474 It ret2 = c.emplace_hint(c.begin(), v2);
475 assert(&(*ret2) == &(*ret));
476 assert(c.size() == 1);
480 CHECKPOINT("Testing C::emplace_hint(p, value_type&&)");
481 Container c;
482 ValueTp v(42, 1);
483 cc->expect<ValueTp&&>();
484 It ret = c.emplace_hint(c.end(), std::move(v));
485 assert(ret != c.end());
486 assert(c.size() == 1);
487 assert(!cc->unchecked());
489 DisableAllocationGuard g;
490 ValueTp v2(42, 1);
491 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
492 assert(&(*ret2) == &(*ret));
493 assert(c.size() == 1);
497 CHECKPOINT("Testing C::emplace_hint(p, const value_type&&)");
498 Container c;
499 const ValueTp v(42, 1);
500 cc->expect<const ValueTp&&>();
501 It ret = c.emplace_hint(c.end(), std::move(v));
502 assert(ret != c.end());
503 assert(c.size() == 1);
504 assert(!cc->unchecked());
506 DisableAllocationGuard g;
507 const ValueTp v2(42, 1);
508 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
509 assert(&(*ret2) == &(*ret));
510 assert(c.size() == 1);
514 CHECKPOINT("Testing C::emplace_hint(p, pair<Key, Mapped> const&)");
515 Container c;
516 const NonConstKeyPair v(42, 1);
517 cc->expect<const NonConstKeyPair&>();
518 It ret = c.emplace_hint(c.end(), v);
519 assert(ret != c.end());
520 assert(c.size() == 1);
521 assert(!cc->unchecked());
523 DisableAllocationGuard g;
524 const NonConstKeyPair v2(42, 1);
525 It ret2 = c.emplace_hint(c.begin(), v2);
526 assert(&(*ret2) == &(*ret));
527 assert(c.size() == 1);
531 CHECKPOINT("Testing C::emplace_hint(p, pair<Key, Mapped>&&)");
532 Container c;
533 NonConstKeyPair v(42, 1);
534 cc->expect<NonConstKeyPair&&>();
535 It ret = c.emplace_hint(c.end(), std::move(v));
536 assert(ret != c.end());
537 assert(c.size() == 1);
538 assert(!cc->unchecked());
540 DisableAllocationGuard g;
541 NonConstKeyPair v2(42, 1);
542 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
543 assert(&(*ret2) == &(*ret));
544 assert(c.size() == 1);
548 CHECKPOINT("Testing C::emplace_hint(p, const Key&, ConvertibleToMapped&&)");
549 Container c;
550 const Key k(42);
551 cc->expect<Key const&, int&&>();
552 It ret = c.emplace_hint(c.end(), k, 42);
553 assert(ret != c.end());
554 assert(c.size() == 1);
555 assert(!cc->unchecked());
557 DisableAllocationGuard g;
558 const Key k2(42);
559 It ret2 = c.emplace_hint(c.begin(), k2, 1);
560 assert(&(*ret2) == &(*ret));
561 assert(c.size() == 1);
565 CHECKPOINT("Testing C::emplace_hint(p, Key&, Mapped&)");
566 Container c;
567 Key k(42);
568 Mapped m(1);
569 cc->expect<Key&, Mapped&>();
570 It ret = c.emplace_hint(c.end(), k, m);
571 assert(ret != c.end());
572 assert(c.size() == 1);
573 assert(!cc->unchecked());
575 DisableAllocationGuard g;
576 Key k2(42);
577 Mapped m2(2);
578 It ret2 = c.emplace_hint(c.begin(), k2, m2);
579 assert(&(*ret2) == &(*ret));
580 assert(c.size() == 1);
584 CHECKPOINT("Testing C::emplace_hint(p, Key&&, Mapped&&)");
585 Container c;
586 Key k(42);
587 Mapped m(1);
588 cc->expect<Key&&, Mapped&&>();
589 It ret = c.emplace_hint(c.end(), std::move(k), std::move(m));
590 assert(ret != c.end());
591 assert(c.size() == 1);
592 assert(!cc->unchecked());
594 DisableAllocationGuard g;
595 Key k2(42);
596 Mapped m2(2);
597 It ret2 = c.emplace_hint(c.begin(), std::move(k2), std::move(m2));
598 assert(&(*ret2) == &(*ret));
599 assert(c.size() == 1);
603 CHECKPOINT("Testing C::emplace_hint(p, ConvertibleToKey&&, ConvertibleToMapped&&)");
604 Container c;
605 cc->expect<int&&, int&&>();
606 It ret = c.emplace_hint(c.end(), 42, 1);
607 assert(ret != c.end());
608 assert(c.size() == 1);
609 assert(!cc->unchecked());
611 cc->expect<int&&, int&&>();
612 It ret2 = c.emplace_hint(c.begin(), 42, 2);
613 assert(&(*ret2) == &(*ret));
614 assert(c.size() == 1);
615 assert(!cc->unchecked());
622 template <class Container>
623 void testMultimapInsert()
625 typedef typename Container::value_type ValueTp;
626 ConstructController* cc = getConstructController();
627 cc->reset();
629 CHECKPOINT("Testing C::insert(const value_type&)");
630 Container c;
631 const ValueTp v(42, 1);
632 cc->expect<const ValueTp&>();
633 c.insert(v);
634 assert(!cc->unchecked());
637 CHECKPOINT("Testing C::insert(value_type&)");
638 Container c;
639 ValueTp v(42, 1);
640 cc->expect<ValueTp&>();
641 c.insert(v);
642 assert(!cc->unchecked());
645 CHECKPOINT("Testing C::insert(value_type&&)");
646 Container c;
647 ValueTp v(42, 1);
648 cc->expect<ValueTp&&>();
649 c.insert(std::move(v));
650 assert(!cc->unchecked());
653 CHECKPOINT("Testing C::insert({key, value})");
654 Container c;
655 cc->expect<ValueTp&&>();
656 c.insert({42, 1});
657 assert(!cc->unchecked());
660 CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
661 Container c;
662 std::initializer_list<ValueTp> il = { ValueTp(1, 1), ValueTp(2, 1) };
663 cc->expect<ValueTp const&>(2);
664 c.insert(il);
665 assert(!cc->unchecked());
668 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
669 Container c;
670 const ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1) };
671 cc->expect<ValueTp const&>(3);
672 c.insert(std::begin(ValueList), std::end(ValueList));
673 assert(!cc->unchecked());
676 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
677 Container c;
678 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
679 cc->expect<ValueTp&&>(3);
680 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
681 std::move_iterator<ValueTp*>(std::end(ValueList)));
682 assert(!cc->unchecked());
685 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
686 Container c;
687 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
688 cc->expect<ValueTp&>(3);
689 c.insert(std::begin(ValueList), std::end(ValueList));
690 assert(!cc->unchecked());
695 template <class Container>
696 void testMultimapInsertHint()
698 typedef typename Container::value_type ValueTp;
699 ConstructController* cc = getConstructController();
700 cc->reset();
702 CHECKPOINT("Testing C::insert(p, const value_type&)");
703 Container c;
704 const ValueTp v(42, 1);
705 cc->expect<const ValueTp&>();
706 c.insert(c.begin(), v);
707 assert(!cc->unchecked());
710 CHECKPOINT("Testing C::insert(p, value_type&)");
711 Container c;
712 ValueTp v(42, 1);
713 cc->expect<ValueTp&>();
714 c.insert(c.begin(), v);
715 assert(!cc->unchecked());
718 CHECKPOINT("Testing C::insert(p, value_type&&)");
719 Container c;
720 ValueTp v(42, 1);
721 cc->expect<ValueTp&&>();
722 c.insert(c.begin(), std::move(v));
723 assert(!cc->unchecked());
726 CHECKPOINT("Testing C::insert(p, {key, value})");
727 Container c;
728 cc->expect<ValueTp&&>();
729 c.insert(c.begin(), {42, 1});
730 assert(!cc->unchecked());
734 #endif