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(unordered_multiset&& u, const allocator_type& a);
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 int P;
36 typedef test_allocator<int> A;
37 typedef std::unordered_multiset<int,
38 test_hash<int>,
39 test_equal_to<int>,
40 A
41 > C;
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(std::move(c0), A(12));
58 assert(c.bucket_count() >= 7);
59 assert(c.size() == 6);
60 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 1), end: c.end(), value: 1, count: 2);
61 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 2), end: c.end(), value: 2, count: 2);
62 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 3), end: c.end(), value: 3, count: 1);
63 CheckConsecutiveValues<C::const_iterator>(pos: c.find(x: 4), end: c.end(), value: 4, count: 1);
64 assert(c.hash_function() == test_hash<int>(8));
65 assert(c.key_eq() == test_equal_to<int>(9));
66 assert(c.get_allocator() == A(12));
67 assert(!c.empty());
68 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
69 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
70 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
71 assert(c.max_load_factor() == 1);
72
73 assert(c0.empty());
74 }
75 {
76 typedef int P;
77 typedef test_allocator<int> A;
78 typedef std::unordered_multiset<int,
79 test_hash<int>,
80 test_equal_to<int>,
81 A
82 > C;
83 P a[] =
84 {
85 P(1),
86 P(2),
87 P(3),
88 P(4),
89 P(1),
90 P(2)
91 };
92 C c0(a, a + sizeof(a)/sizeof(a[0]),
93 7,
94 test_hash<int>(8),
95 test_equal_to<int>(9),
96 A(10)
97 );
98 C c(std::move(c0), A(10));
99 LIBCPP_ASSERT(c.bucket_count() == 7);
100 assert(c.size() == 6);
101 assert(c.count(1) == 2);
102 assert(c.count(2) == 2);
103 assert(c.count(3) == 1);
104 assert(c.count(4) == 1);
105 assert(c.hash_function() == test_hash<int>(8));
106 assert(c.key_eq() == test_equal_to<int>(9));
107 assert(c.get_allocator() == A(10));
108 assert(!c.empty());
109 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
110 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
111 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
112 assert(c.max_load_factor() == 1);
113
114 assert(c0.empty());
115 }
116 {
117 typedef int P;
118 typedef min_allocator<int> A;
119 typedef std::unordered_multiset<int,
120 test_hash<int>,
121 test_equal_to<int>,
122 A
123 > C;
124 P a[] =
125 {
126 P(1),
127 P(2),
128 P(3),
129 P(4),
130 P(1),
131 P(2)
132 };
133 C c0(a, a + sizeof(a)/sizeof(a[0]),
134 7,
135 test_hash<int>(8),
136 test_equal_to<int>(9),
137 A()
138 );
139 C c(std::move(c0), A());
140 assert(c.bucket_count() >= 7);
141 assert(c.size() == 6);
142 assert(c.count(1) == 2);
143 assert(c.count(2) == 2);
144 assert(c.count(3) == 1);
145 assert(c.count(4) == 1);
146 assert(c.hash_function() == test_hash<int>(8));
147 assert(c.key_eq() == test_equal_to<int>(9));
148 assert(c.get_allocator() == A());
149 assert(!c.empty());
150 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
151 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
152 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
153 assert(c.max_load_factor() == 1);
154
155 assert(c0.empty());
156 }
157 {
158 typedef int P;
159 typedef min_allocator<int> A;
160 typedef std::unordered_multiset<int,
161 test_hash<int>,
162 test_equal_to<int>,
163 A
164 > C;
165 P a[] =
166 {
167 P(1),
168 P(2),
169 P(3),
170 P(4),
171 P(1),
172 P(2)
173 };
174 C c0(a, a + sizeof(a)/sizeof(a[0]),
175 7,
176 test_hash<int>(8),
177 test_equal_to<int>(9),
178 A()
179 );
180 C c(std::move(c0), A());
181 LIBCPP_ASSERT(c.bucket_count() == 7);
182 assert(c.size() == 6);
183 assert(c.count(1) == 2);
184 assert(c.count(2) == 2);
185 assert(c.count(3) == 1);
186 assert(c.count(4) == 1);
187 assert(c.hash_function() == test_hash<int>(8));
188 assert(c.key_eq() == test_equal_to<int>(9));
189 assert(c.get_allocator() == A());
190 assert(!c.empty());
191 assert(static_cast<std::size_t>(std::distance(c.begin(), c.end())) == c.size());
192 assert(static_cast<std::size_t>(std::distance(c.cbegin(), c.cend())) == c.size());
193 assert(std::fabs(c.load_factor() - (float)c.size()/c.bucket_count()) < FLT_EPSILON);
194 assert(c.max_load_factor() == 1);
195
196 assert(c0.empty());
197 }
198
199 return 0;
200}
201

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