1 //===----------------------------------------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14
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>;
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>;
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>>,
35 // template<class InputIterator, class Hash, class Allocator>
36 // unordered_multiset(InputIterator, InputIterator, typename see below::size_type,
38 // -> unordered_multiset<iter-value-type<InputIterator>, Hash,
39 // equal_to<iter-value-type<InputIterator>>,
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>;
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>;
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
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
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
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
72 #include <algorithm> // is_permutation
75 #include <climits> // INT_MAX
76 #include <type_traits>
77 #include <unordered_set>
79 #include "../../../test_compare.h"
80 #include "../../../test_hash.h"
81 #include "deduction_guides_sfinae_checks.h"
82 #include "test_allocator.h"
86 const int expected_s
[] = {1, 1, 2, 3, INT_MAX
};
89 const int arr
[] = { 1, 2, 1, INT_MAX
, 3 };
90 std::unordered_multiset
s(std::begin(arr
), std::end(arr
));
92 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int>);
93 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
97 const int arr
[] = { 1, 2, 1, INT_MAX
, 3 };
98 std::unordered_multiset
s(std::begin(arr
), std::end(arr
), 42);
100 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int>);
101 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
105 const int arr
[] = { 1, 2, 1, INT_MAX
, 3 };
106 std::unordered_multiset
s(std::begin(arr
), std::end(arr
), 42, std::hash
<long long>());
108 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int, std::hash
<long long>>);
109 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
113 const int arr
[] = { 1, 2, 1, INT_MAX
, 3 };
114 std::unordered_multiset
s(std::begin(arr
), std::end(arr
), 42, std::hash
<long long>(), test_allocator
<int>(0, 40));
116 ASSERT_SAME_TYPE(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);
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);
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);
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);
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);
152 std::unordered_multiset s
{ 1, 2, 1, INT_MAX
, 3 };
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
)));
159 std::unordered_multiset
s({ 1, 2, 1, INT_MAX
, 3 }, 42);
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
)));
166 std::unordered_multiset
s({ 1, 2, 1, INT_MAX
, 3 }, 42, std::hash
<long long>());
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
)));
173 std::unordered_multiset
s({ 1, 2, 1, INT_MAX
, 3 }, 42, std::hash
<long long>(), std::equal_to
<>());
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
)));
180 std::unordered_multiset
s({ 1, 2, 1, INT_MAX
, 3 }, 42, std::hash
<long long>(), std::equal_to
<>(), test_allocator
<int>(0, 43));
182 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int, std::hash
<long long>, std::equal_to
<>, test_allocator
<int>>);
183 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
184 assert(s
.get_allocator().get_id() == 43);
188 const int arr
[] = { 1, 2, 1, INT_MAX
, 3 };
189 std::unordered_multiset
s(std::begin(arr
), std::end(arr
), 42, test_allocator
<int>(0, 44));
191 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int, std::hash
<int>, std::equal_to
<int>, test_allocator
<int>>);
192 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
193 assert(s
.get_allocator().get_id() == 44);
197 const int arr
[] = { 1, 2, 1, INT_MAX
, 3 };
198 std::unordered_multiset
s(std::begin(arr
), std::end(arr
), 42, std::hash
<long long>(), test_allocator
<int>(0, 44));
200 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int, std::hash
<long long>, std::equal_to
<int>, test_allocator
<int>>);
201 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
202 assert(s
.get_allocator().get_id() == 44);
206 std::unordered_multiset
s({ 1, 2, 1, INT_MAX
, 3 }, 42, test_allocator
<int>(0, 43));
208 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int, std::hash
<int>, std::equal_to
<int>, test_allocator
<int>>);
209 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
210 assert(s
.get_allocator().get_id() == 43);
214 std::unordered_multiset
s({ 1, 2, 1, INT_MAX
, 3 }, 42, std::hash
<long long>(), test_allocator
<int>(0, 42));
216 ASSERT_SAME_TYPE(decltype(s
), std::unordered_multiset
<int, std::hash
<long long>, std::equal_to
<int>, test_allocator
<int>>);
217 assert(std::is_permutation(s
.begin(), s
.end(), std::begin(expected_s
), std::end(expected_s
)));
218 assert(s
.get_allocator().get_id() == 42);
221 #if TEST_STD_VER >= 23
223 using Range
= std::array
<int, 0>;
224 using Pred
= test_equal_to
<int>;
225 using DefaultPred
= std::equal_to
<int>;
226 using Hash
= test_hash
<int>;
227 using DefaultHash
= std::hash
<int>;
228 using Alloc
= test_allocator
<int>;
230 { // (from_range, range)
231 std::unordered_multiset
c(std::from_range
, Range());
232 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int>>);
235 { // (from_range, range, n)
236 std::unordered_multiset
c(std::from_range
, Range(), std::size_t());
237 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int>>);
240 { // (from_range, range, n, hash)
241 std::unordered_multiset
c(std::from_range
, Range(), std::size_t(), Hash());
242 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int, Hash
>>);
245 { // (from_range, range, n, hash, pred)
246 std::unordered_multiset
c(std::from_range
, Range(), std::size_t(), Hash(), Pred());
247 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int, Hash
, Pred
>>);
250 { // (from_range, range, n, hash, pred, alloc)
251 std::unordered_multiset
c(std::from_range
, Range(), std::size_t(), Hash(), Pred(), Alloc());
252 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int, Hash
, Pred
, Alloc
>>);
255 { // (from_range, range, n, alloc)
256 std::unordered_multiset
c(std::from_range
, Range(), std::size_t(), Alloc());
257 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int, DefaultHash
, DefaultPred
, Alloc
>>);
260 // TODO(LWG 2713): uncomment this test once the constructor is added.
261 { // (from_range, range, alloc)
262 //std::unordered_multiset c(std::from_range, Range(), Alloc());
263 //static_assert(std::is_same_v<decltype(c), std::unordered_multiset<int, DefaultHash, DefaultPred, Alloc>>);
266 { // (from_range, range, n, hash, alloc)
267 std::unordered_multiset
c(std::from_range
, Range(), std::size_t(), Hash(), Alloc());
268 static_assert(std::is_same_v
<decltype(c
), std::unordered_multiset
<int, Hash
, DefaultPred
, Alloc
>>);
272 UnorderedContainerDeductionGuidesSfinaeAway
<std::unordered_multiset
, std::unordered_multiset
<int>>();