1 // { dg-options "-std=gnu++2a" }
2 // { dg-do run { target c++2a } }
3
4 // Copyright (C) 2018-2019 Free Software Foundation, Inc.
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 <map>
22 #include <testsuite_hooks.h>
23
24 #ifndef __cpp_lib_erase_if
25 # error "Feature-test macro for erase_if missing in <map>"
26 #elif __cpp_lib_erase_if < 202002
27 # error "Feature-test macro for erase_if has wrong value in <map>"
28 #endif
29
30 auto is_odd_pair = [](const std::pair<const int, std::string>& p)
__anon552cc7c30102(const std::pair<const int, std::string>& p) 31 {
32 return p.first % 2 != 0;
33 };
34
35 void
test01()36 test01()
37 {
38 std::map<int, std::string> m{ { 10, "A" }, { 11, "B" },
39 { 12, "C" }, { 14, "D" },
40 { 15, "E" }, { 17, "F" },
41 { 18, "G" }, { 19, "H" } };
42 auto num = std::erase_if(m, is_odd_pair);
43 std::map<int, std::string> t{ { 10, "A" }, { 12, "C" },
44 { 14, "D" }, { 18, "G" } };
45 VERIFY( m == t );
46 VERIFY( num == 4 );
47 }
48
49 void
test02()50 test02()
51 {
52 std::multimap<int, std::string> mm{ { 20, "S" }, { 21, "T" },
53 { 22, "U" }, { 22, "V" },
54 { 23, "W" }, { 23, "X" },
55 { 24, "Y" }, { 25, "Z" } };
56 auto num = std::erase_if(mm, is_odd_pair);
57 std::multimap<int, std::string> t{ { 20, "S" }, { 22, "U" },
58 { 22, "V" }, { 24, "Y" } };
59 VERIFY( mm == t );
60 VERIFY( num == 4 );
61 }
62
63 int
main()64 main()
65 {
66 test01();
67 test02();
68
69 return 0;
70 }
71