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, c++11, c++14
10
11// <unordered_set>
12
13// template<class InputIterator,
14// class Hash = hash<iter-value-type<InputIterator>>,
15// class Pred = equal_to<iter-value-type<InputIterator>>,
16// class Allocator = allocator<iter-value-type<InputIterator>>>
17// unordered_multiset(InputIterator, InputIterator, typename see below::size_type = see below,
18// Hash = Hash(), Pred = Pred(), Allocator = Allocator())
19// -> unordered_multiset<iter-value-type<InputIterator>,
20// Hash, Pred, Allocator>;
21//
22// template<class T, class Hash = hash<T>,
23// class Pred = equal_to<T>, class Allocator = allocator<T>>
24// unordered_multiset(initializer_list<T>, typename see below::size_type = see below,
25// Hash = Hash(), Pred = Pred(), Allocator = Allocator())
26// -> unordered_multiset<T, Hash, Pred, Allocator>;
27//
28// template<class InputIterator, class Allocator>
29// unordered_multiset(InputIterator, InputIterator, typename see below::size_type, Allocator)
30// -> unordered_multiset<iter-value-type<InputIterator>,
31// hash<iter-value-type<InputIterator>>,
32// equal_to<iter-value-type<InputIterator>>,
33// Allocator>;
34//
35// template<class InputIterator, class Hash, class Allocator>
36// unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
37// Hash, Allocator)
38// -> unordered_multiset<iter-value-type<InputIterator>, Hash,
39// equal_to<iter-value-type<InputIterator>>,
40// Allocator>;
41//
42// template<class T, class Allocator>
43// unordered_multiset(initializer_list<T>, typename see below::size_type, Allocator)
44// -> unordered_multiset<T, hash<T>, equal_to<T>, Allocator>;
45//
46// template<class T, class Hash, class Allocator>
47// unordered_multiset(initializer_list<T>, typename see below::size_type, Hash, Allocator)
48// -> unordered_multiset<T, Hash, equal_to<T>, Allocator>;
49//
50// template<ranges::input_range R,
51// class Hash = hash<ranges::range_value_t<R>>,
52// class Pred = equal_to<ranges::range_value_t<R>>,
53// class Allocator = allocator<ranges::range_value_t<R>>>
54// unordered_multiset(from_range_t, R&&, typename see below::size_type = see below, Hash = Hash(), Pred = Pred(), Allocator = Allocator())
55// -> unordered_multiset<ranges::range_value_t<R>, Hash, Pred, Allocator>; // C++23
56//
57// template<ranges::input_range R, class Allocator>
58// unordered_multiset(from_range_t, R&&, typename see below::size_type, Allocator)
59// -> unordered_multiset<ranges::range_value_t<R>, hash<ranges::range_value_t<R>>,
60// equal_to<ranges::range_value_t<R>>, Allocator>; // C++23
61//
62// template<ranges::input_range R, class Allocator>
63// unordered_multiset(from_range_t, R&&, Allocator)
64// -> unordered_multiset<ranges::range_value_t<R>, hash<ranges::range_value_t<R>>,
65// equal_to<ranges::range_value_t<R>>, Allocator>; // C++23
66//
67// template<ranges::input_range R, class Hash, class Allocator>
68// unordered_multiset(from_range_t, R&&, typename see below::size_type, Hash, Allocator)
69// -> unordered_multiset<ranges::range_value_t<R>, Hash,
70// equal_to<ranges::range_value_t<R>>, Allocator>; // C++23
71
72#include <algorithm> // is_permutation
73#include <array>
74#include <cassert>
75#include <climits> // INT_MAX
76#include <type_traits>
77#include <unordered_set>
78
79#include "../../../test_compare.h"
80#include "../../../test_hash.h"
81#include "deduction_guides_sfinae_checks.h"
82#include "test_allocator.h"
83
84int main(int, char**) {
85 const int expected_s[] = {1, 1, 2, 3, INT_MAX};
86
87 {
88 const int arr[] = {1, 2, 1, INT_MAX, 3};
89 std::unordered_multiset s(std::begin(arr: arr), std::end(arr: arr));
90
91 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int>);
92 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
93 }
94
95 {
96 const int arr[] = {1, 2, 1, INT_MAX, 3};
97 std::unordered_multiset s(std::begin(arr: arr), std::end(arr: arr), 42);
98
99 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int>);
100 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
101 }
102
103 {
104 const int arr[] = {1, 2, 1, INT_MAX, 3};
105 std::unordered_multiset s(std::begin(arr: arr), std::end(arr: arr), 42, std::hash<long long>());
106
107 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int, std::hash<long long>>);
108 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
109 }
110
111 {
112 const int arr[] = {1, 2, 1, INT_MAX, 3};
113 std::unordered_multiset s(std::begin(arr: arr), std::end(arr: arr), 42, std::hash<long long>(), test_allocator<int>(0, 40));
114
115 ASSERT_SAME_TYPE(
116 decltype(s), std::unordered_multiset<int, std::hash<long long>, std::equal_to<int>, test_allocator<int>>);
117 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
118 assert(s.get_allocator().get_id() == 40);
119 }
120
121 {
122 std::unordered_multiset<int, std::hash<long long>, std::equal_to<>, test_allocator<int>> source;
123 std::unordered_multiset s(source);
124 ASSERT_SAME_TYPE(decltype(s), decltype(source));
125 assert(s.size() == 0);
126 }
127
128 {
129 std::unordered_multiset<int, std::hash<long long>, std::equal_to<>, test_allocator<int>> source;
130 std::unordered_multiset s{source}; // braces instead of parens
131 ASSERT_SAME_TYPE(decltype(s), decltype(source));
132 assert(s.size() == 0);
133 }
134
135 {
136 std::unordered_multiset<int, std::hash<long long>, std::equal_to<>, test_allocator<int>> source;
137 std::unordered_multiset s(source, test_allocator<int>(0, 41));
138 ASSERT_SAME_TYPE(decltype(s), decltype(source));
139 assert(s.size() == 0);
140 assert(s.get_allocator().get_id() == 41);
141 }
142
143 {
144 std::unordered_multiset<int, std::hash<long long>, std::equal_to<>, test_allocator<int>> source;
145 std::unordered_multiset s{source, test_allocator<int>(0, 42)}; // braces instead of parens
146 ASSERT_SAME_TYPE(decltype(s), decltype(source));
147 assert(s.size() == 0);
148 assert(s.get_allocator().get_id() == 42);
149 }
150
151 {
152 std::unordered_multiset s{1, 2, 1, INT_MAX, 3};
153
154 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int>);
155 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
156 }
157
158 {
159 std::unordered_multiset s({1, 2, 1, INT_MAX, 3}, 42);
160
161 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int>);
162 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
163 }
164
165 {
166 std::unordered_multiset s({1, 2, 1, INT_MAX, 3}, 42, std::hash<long long>());
167
168 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int, std::hash<long long>>);
169 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
170 }
171
172 {
173 std::unordered_multiset s({1, 2, 1, INT_MAX, 3}, 42, std::hash<long long>(), std::equal_to<>());
174
175 ASSERT_SAME_TYPE(decltype(s), std::unordered_multiset<int, std::hash<long long>, std::equal_to<>>);
176 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
177 }
178
179 {
180 std::unordered_multiset s(
181 {1, 2, 1, INT_MAX, 3}, 42, std::hash<long long>(), std::equal_to<>(), test_allocator<int>(0, 43));
182
183 ASSERT_SAME_TYPE(
184 decltype(s), std::unordered_multiset<int, std::hash<long long>, std::equal_to<>, test_allocator<int>>);
185 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
186 assert(s.get_allocator().get_id() == 43);
187 }
188
189 {
190 const int arr[] = {1, 2, 1, INT_MAX, 3};
191 std::unordered_multiset s(std::begin(arr: arr), std::end(arr: arr), 42, test_allocator<int>(0, 44));
192
193 ASSERT_SAME_TYPE(
194 decltype(s), std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, test_allocator<int>>);
195 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
196 assert(s.get_allocator().get_id() == 44);
197 }
198
199 {
200 const int arr[] = {1, 2, 1, INT_MAX, 3};
201 std::unordered_multiset s(std::begin(arr: arr), std::end(arr: arr), 42, std::hash<long long>(), test_allocator<int>(0, 44));
202
203 ASSERT_SAME_TYPE(
204 decltype(s), std::unordered_multiset<int, std::hash<long long>, std::equal_to<int>, test_allocator<int>>);
205 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
206 assert(s.get_allocator().get_id() == 44);
207 }
208
209 {
210 std::unordered_multiset s({1, 2, 1, INT_MAX, 3}, 42, test_allocator<int>(0, 43));
211
212 ASSERT_SAME_TYPE(
213 decltype(s), std::unordered_multiset<int, std::hash<int>, std::equal_to<int>, test_allocator<int>>);
214 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
215 assert(s.get_allocator().get_id() == 43);
216 }
217
218 {
219 std::unordered_multiset s({1, 2, 1, INT_MAX, 3}, 42, std::hash<long long>(), test_allocator<int>(0, 42));
220
221 ASSERT_SAME_TYPE(
222 decltype(s), std::unordered_multiset<int, std::hash<long long>, std::equal_to<int>, test_allocator<int>>);
223 assert(std::is_permutation(s.begin(), s.end(), std::begin(expected_s), std::end(expected_s)));
224 assert(s.get_allocator().get_id() == 42);
225 }
226
227#if TEST_STD_VER >= 23
228 {
229 using Range = std::array<int, 0>;
230 using Pred = test_equal_to<int>;
231 using DefaultPred = std::equal_to<int>;
232 using Hash = test_hash<int>;
233 using DefaultHash = std::hash<int>;
234 using Alloc = test_allocator<int>;
235
236 { // (from_range, range)
237 std::unordered_multiset c(std::from_range, Range());
238 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int>>);
239 }
240
241 { // (from_range, range, n)
242 std::unordered_multiset c(std::from_range, Range(), std::size_t());
243 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int>>);
244 }
245
246 { // (from_range, range, n, hash)
247 std::unordered_multiset c(std::from_range, Range(), std::size_t(), Hash());
248 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, Hash>>);
249 }
250
251 { // (from_range, range, n, hash, pred)
252 std::unordered_multiset c(std::from_range, Range(), std::size_t(), Hash(), Pred());
253 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, Hash, Pred>>);
254 }
255
256 { // (from_range, range, n, hash, pred, alloc)
257 std::unordered_multiset c(std::from_range, Range(), std::size_t(), Hash(), Pred(), Alloc());
258 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, Hash, Pred, Alloc>>);
259 }
260
261 { // (from_range, range, n, alloc)
262 std::unordered_multiset c(std::from_range, Range(), std::size_t(), Alloc());
263 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, DefaultHash, DefaultPred, Alloc>>);
264 }
265
266 // TODO(LWG 2713): uncomment this test once the constructor is added.
267 { // (from_range, range, alloc)
268 //std::unordered_multiset c(std::from_range, Range(), Alloc());
269 //static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, DefaultHash, DefaultPred, Alloc>>);
270 }
271
272 { // (from_range, range, n, hash, alloc)
273 std::unordered_multiset c(std::from_range, Range(), std::size_t(), Hash(), Alloc());
274 static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, Hash, DefaultPred, Alloc>>);
275 }
276 }
277#endif
278 UnorderedContainerDeductionGuidesSfinaeAway<std::unordered_multiset, std::unordered_multiset<int>>();
279
280 return 0;
281}
282

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