]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/multiset/modifiers/merge.cc
libstdc++: Ensure c++NN effective target present in all C++17 tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 23_containers / multiset / modifiers / merge.cc
1 // Copyright (C) 2016-2020 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 // { dg-do run { target c++17 } }
20
21 #include <set>
22 #include <algorithm>
23 #include <testsuite_hooks.h>
24
25 using test_type = std::multiset<int>;
26
27 void
28 test01()
29 {
30 test_type c0{ 1, 1, 2, 2, 3, 3 };
31 test_type c1 = c0, c2 = c0;
32
33 c1.merge(c2);
34 for (auto i : c1)
35 VERIFY( c1.count(i) == (2 * c0.count(i)) );
36 VERIFY( c2.empty() );
37
38 c1.clear();
39 c2 = c0;
40 c1.merge(std::move(c2));
41 VERIFY( c1 == c0 );
42 VERIFY( c2.empty() );
43 }
44
45 void
46 test02()
47 {
48 test_type c0{ 1, 1, 2, 2, 3, 3 };
49 test_type c1 = c0;
50 std::multiset<int, std::less<>> c2( c0.begin(), c0.end() );
51
52 c1.merge(c2);
53 VERIFY( c1.size() == (2 * c0.size()) );
54 for (auto i : c1)
55 VERIFY( c1.count(i) == (2 * c0.count(i)) );
56 VERIFY( c2.empty() );
57
58 c1.clear();
59 c2.insert( c0.begin(), c0.end() );
60 c1.merge(std::move(c2));
61 VERIFY( c1 == c0 );
62 VERIFY( c2.empty() );
63 }
64
65 void
66 test03()
67 {
68 const test_type c0{ 1, 1, 2, 2, 3, 3 };
69 test_type c1 = c0;
70 std::multiset<int, std::greater<>> c2( c0.begin(), c0.end() );
71
72 c1.merge(c2);
73 VERIFY( c1.size() == (2 * c0.size()) );
74 for (auto i : c1)
75 VERIFY( c1.count(i) == (2 * c0.count(i)) );
76 VERIFY( c2.empty() );
77
78 c1.clear();
79 c2.insert( c0.begin(), c0.end() );
80 c1.merge(std::move(c2));
81 VERIFY( c1 == c0 );
82 VERIFY( c2.empty() );
83 }
84
85 void
86 test04()
87 {
88 const test_type c0{ 1, 1, 2, 2, 3, 3 };
89 test_type c1 = c0;
90 std::set<int, std::greater<>> c2( c0.begin(), c0.end() );
91
92 c1.merge(c2);
93 VERIFY( c1.size() == (1.5 * c0.size()) );
94 for (auto& i : c1)
95 VERIFY( c1.count(i) == (1.5 * c0.count(i)) );
96 VERIFY( c2.empty() );
97
98 c1.clear();
99 c2.insert( c0.begin(), c0.end() );
100 c1.merge(std::move(c2));
101 VERIFY( c1.size() == (0.5 * c0.size()) );
102 VERIFY( c2.empty() );
103 }
104
105 int
106 main()
107 {
108 test01();
109 test02();
110 test03();
111 test04();
112 }