]>
Commit | Line | Data |
---|---|---|
a62b871d | 1 | // { dg-options "-std=gnu++2a" } |
188588e4 ESR |
2 | // { dg-do run { target c++2a } } |
3 | ||
7adcbafe | 4 | // Copyright (C) 2018-2022 Free Software Foundation, Inc. |
188588e4 ESR |
5 | // |
6 | // This file is part of the GNU ISO C++ Library. This library is free | |
7 | // software; you can redistribute it and/or modify it under the | |
8 | // terms of the GNU General Public License as published by the | |
9 | // Free Software Foundation; either version 3, or (at your option) | |
10 | // any later version. | |
11 | ||
12 | // This library is distributed in the hope that it will be useful, | |
13 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | // GNU General Public License for more details. | |
16 | ||
17 | // You should have received a copy of the GNU General Public License along | |
18 | // with this library; see the file COPYING3. If not see | |
19 | // <http://www.gnu.org/licenses/>. | |
20 | ||
21 | #include <unordered_map> | |
beb0086f | 22 | #include <string> |
188588e4 ESR |
23 | #include <testsuite_hooks.h> |
24 | ||
45a8d80f | 25 | #ifndef __cpp_lib_erase_if |
0fe9eaaa | 26 | # error "Feature-test macro for erase_if missing in <unordered_map>" |
55b00d14 | 27 | #elif __cpp_lib_erase_if < 202002 |
0fe9eaaa | 28 | # error "Feature-test macro for erase_if has wrong value in <unordered_map>" |
45a8d80f JW |
29 | #endif |
30 | ||
188588e4 ESR |
31 | auto is_odd_pair = [](const std::pair<const int, std::string>& p) |
32 | { | |
33 | return p.first % 2 != 0; | |
34 | }; | |
35 | ||
36 | void | |
37 | test01() | |
38 | { | |
39 | std::unordered_map<int, std::string> um{ { 10, "A" }, { 11, "B" }, | |
40 | { 12, "C" }, { 14, "D" }, | |
41 | { 15, "E" }, { 17, "F" }, | |
42 | { 18, "G" }, { 19, "H" } }; | |
0b44b4b8 | 43 | auto num = std::erase_if(um, is_odd_pair); |
188588e4 ESR |
44 | std::unordered_map<int, std::string> t{ { 10, "A" }, { 12, "C" }, |
45 | { 14, "D" }, { 18, "G" } }; | |
46 | VERIFY( um == t ); | |
0b44b4b8 | 47 | VERIFY( num == 4 ); |
188588e4 ESR |
48 | } |
49 | ||
50 | void | |
51 | test02() | |
52 | { | |
53 | std::unordered_multimap<int, std::string> umm{ { 20, "S" }, { 21, "T" }, | |
54 | { 22, "U" }, { 22, "V" }, | |
55 | { 23, "W" }, { 23, "X" }, | |
56 | { 24, "Y" }, { 25, "Z" } }; | |
0b44b4b8 | 57 | auto num = std::erase_if(umm, is_odd_pair); |
188588e4 ESR |
58 | std::unordered_multimap<int, std::string> t{ { 20, "S" }, { 22, "U" }, |
59 | { 22, "V" }, { 24, "Y" } }; | |
60 | VERIFY( umm == t ); | |
0b44b4b8 | 61 | VERIFY( num == 4 ); |
188588e4 ESR |
62 | } |
63 | ||
64 | int | |
65 | main() | |
66 | { | |
67 | test01(); | |
68 | test02(); | |
69 | ||
70 | return 0; | |
71 | } |