]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_multiset/modifiers/merge.cc
1 // Copyright (C) 2016-2024 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do run { target c++17 } }
21 #include <unordered_set>
23 #include <testsuite_hooks.h>
25 using test_type
= std::unordered_multiset
<int>;
27 auto operator()(int i
) const noexcept
{ return ~std::hash
<int>()(i
); }
29 struct equal
: std::equal_to
<> { };
34 test_type c0
{ 1, 1, 2, 2, 3, 3 };
35 test_type c1
= c0
, c2
= c0
;
39 VERIFY( c1
.count(i
) == (2 * c0
.count(i
)) );
44 c1
.merge(std::move(c2
));
52 test_type c0
{ 1, 1, 2, 2, 3, 3 };
54 std::unordered_multiset
<int, hash
, equal
> c2( c0
.begin(), c0
.end() );
57 VERIFY( c1
.size() == (2 * c0
.size()) );
59 VERIFY( c1
.count(i
) == (2 * c0
.count(i
)) );
63 c2
.insert( c0
.begin(), c0
.end() );
64 c1
.merge(std::move(c2
));
72 const test_type c0
{ 1, 1, 2, 2, 3, 3 };
74 std::unordered_multiset
<int, hash
, equal
> c2( c0
.begin(), c0
.end() );
77 VERIFY( c1
.size() == (2 * c0
.size()) );
79 VERIFY( c1
.count(i
) == (2 * c0
.count(i
)) );
83 c2
.insert( c0
.begin(), c0
.end() );
84 c1
.merge(std::move(c2
));
92 const test_type c0
{ 1, 1, 2, 2, 3, 3 };
94 std::unordered_set
<int, hash
, equal
> c2( c0
.begin(), c0
.end() );
97 VERIFY( c1
.size() == (1.5 * c0
.size()) );
99 VERIFY( c1
.count(i
) == (1.5 * c0
.count(i
)) );
100 VERIFY( c2
.empty() );
103 c2
.insert( c0
.begin(), c0
.end() );
104 c1
.merge(std::move(c2
));
105 VERIFY( c1
.size() == (0.5 * c0
.size()) );
106 VERIFY( c2
.empty() );
112 const std::unordered_multiset
<std::string
> c0
{ "abcd", "abcd", "efgh", "efgh", "ijkl", "ijkl" };
113 std::unordered_multiset
<std::string
> c1
= c0
;
114 std::unordered_set
<std::string
> c2( c0
.begin(), c0
.end() );
117 VERIFY( c1
.size() == (1.5 * c0
.size()) );
119 VERIFY( c1
.count(i
) == (1.5 * c0
.count(i
)) );
120 VERIFY( c2
.empty() );
123 c2
.insert( c0
.begin(), c0
.end() );
124 c1
.merge(std::move(c2
));
125 VERIFY( c1
.size() == (0.5 * c0
.size()) );
126 VERIFY( c2
.empty() );