]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/23_containers/multimap/modifiers/merge.cc
Implement C++17 node extraction and insertion (P0083R5)
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multimap / modifiers / merge.cc
CommitLineData
2dbe56bd
JW
1// Copyright (C) 2016 Free Software Foundation, Inc.
2//
3// This file is part of the GNU ISO C++ Library. This library is free
4// software; you can redistribute it and/or modify it under the
5// terms of the GNU General Public License as published by the
6// Free Software Foundation; either version 3, or (at your option)
7// any later version.
8
9// This library is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13
14// You should have received a copy of the GNU General Public License along
15// with this library; see the file COPYING3. If not see
16// <http://www.gnu.org/licenses/>.
17
18// { dg-options "-std=gnu++17" }
19
20#include <map>
21#include <algorithm>
22#include <testsuite_hooks.h>
23
24using test_type = std::multimap<int, int>;
25
26void
27test01()
28{
29 bool test __attribute__((unused)) = true;
30
31 const test_type c0{ {1, 10}, {1, 11}, {2, 20}, {2, 21}, {3, 30}, {3, 31} };
32 test_type c1 = c0, c2 = c0;
33
34 c1.merge(c2);
35 for (auto& i : c1)
36 VERIFY( c1.count(i.first) == (2 * c0.count(i.first)) );
37 VERIFY( c2.empty() );
38
39 c1.clear();
40 c2 = c0;
41 c1.merge(std::move(c2));
42 VERIFY( c1 == c0 );
43 VERIFY( c2.empty() );
44}
45
46void
47test02()
48{
49 bool test __attribute__((unused)) = true;
50
51 const test_type c0{ {1, 10}, {1, 11}, {2, 20}, {2, 21}, {3, 30}, {3, 31} };
52 test_type c1 = c0;
53 std::multimap<int, int, std::less<>> c2( c0.begin(), c0.end() );
54
55 c1.merge(c2);
56 VERIFY( c1.size() == (2 * c0.size()) );
57 for (auto& i : c1)
58 VERIFY( c1.count(i.first) == (2 * c0.count(i.first)) );
59 VERIFY( c2.empty() );
60
61 c1.clear();
62 c2.insert( c0.begin(), c0.end() );
63 c1.merge(std::move(c2));
64 VERIFY( c1 == c0 );
65 VERIFY( c2.empty() );
66}
67
68void
69test03()
70{
71 bool test __attribute__((unused)) = true;
72
73 const test_type c0{ {1, 10}, {1, 11}, {2, 20}, {2, 21}, {3, 30}, {3, 31} };
74 test_type c1 = c0;
75 std::multimap<int, int, std::greater<>> c2( c0.begin(), c0.end() );
76
77 c1.merge(c2);
78 VERIFY( c1.size() == (2 * c0.size()) );
79 for (auto& i : c1)
80 VERIFY( c1.count(i.first) == (2 * c0.count(i.first)) );
81 VERIFY( c2.empty() );
82
83 c1.clear();
84 c2.insert( c0.begin(), c0.end() );
85 c1.merge(std::move(c2));
86 VERIFY( c1 == c0 );
87 VERIFY( c2.empty() );
88}
89
90void
91test04()
92{
93 bool test __attribute__((unused)) = true;
94
95 const test_type c0{ {1, 10}, {1, 11}, {2, 20}, {2, 21}, {3, 30}, {3, 31} };
96 test_type c1 = c0;
97 std::map<int, int, std::greater<>> c2( c0.begin(), c0.end() );
98
99 c1.merge(c2);
100 VERIFY( c1.size() == (1.5 * c0.size()) );
101 for (auto& i : c1)
102 VERIFY( c1.count(i.first) == (1.5 * c0.count(i.first)) );
103 VERIFY( c2.empty() );
104
105 c1.clear();
106 c2.insert( c0.begin(), c0.end() );
107 c1.merge(std::move(c2));
108 VERIFY( c1.size() == (0.5 * c0.size()) );
109 VERIFY( c2.empty() );
110}
111
112int
113main()
114{
115 test01();
116 test02();
117 test03();
118 test04();
119}