]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/experimental/unordered_map/erasure.cc
Add fundamentals TR container erasure.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / experimental / unordered_map / erasure.cc
1 // { dg-options "-std=gnu++14" }
2 // { dg-do run }
3
4 // Copyright (C) 2015 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 moved_to 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 <experimental/unordered_map>
22 #include <testsuite_hooks.h>
23
24 auto is_odd_pair = [](const std::pair<const int, std::string>& p)
25 {
26 return p.first % 2 != 0;
27 };
28
29 void
30 test01()
31 {
32 bool test [[gnu::unused]] = true;
33
34 std::unordered_map<int, std::string> um{ { 10, "A" }, { 11, "B" },
35 { 12, "C" }, { 14, "D" },
36 { 15, "E" }, { 17, "F" },
37 { 18, "G" }, { 19, "H" } };
38 std::experimental::erase_if(um, is_odd_pair);
39 std::unordered_map<int, std::string> t{ { 10, "A" }, { 12, "C" },
40 { 14, "D" }, { 18, "G" } };
41 VERIFY( um == t );
42 }
43
44 void
45 test02()
46 {
47 bool test [[gnu::unused]] = true;
48
49 std::unordered_multimap<int, std::string> umm{ { 20, "S" }, { 21, "T" },
50 { 22, "U" }, { 22, "V" },
51 { 23, "W" }, { 23, "X" },
52 { 24, "Y" }, { 25, "Z" } };
53 std::experimental::erase_if(umm, is_odd_pair);
54 std::unordered_multimap<int, std::string> t{ { 20, "S" }, { 22, "U" },
55 { 22, "V" }, { 24, "Y" } };
56 VERIFY( umm == t );
57 }
58
59 int
60 main()
61 {
62 test01();
63 test02();
64
65 return 0;
66 }