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 #ifndef SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
10 #define SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
16 // class unordered_set
26 #include "test_macros.h"
27 #include "count_new.h"
28 #include "container_test_types.h"
31 template <class Container
>
34 typedef typename
Container::value_type ValueTp
;
35 ConstructController
* cc
= getConstructController();
38 // Testing C::insert(const value_type&)"
41 cc
->expect
<const ValueTp
&>();
42 assert(c
.insert(v
).second
);
43 assert(!cc
->unchecked());
45 DisableAllocationGuard g
;
47 assert(c
.insert(v2
).second
== false);
51 // Testing C::insert(value_type&)"
54 cc
->expect
<const ValueTp
&>();
55 assert(c
.insert(v
).second
);
56 assert(!cc
->unchecked());
58 DisableAllocationGuard g
;
60 assert(c
.insert(v2
).second
== false);
64 // Testing C::insert(value_type&&)"
67 cc
->expect
<ValueTp
&&>();
68 assert(c
.insert(std::move(v
)).second
);
69 assert(!cc
->unchecked());
71 DisableAllocationGuard g
;
73 assert(c
.insert(std::move(v2
)).second
== false);
77 // Testing C::insert(const value_type&&)"
80 cc
->expect
<const ValueTp
&>();
81 assert(c
.insert(std::move(v
)).second
);
82 assert(!cc
->unchecked());
84 DisableAllocationGuard g
;
86 assert(c
.insert(std::move(v2
)).second
== false);
90 // Testing C::insert(std::initializer_list<ValueTp>)"
92 std::initializer_list
<ValueTp
> il
= { ValueTp(1), ValueTp(2) };
93 cc
->expect
<ValueTp
const&>(2);
95 assert(!cc
->unchecked());
97 DisableAllocationGuard g
;
102 // Testing C::insert(Iter, Iter) for *Iter = value_type const&"
104 const ValueTp ValueList
[] = { ValueTp(1), ValueTp(2), ValueTp(3) };
105 cc
->expect
<ValueTp
const&>(3);
106 c
.insert(std::begin(ValueList
), std::end(ValueList
));
107 assert(!cc
->unchecked());
109 DisableAllocationGuard g
;
110 c
.insert(std::begin(ValueList
), std::end(ValueList
));
114 // Testing C::insert(Iter, Iter) for *Iter = value_type&&"
116 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
117 cc
->expect
<ValueTp
&&>(3);
118 c
.insert(std::move_iterator
<ValueTp
*>(std::begin(ValueList
)),
119 std::move_iterator
<ValueTp
*>(std::end(ValueList
)));
120 assert(!cc
->unchecked());
122 DisableAllocationGuard g
;
123 ValueTp ValueList2
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
124 c
.insert(std::move_iterator
<ValueTp
*>(std::begin(ValueList2
)),
125 std::move_iterator
<ValueTp
*>(std::end(ValueList2
)));
129 // Testing C::insert(Iter, Iter) for *Iter = value_type&"
131 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
132 cc
->expect
<ValueTp
const&>(3);
133 c
.insert(std::begin(ValueList
), std::end(ValueList
));
134 assert(!cc
->unchecked());
136 DisableAllocationGuard g
;
137 c
.insert(std::begin(ValueList
), std::end(ValueList
));
143 template <class Container
>
144 void testSetEmplace()
146 typedef typename
Container::value_type ValueTp
;
147 ConstructController
* cc
= getConstructController();
150 // Testing C::emplace(const value_type&)"
153 cc
->expect
<const ValueTp
&>();
154 assert(c
.emplace(v
).second
);
155 assert(!cc
->unchecked());
157 DisableAllocationGuard g
;
158 const ValueTp
v2(42);
159 assert(c
.emplace(v2
).second
== false);
163 // Testing C::emplace(value_type&)"
166 cc
->expect
<ValueTp
&>();
167 assert(c
.emplace(v
).second
);
168 assert(!cc
->unchecked());
170 DisableAllocationGuard g
;
172 assert(c
.emplace(v2
).second
== false);
176 // Testing C::emplace(value_type&&)"
179 cc
->expect
<ValueTp
&&>();
180 assert(c
.emplace(std::move(v
)).second
);
181 assert(!cc
->unchecked());
183 DisableAllocationGuard g
;
185 assert(c
.emplace(std::move(v2
)).second
== false);
189 // Testing C::emplace(const value_type&&)"
192 cc
->expect
<const ValueTp
&&>();
193 assert(c
.emplace(std::move(v
)).second
);
194 assert(!cc
->unchecked());
196 DisableAllocationGuard g
;
197 const ValueTp
v2(42);
198 assert(c
.emplace(std::move(v2
)).second
== false);
204 template <class Container
>
205 void testSetEmplaceHint()
207 typedef typename
Container::value_type ValueTp
;
209 typedef typename
C::iterator It
;
210 ConstructController
* cc
= getConstructController();
213 // Testing C::emplace_hint(p, const value_type&)"
216 cc
->expect
<const ValueTp
&>();
217 It ret
= c
.emplace_hint(c
.end(), v
);
218 assert(ret
!= c
.end());
219 assert(c
.size() == 1);
220 assert(!cc
->unchecked());
222 DisableAllocationGuard g
;
223 const ValueTp
v2(42);
224 It ret2
= c
.emplace_hint(c
.begin(), v2
);
225 assert(&(*ret2
) == &(*ret
));
226 assert(c
.size() == 1);
230 // Testing C::emplace_hint(p, value_type&)"
233 cc
->expect
<ValueTp
&>();
234 It ret
= c
.emplace_hint(c
.end(), v
);
235 assert(ret
!= c
.end());
236 assert(c
.size() == 1);
237 assert(!cc
->unchecked());
239 DisableAllocationGuard g
;
241 It ret2
= c
.emplace_hint(c
.begin(), v2
);
242 assert(&(*ret2
) == &(*ret
));
243 assert(c
.size() == 1);
247 // Testing C::emplace_hint(p, value_type&&)"
250 cc
->expect
<ValueTp
&&>();
251 It ret
= c
.emplace_hint(c
.end(), std::move(v
));
252 assert(ret
!= c
.end());
253 assert(c
.size() == 1);
254 assert(!cc
->unchecked());
256 DisableAllocationGuard g
;
258 It ret2
= c
.emplace_hint(c
.begin(), std::move(v2
));
259 assert(&(*ret2
) == &(*ret
));
260 assert(c
.size() == 1);
264 // Testing C::emplace_hint(p, const value_type&&)"
267 cc
->expect
<const ValueTp
&&>();
268 It ret
= c
.emplace_hint(c
.end(), std::move(v
));
269 assert(ret
!= c
.end());
270 assert(c
.size() == 1);
271 assert(!cc
->unchecked());
273 DisableAllocationGuard g
;
274 const ValueTp
v2(42);
275 It ret2
= c
.emplace_hint(c
.begin(), std::move(v2
));
276 assert(&(*ret2
) == &(*ret
));
277 assert(c
.size() == 1);
283 template <class Container
>
284 void testMultisetInsert()
286 typedef typename
Container::value_type ValueTp
;
287 ConstructController
* cc
= getConstructController();
290 // Testing C::insert(const value_type&)"
293 cc
->expect
<const ValueTp
&>();
295 assert(!cc
->unchecked());
298 // Testing C::insert(value_type&)"
301 cc
->expect
<const ValueTp
&>();
303 assert(!cc
->unchecked());
306 // Testing C::insert(value_type&&)"
309 cc
->expect
<ValueTp
&&>();
310 c
.insert(std::move(v
));
311 assert(!cc
->unchecked());
314 // Testing C::insert(std::initializer_list<ValueTp>)"
316 std::initializer_list
<ValueTp
> il
= { ValueTp(1), ValueTp(2) };
317 cc
->expect
<ValueTp
const&>(2);
319 assert(!cc
->unchecked());
322 // Testing C::insert(Iter, Iter) for *Iter = value_type const&"
324 const ValueTp ValueList
[] = { ValueTp(1), ValueTp(2), ValueTp(3) };
325 cc
->expect
<ValueTp
const&>(3);
326 c
.insert(std::begin(ValueList
), std::end(ValueList
));
327 assert(!cc
->unchecked());
330 // Testing C::insert(Iter, Iter) for *Iter = value_type&&"
332 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
333 cc
->expect
<ValueTp
&&>(3);
334 c
.insert(std::move_iterator
<ValueTp
*>(std::begin(ValueList
)),
335 std::move_iterator
<ValueTp
*>(std::end(ValueList
)));
336 assert(!cc
->unchecked());
339 // Testing C::insert(Iter, Iter) for *Iter = value_type&"
341 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(1) };
342 cc
->expect
<ValueTp
&>(3);
343 c
.insert(std::begin(ValueList
), std::end(ValueList
));
344 assert(!cc
->unchecked());
349 template <class Container
>
350 void testMultisetEmplace()
352 typedef typename
Container::value_type ValueTp
;
353 ConstructController
* cc
= getConstructController();
356 // Testing C::emplace(const value_type&)"
359 cc
->expect
<const ValueTp
&>();
361 assert(!cc
->unchecked());
364 // Testing C::emplace(value_type&)"
367 cc
->expect
<ValueTp
&>();
369 assert(!cc
->unchecked());
372 // Testing C::emplace(value_type&&)"
375 cc
->expect
<ValueTp
&&>();
376 c
.emplace(std::move(v
));
377 assert(!cc
->unchecked());
380 // Testing C::emplace(const value_type&&)"
383 cc
->expect
<const ValueTp
&&>();
384 c
.emplace(std::move(v
));
385 assert(!cc
->unchecked());