]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/unordered_set/modifiers/merge.cc
7cc2ce11cee044f01513985fe567cf7fad83735c
1 // Copyright (C) 2016-2021 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-options "-std=gnu++17" }
19 // { dg-do run { target c++17 } }
21 #include <unordered_set>
23 #include <testsuite_hooks.h>
25 using test_type
= std::unordered_set
<int>;
28 auto operator()(int i
) const noexcept
{ return ~std::hash
<int>()(i
); }
30 struct equal
: std::equal_to
<> { };
32 template<typename C1
, typename C2
>
33 bool equal_elements(const C1
& c1
, const C2
& c2
)
35 if (c2
.size() != c1
.size())
38 if (c2
.count(i
) != c1
.count(i
))
46 const test_type c0
{ 1, 2, 3, };
47 test_type c1
= c0
, c2
= c0
;
58 c2
.merge(std::move(c1
));
66 const test_type c0
{ 1, 2, 3, };
68 std::unordered_set
<int, hash
, equal
> c2( c0
.begin(), c0
.end() );
72 VERIFY( equal_elements(c2
, c0
) );
81 VERIFY( equal_elements(c2
, c0
) );
83 c1
.merge(std::move(c2
));
91 const test_type c0
{ 1, 2, 3, };
93 std::unordered_multiset
<int, hash
, equal
> c2( c0
.begin(), c0
.end() );
96 VERIFY( equal_elements(c2
, c0
) );
101 VERIFY( c2
.empty() );
104 VERIFY( c1
.empty() );
105 VERIFY( equal_elements(c2
, c0
) );
109 VERIFY( c1
.empty() );
110 VERIFY( c2
.size() == (2 * c0
.size()) );
111 VERIFY( c2
.count(1) == 2 );
112 VERIFY( c2
.count(2) == 2 );
113 VERIFY( c2
.count(3) == 2 );
117 VERIFY( equal_elements(c2
, c0
) );
119 c1
.merge(std::move(c2
));
121 VERIFY( equal_elements(c2
, c0
) );
124 c1
.merge(std::move(c2
));
126 VERIFY( c2
.empty() );