[PowerPC][NFC] Cleanup PPCCTRLoopsVerify pass
[llvm-project.git] / libcxx / test / std / containers / map_allocator_requirement_test_templates.h
blob65d57737733fbf375567c5176d1b4ae9b2310024
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++03
23 #include <cassert>
25 #include "test_macros.h"
26 #include "count_new.h"
27 #include "container_test_types.h"
30 template <class Container>
31 void testMapInsert()
33 typedef typename Container::value_type ValueTp;
34 ConstructController* cc = getConstructController();
35 cc->reset();
37 // Testing C::insert(const value_type&)
38 Container c;
39 const ValueTp v(42, 1);
40 cc->expect<const ValueTp&>();
41 assert(c.insert(v).second);
42 assert(!cc->unchecked());
44 DisableAllocationGuard g;
45 const ValueTp v2(42, 1);
46 assert(c.insert(v2).second == false);
50 // Testing C::insert(value_type&)
51 Container c;
52 ValueTp v(42, 1);
53 cc->expect<const ValueTp&>();
54 assert(c.insert(v).second);
55 assert(!cc->unchecked());
57 DisableAllocationGuard g;
58 ValueTp v2(42, 1);
59 assert(c.insert(v2).second == false);
63 // Testing C::insert(value_type&&)
64 Container c;
65 ValueTp v(42, 1);
66 cc->expect<ValueTp&&>();
67 assert(c.insert(std::move(v)).second);
68 assert(!cc->unchecked());
70 DisableAllocationGuard g;
71 ValueTp v2(42, 1);
72 assert(c.insert(std::move(v2)).second == false);
76 // Testing C::insert(const value_type&&)
77 Container c;
78 const ValueTp v(42, 1);
79 cc->expect<const ValueTp&>();
80 assert(c.insert(std::move(v)).second);
81 assert(!cc->unchecked());
83 DisableAllocationGuard g;
84 const ValueTp v2(42, 1);
85 assert(c.insert(std::move(v2)).second == false);
89 // Testing C::insert({key, value})
90 Container c;
91 cc->expect<ValueTp&&>();
92 assert(c.insert({42, 1}).second);
93 assert(!cc->unchecked());
95 DisableAllocationGuard g;
96 const ValueTp v2(42, 1);
97 assert(c.insert(std::move(v2)).second == false);
101 // Testing C::insert(std::initializer_list<ValueTp>)
102 Container c;
103 std::initializer_list<ValueTp> il = { ValueTp(1, 1), ValueTp(2, 1) };
104 cc->expect<ValueTp const&>(2);
105 c.insert(il);
106 assert(!cc->unchecked());
108 DisableAllocationGuard g;
109 c.insert(il);
113 // Testing C::insert(Iter, Iter) for *Iter = value_type const&
114 Container c;
115 const ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1) };
116 cc->expect<ValueTp const&>(3);
117 c.insert(std::begin(ValueList), std::end(ValueList));
118 assert(!cc->unchecked());
120 DisableAllocationGuard g;
121 c.insert(std::begin(ValueList), std::end(ValueList));
125 // Testing C::insert(Iter, Iter) for *Iter = value_type&&
126 Container c;
127 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
128 cc->expect<ValueTp&&>(3);
129 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
130 std::move_iterator<ValueTp*>(std::end(ValueList)));
131 assert(!cc->unchecked());
133 DisableAllocationGuard g;
134 ValueTp ValueList2[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
135 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList2)),
136 std::move_iterator<ValueTp*>(std::end(ValueList2)));
140 // Testing C::insert(Iter, Iter) for *Iter = value_type&
141 Container c;
142 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
143 cc->expect<ValueTp const&>(3);
144 c.insert(std::begin(ValueList), std::end(ValueList));
145 assert(!cc->unchecked());
147 DisableAllocationGuard g;
148 c.insert(std::begin(ValueList), std::end(ValueList));
154 template <class Container>
155 void testMapInsertHint()
157 typedef typename Container::value_type ValueTp;
158 typedef typename Container::key_type Key;
159 typedef typename Container::mapped_type Mapped;
160 typedef typename std::pair<Key, Mapped> NonConstKeyPair;
161 typedef Container C;
162 typedef typename C::iterator It;
163 ConstructController* cc = getConstructController();
164 cc->reset();
166 // Testing C::insert(p, const value_type&)
167 Container c;
168 const ValueTp v(42, 1);
169 cc->expect<const ValueTp&>();
170 It ret = c.insert(c.end(), v);
171 assert(ret != c.end());
172 assert(c.size() == 1);
173 assert(!cc->unchecked());
175 DisableAllocationGuard g;
176 const ValueTp v2(42, 1);
177 It ret2 = c.insert(c.begin(), v2);
178 assert(&(*ret2) == &(*ret));
179 assert(c.size() == 1);
183 // Testing C::insert(p, value_type&)
184 Container c;
185 ValueTp v(42, 1);
186 cc->expect<ValueTp const&>();
187 It ret = c.insert(c.end(), v);
188 assert(ret != c.end());
189 assert(c.size() == 1);
190 assert(!cc->unchecked());
192 DisableAllocationGuard g;
193 ValueTp v2(42, 1);
194 It ret2 = c.insert(c.begin(), v2);
195 assert(&(*ret2) == &(*ret));
196 assert(c.size() == 1);
200 // Testing C::insert(p, value_type&&)
201 Container c;
202 ValueTp v(42, 1);
203 cc->expect<ValueTp&&>();
204 It ret = c.insert(c.end(), std::move(v));
205 assert(ret != c.end());
206 assert(c.size() == 1);
207 assert(!cc->unchecked());
209 DisableAllocationGuard g;
210 ValueTp v2(42, 1);
211 It ret2 = c.insert(c.begin(), std::move(v2));
212 assert(&(*ret2) == &(*ret));
213 assert(c.size() == 1);
217 // Testing C::insert(p, {key, value})
218 Container c;
219 cc->expect<ValueTp&&>();
220 It ret = c.insert(c.end(), {42, 1});
221 assert(ret != c.end());
222 assert(c.size() == 1);
223 assert(!cc->unchecked());
225 DisableAllocationGuard g;
226 It ret2 = c.insert(c.begin(), {42, 1});
227 assert(&(*ret2) == &(*ret));
228 assert(c.size() == 1);
232 // Testing C::insert(p, const value_type&&)
233 Container c;
234 const ValueTp v(42, 1);
235 cc->expect<const ValueTp&>();
236 It ret = c.insert(c.end(), std::move(v));
237 assert(ret != c.end());
238 assert(c.size() == 1);
239 assert(!cc->unchecked());
241 DisableAllocationGuard g;
242 const ValueTp v2(42, 1);
243 It ret2 = c.insert(c.begin(), std::move(v2));
244 assert(&(*ret2) == &(*ret));
245 assert(c.size() == 1);
249 // Testing C::insert(p, pair<Key, Mapped> const&)
250 Container c;
251 const NonConstKeyPair v(42, 1);
252 cc->expect<const NonConstKeyPair&>();
253 It ret = c.insert(c.end(), v);
254 assert(ret != c.end());
255 assert(c.size() == 1);
256 assert(!cc->unchecked());
258 DisableAllocationGuard g;
259 const NonConstKeyPair v2(42, 1);
260 It ret2 = c.insert(c.begin(), v2);
261 assert(&(*ret2) == &(*ret));
262 assert(c.size() == 1);
266 // Testing C::insert(p, pair<Key, Mapped>&&)
267 Container c;
268 NonConstKeyPair v(42, 1);
269 cc->expect<NonConstKeyPair&&>();
270 It ret = c.insert(c.end(), std::move(v));
271 assert(ret != c.end());
272 assert(c.size() == 1);
273 assert(!cc->unchecked());
275 DisableAllocationGuard g;
276 NonConstKeyPair v2(42, 1);
277 It ret2 = c.insert(c.begin(), std::move(v2));
278 assert(&(*ret2) == &(*ret));
279 assert(c.size() == 1);
287 template <class Container>
288 void testMapEmplace()
290 typedef typename Container::value_type ValueTp;
291 typedef typename Container::key_type Key;
292 typedef typename Container::mapped_type Mapped;
293 typedef typename std::pair<Key, Mapped> NonConstKeyPair;
294 ConstructController* cc = getConstructController();
295 cc->reset();
297 // Testing C::emplace(const value_type&)
298 Container c;
299 const ValueTp v(42, 1);
300 cc->expect<const ValueTp&>();
301 assert(c.emplace(v).second);
302 assert(!cc->unchecked());
304 DisableAllocationGuard g;
305 const ValueTp v2(42, 1);
306 assert(c.emplace(v2).second == false);
310 // Testing C::emplace(value_type&)
311 Container c;
312 ValueTp v(42, 1);
313 cc->expect<ValueTp&>();
314 assert(c.emplace(v).second);
315 assert(!cc->unchecked());
317 DisableAllocationGuard g;
318 ValueTp v2(42, 1);
319 assert(c.emplace(v2).second == false);
323 // Testing C::emplace(value_type&&)
324 Container c;
325 ValueTp v(42, 1);
326 cc->expect<ValueTp&&>();
327 assert(c.emplace(std::move(v)).second);
328 assert(!cc->unchecked());
330 DisableAllocationGuard g;
331 ValueTp v2(42, 1);
332 assert(c.emplace(std::move(v2)).second == false);
336 // Testing C::emplace(const value_type&&)
337 Container c;
338 const ValueTp v(42, 1);
339 cc->expect<const ValueTp&&>();
340 assert(c.emplace(std::move(v)).second);
341 assert(!cc->unchecked());
343 DisableAllocationGuard g;
344 const ValueTp v2(42, 1);
345 assert(c.emplace(std::move(v2)).second == false);
349 // Testing C::emplace(pair<Key, Mapped> const&)
350 Container c;
351 const NonConstKeyPair v(42, 1);
352 cc->expect<const NonConstKeyPair&>();
353 assert(c.emplace(v).second);
354 assert(!cc->unchecked());
356 DisableAllocationGuard g;
357 const NonConstKeyPair v2(42, 1);
358 assert(c.emplace(v2).second == false);
362 // Testing C::emplace(pair<Key, Mapped> &&)
363 Container c;
364 NonConstKeyPair v(42, 1);
365 cc->expect<NonConstKeyPair&&>();
366 assert(c.emplace(std::move(v)).second);
367 assert(!cc->unchecked());
369 DisableAllocationGuard g;
370 NonConstKeyPair v2(42, 1);
371 assert(c.emplace(std::move(v2)).second == false);
375 // Testing C::emplace(const Key&, ConvertibleToMapped&&)
376 Container c;
377 const Key k(42);
378 cc->expect<Key const&, int&&>();
379 assert(c.emplace(k, 1).second);
380 assert(!cc->unchecked());
382 DisableAllocationGuard g;
383 const Key k2(42);
384 assert(c.emplace(k2, 2).second == false);
388 // Testing C::emplace(Key&, Mapped&)
389 Container c;
390 Key k(42);
391 Mapped m(1);
392 cc->expect<Key&, Mapped&>();
393 assert(c.emplace(k, m).second);
394 assert(!cc->unchecked());
396 DisableAllocationGuard g;
397 Key k2(42);
398 assert(c.emplace(k2, m).second == false);
402 // Testing C::emplace(Key&&, Mapped&&)
403 Container c;
404 Key k(42);
405 Mapped m(1);
406 cc->expect<Key&&, Mapped&&>();
407 assert(c.emplace(std::move(k), std::move(m)).second);
408 assert(!cc->unchecked());
410 DisableAllocationGuard g;
411 Key k2(42);
412 Mapped m2(2);
413 assert(c.emplace(std::move(k2), std::move(m2)).second == false);
417 // Testing C::emplace(ConvertibleToKey&&, ConvertibleToMapped&&)
418 Container c;
419 cc->expect<int&&, int&&>();
420 assert(c.emplace(42, 1).second);
421 assert(!cc->unchecked());
423 // test that emplacing a duplicate item allocates. We cannot optimize
424 // this case because int&& does not match the type of key exactly.
425 cc->expect<int&&, int&&>();
426 assert(c.emplace(42, 1).second == false);
427 assert(!cc->unchecked());
433 template <class Container>
434 void testMapEmplaceHint()
436 typedef typename Container::value_type ValueTp;
437 typedef typename Container::key_type Key;
438 typedef typename Container::mapped_type Mapped;
439 typedef typename std::pair<Key, Mapped> NonConstKeyPair;
440 typedef Container C;
441 typedef typename C::iterator It;
442 ConstructController* cc = getConstructController();
443 cc->reset();
445 // Testing C::emplace_hint(p, const value_type&)
446 Container c;
447 const ValueTp v(42, 1);
448 cc->expect<const ValueTp&>();
449 It ret = c.emplace_hint(c.end(), v);
450 assert(ret != c.end());
451 assert(c.size() == 1);
452 assert(!cc->unchecked());
454 DisableAllocationGuard g;
455 const ValueTp v2(42, 1);
456 It ret2 = c.emplace_hint(c.begin(), v2);
457 assert(&(*ret2) == &(*ret));
458 assert(c.size() == 1);
462 // Testing C::emplace_hint(p, value_type&)
463 Container c;
464 ValueTp v(42, 1);
465 cc->expect<ValueTp&>();
466 It ret = c.emplace_hint(c.end(), v);
467 assert(ret != c.end());
468 assert(c.size() == 1);
469 assert(!cc->unchecked());
471 DisableAllocationGuard g;
472 ValueTp v2(42, 1);
473 It ret2 = c.emplace_hint(c.begin(), v2);
474 assert(&(*ret2) == &(*ret));
475 assert(c.size() == 1);
479 // Testing C::emplace_hint(p, value_type&&)
480 Container c;
481 ValueTp v(42, 1);
482 cc->expect<ValueTp&&>();
483 It ret = c.emplace_hint(c.end(), std::move(v));
484 assert(ret != c.end());
485 assert(c.size() == 1);
486 assert(!cc->unchecked());
488 DisableAllocationGuard g;
489 ValueTp v2(42, 1);
490 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
491 assert(&(*ret2) == &(*ret));
492 assert(c.size() == 1);
496 // Testing C::emplace_hint(p, const value_type&&)
497 Container c;
498 const ValueTp v(42, 1);
499 cc->expect<const ValueTp&&>();
500 It ret = c.emplace_hint(c.end(), std::move(v));
501 assert(ret != c.end());
502 assert(c.size() == 1);
503 assert(!cc->unchecked());
505 DisableAllocationGuard g;
506 const ValueTp v2(42, 1);
507 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
508 assert(&(*ret2) == &(*ret));
509 assert(c.size() == 1);
513 // Testing C::emplace_hint(p, pair<Key, Mapped> const&)
514 Container c;
515 const NonConstKeyPair v(42, 1);
516 cc->expect<const NonConstKeyPair&>();
517 It ret = c.emplace_hint(c.end(), v);
518 assert(ret != c.end());
519 assert(c.size() == 1);
520 assert(!cc->unchecked());
522 DisableAllocationGuard g;
523 const NonConstKeyPair v2(42, 1);
524 It ret2 = c.emplace_hint(c.begin(), v2);
525 assert(&(*ret2) == &(*ret));
526 assert(c.size() == 1);
530 // Testing C::emplace_hint(p, pair<Key, Mapped>&&)
531 Container c;
532 NonConstKeyPair v(42, 1);
533 cc->expect<NonConstKeyPair&&>();
534 It ret = c.emplace_hint(c.end(), std::move(v));
535 assert(ret != c.end());
536 assert(c.size() == 1);
537 assert(!cc->unchecked());
539 DisableAllocationGuard g;
540 NonConstKeyPair v2(42, 1);
541 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
542 assert(&(*ret2) == &(*ret));
543 assert(c.size() == 1);
547 // Testing C::emplace_hint(p, const Key&, ConvertibleToMapped&&)
548 Container c;
549 const Key k(42);
550 cc->expect<Key const&, int&&>();
551 It ret = c.emplace_hint(c.end(), k, 42);
552 assert(ret != c.end());
553 assert(c.size() == 1);
554 assert(!cc->unchecked());
556 DisableAllocationGuard g;
557 const Key k2(42);
558 It ret2 = c.emplace_hint(c.begin(), k2, 1);
559 assert(&(*ret2) == &(*ret));
560 assert(c.size() == 1);
564 // Testing C::emplace_hint(p, Key&, Mapped&)
565 Container c;
566 Key k(42);
567 Mapped m(1);
568 cc->expect<Key&, Mapped&>();
569 It ret = c.emplace_hint(c.end(), k, m);
570 assert(ret != c.end());
571 assert(c.size() == 1);
572 assert(!cc->unchecked());
574 DisableAllocationGuard g;
575 Key k2(42);
576 Mapped m2(2);
577 It ret2 = c.emplace_hint(c.begin(), k2, m2);
578 assert(&(*ret2) == &(*ret));
579 assert(c.size() == 1);
583 // Testing C::emplace_hint(p, Key&&, Mapped&&)
584 Container c;
585 Key k(42);
586 Mapped m(1);
587 cc->expect<Key&&, Mapped&&>();
588 It ret = c.emplace_hint(c.end(), std::move(k), std::move(m));
589 assert(ret != c.end());
590 assert(c.size() == 1);
591 assert(!cc->unchecked());
593 DisableAllocationGuard g;
594 Key k2(42);
595 Mapped m2(2);
596 It ret2 = c.emplace_hint(c.begin(), std::move(k2), std::move(m2));
597 assert(&(*ret2) == &(*ret));
598 assert(c.size() == 1);
602 // Testing C::emplace_hint(p, ConvertibleToKey&&, ConvertibleToMapped&&)
603 Container c;
604 cc->expect<int&&, int&&>();
605 It ret = c.emplace_hint(c.end(), 42, 1);
606 assert(ret != c.end());
607 assert(c.size() == 1);
608 assert(!cc->unchecked());
610 cc->expect<int&&, int&&>();
611 It ret2 = c.emplace_hint(c.begin(), 42, 2);
612 assert(&(*ret2) == &(*ret));
613 assert(c.size() == 1);
614 assert(!cc->unchecked());
621 template <class Container>
622 void testMultimapInsert()
624 typedef typename Container::value_type ValueTp;
625 ConstructController* cc = getConstructController();
626 cc->reset();
628 // Testing C::insert(const value_type&)
629 Container c;
630 const ValueTp v(42, 1);
631 cc->expect<const ValueTp&>();
632 c.insert(v);
633 assert(!cc->unchecked());
636 // Testing C::insert(value_type&)
637 Container c;
638 ValueTp v(42, 1);
639 cc->expect<ValueTp&>();
640 c.insert(v);
641 assert(!cc->unchecked());
644 // Testing C::insert(value_type&&)
645 Container c;
646 ValueTp v(42, 1);
647 cc->expect<ValueTp&&>();
648 c.insert(std::move(v));
649 assert(!cc->unchecked());
652 // Testing C::insert({key, value})
653 Container c;
654 cc->expect<ValueTp&&>();
655 c.insert({42, 1});
656 assert(!cc->unchecked());
659 // Testing C::insert(std::initializer_list<ValueTp>)
660 Container c;
661 std::initializer_list<ValueTp> il = { ValueTp(1, 1), ValueTp(2, 1) };
662 cc->expect<ValueTp const&>(2);
663 c.insert(il);
664 assert(!cc->unchecked());
667 // Testing C::insert(Iter, Iter) for *Iter = value_type const&
668 Container c;
669 const ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1), ValueTp(3, 1) };
670 cc->expect<ValueTp const&>(3);
671 c.insert(std::begin(ValueList), std::end(ValueList));
672 assert(!cc->unchecked());
675 // Testing C::insert(Iter, Iter) for *Iter = value_type&&
676 Container c;
677 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
678 cc->expect<ValueTp&&>(3);
679 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)),
680 std::move_iterator<ValueTp*>(std::end(ValueList)));
681 assert(!cc->unchecked());
684 // Testing C::insert(Iter, Iter) for *Iter = value_type&
685 Container c;
686 ValueTp ValueList[] = { ValueTp(1, 1), ValueTp(2, 1) , ValueTp(3, 1) };
687 cc->expect<ValueTp&>(3);
688 c.insert(std::begin(ValueList), std::end(ValueList));
689 assert(!cc->unchecked());
694 template <class Container>
695 void testMultimapInsertHint()
697 typedef typename Container::value_type ValueTp;
698 ConstructController* cc = getConstructController();
699 cc->reset();
701 // Testing C::insert(p, const value_type&)
702 Container c;
703 const ValueTp v(42, 1);
704 cc->expect<const ValueTp&>();
705 c.insert(c.begin(), v);
706 assert(!cc->unchecked());
709 // Testing C::insert(p, value_type&)
710 Container c;
711 ValueTp v(42, 1);
712 cc->expect<ValueTp&>();
713 c.insert(c.begin(), v);
714 assert(!cc->unchecked());
717 // Testing C::insert(p, value_type&&)
718 Container c;
719 ValueTp v(42, 1);
720 cc->expect<ValueTp&&>();
721 c.insert(c.begin(), std::move(v));
722 assert(!cc->unchecked());
725 // Testing C::insert(p, {key, value})
726 Container c;
727 cc->expect<ValueTp&&>();
728 c.insert(c.begin(), {42, 1});
729 assert(!cc->unchecked());
733 #endif