1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// UNSUPPORTED: c++03
10
11// <unordered_set>
12
13// template <class Value, class Hash = hash<Value>, class Pred = equal_to<Value>,
14// class Alloc = allocator<Value>>
15// class unordered_multiset
16
17// unordered_multiset& operator=(unordered_multiset&& u);
18
19#include <unordered_set>
20#include <cassert>
21#include <cfloat>
22#include <cmath>
23#include <cstddef>
24
25#include "test_macros.h"
26#include "../../../check_consecutive.h"
27#include "../../../test_compare.h"
28#include "../../../test_hash.h"
29#include "test_allocator.h"
30#include "min_allocator.h"
31
32int main(int, char**)
33{
34 {
35 typedef test_allocator<int> A;
36 typedef std::unordered_multiset<int,
37 test_hash<int>,
38 test_equal_to<int>,
39 A
40 > C;
41 typedef int P;
42 P a[] =
43 {
44 P(1),
45 P(2),
46 P(3),
47 P(4),
48 P(1),
49 P(2)
50 };
51 C c0(a, a + sizeof(a)/sizeof(a[0]),
52 7,
53 test_hash<int>(8),
54 test_equal_to<int>(9),
55 A(10)
56 );
57 C c(a, a + 2,
58 7,
59 test_hash<int>(2),
60 test_equal_to<int>(3),
61 A(4)
62 );
63 c = std::move(c0);
64 LIBCPP_ASSERT(c.bucket_count() == 7);
65 assert(c.size() == 6);
66 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 1), end: c.end(), value: 1, count: 2);
67 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 2), end: c.end(), value: 2, count: 2);
68 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 3), end: c.end(), value: 3, count: 1);
69 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 4), end: c.end(), value: 4, count: 1);
70 assert(c.hash_function() == test_hash<int>(8));
71 assert(c.key_eq() == test_equal_to<int>(9));
72 assert(c.get_allocator() == A(4));
73 assert(!c.empty());
74 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
75 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
76 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
77 assert(c.max_load_factor() == 1);
78 }
79 {
80 typedef test_allocator<int> A;
81 typedef std::unordered_multiset<int,
82 test_hash<int>,
83 test_equal_to<int>,
84 A
85 > C;
86 typedef int P;
87 P a[] =
88 {
89 P(1),
90 P(2),
91 P(3),
92 P(4),
93 P(1),
94 P(2)
95 };
96 C c0(a, a + sizeof(a)/sizeof(a[0]),
97 7,
98 test_hash<int>(8),
99 test_equal_to<int>(9),
100 A(10)
101 );
102 C c(a, a + 2,
103 7,
104 test_hash<int>(2),
105 test_equal_to<int>(3),
106 A(10)
107 );
108 C::iterator it0 = c0.begin();
109 c = std::move(c0);
110 LIBCPP_ASSERT(c.bucket_count() == 7);
111 assert(c.size() == 6);
112 assert(c.count(1) == 2);
113 assert(c.count(2) == 2);
114 assert(c.count(3) == 1);
115 assert(c.count(4) == 1);
116 assert(c.hash_function() == test_hash<int>(8));
117 assert(c.key_eq() == test_equal_to<int>(9));
118 assert(c.get_allocator() == A(10));
119 assert(!c.empty());
120 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
121 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
122 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
123 assert(c.max_load_factor() == 1);
124 assert(it0 == c.begin()); // Iterators remain valid
125 }
126 {
127 typedef other_allocator<int> A;
128 typedef std::unordered_multiset<int,
129 test_hash<int>,
130 test_equal_to<int>,
131 A
132 > C;
133 typedef int P;
134 P a[] =
135 {
136 P(1),
137 P(2),
138 P(3),
139 P(4),
140 P(1),
141 P(2)
142 };
143 C c0(a, a + sizeof(a)/sizeof(a[0]),
144 7,
145 test_hash<int>(8),
146 test_equal_to<int>(9),
147 A(10)
148 );
149 C c(a, a + 2,
150 7,
151 test_hash<int>(2),
152 test_equal_to<int>(3),
153 A(4)
154 );
155 C::iterator it0 = c0.begin();
156 c = std::move(c0);
157 LIBCPP_ASSERT(c.bucket_count() == 7);
158 assert(c.size() == 6);
159 assert(c.count(1) == 2);
160 assert(c.count(2) == 2);
161 assert(c.count(3) == 1);
162 assert(c.count(4) == 1);
163 assert(c.hash_function() == test_hash<int>(8));
164 assert(c.key_eq() == test_equal_to<int>(9));
165 assert(c.get_allocator() == A(10));
166 assert(!c.empty());
167 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
168 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
169 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
170 assert(c.max_load_factor() == 1);
171 assert(it0 == c.begin()); // Iterators remain valid
172 }
173 {
174 typedef test_allocator<int> A;
175 typedef std::unordered_multiset<int,
176 test_hash<int>,
177 test_equal_to<int>,
178 A
179 > C;
180 typedef int P;
181 P a[] =
182 {
183 P(1),
184 P(2),
185 P(3),
186 P(4),
187 P(1),
188 P(2)
189 };
190 C c0(a, a + sizeof(a)/sizeof(a[0]),
191 7,
192 test_hash<int>(8),
193 test_equal_to<int>(9),
194 A()
195 );
196 C c(a, a + 2,
197 7,
198 test_hash<int>(2),
199 test_equal_to<int>(3),
200 A()
201 );
202 C::iterator it0 = c0.begin();
203 c = std::move(c0);
204 LIBCPP_ASSERT(c.bucket_count() == 7);
205 assert(c.size() == 6);
206 assert(c.count(1) == 2);
207 assert(c.count(2) == 2);
208 assert(c.count(3) == 1);
209 assert(c.count(4) == 1);
210 assert(c.hash_function() == test_hash<int>(8));
211 assert(c.key_eq() == test_equal_to<int>(9));
212 assert(c.get_allocator() == A());
213 assert(!c.empty());
214 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
215 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
216 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
217 assert(c.max_load_factor() == 1);
218 assert(it0 == c.begin()); // Iterators remain valid
219 }
220 {
221 typedef min_allocator<int> A;
222 typedef std::unordered_multiset<int,
223 test_hash<int>,
224 test_equal_to<int>,
225 A
226 > C;
227 typedef int P;
228 P a[] =
229 {
230 P(1),
231 P(2),
232 P(3),
233 P(4),
234 P(1),
235 P(2)
236 };
237 C c0(a, a + sizeof(a)/sizeof(a[0]),
238 7,
239 test_hash<int>(8),
240 test_equal_to<int>(9),
241 A()
242 );
243 C c(a, a + 2,
244 7,
245 test_hash<int>(2),
246 test_equal_to<int>(3),
247 A()
248 );
249 C::iterator it0 = c0.begin();
250 c = std::move(c0);
251 LIBCPP_ASSERT(c.bucket_count() == 7);
252 assert(c.size() == 6);
253 assert(c.count(1) == 2);
254 assert(c.count(2) == 2);
255 assert(c.count(3) == 1);
256 assert(c.count(4) == 1);
257 assert(c.hash_function() == test_hash<int>(8));
258 assert(c.key_eq() == test_equal_to<int>(9));
259 assert(c.get_allocator() == A());
260 assert(!c.empty());
261 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
262 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
263 assert(fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
264 assert(c.max_load_factor() == 1);
265 assert(it0 == c.begin()); // Iterators remain valid
266 }
267
268 return 0;
269}
270

source code of libcxx/test/std/containers/unord/unord.multiset/unord.multiset.cnstr/assign_move.pass.cpp