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 //===----------------------------------------------------------------------===//
8 #ifndef SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
9 #define SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
15 // class unordered_set
24 #include "test_macros.h"
25 #include "count_new.h"
26 #include "container_test_types.h"
27 #include "assert_checkpoint.h"
30 template <class Container
>
33 typedef typename
Container::value_type ValueTp
;
34 ConstructController
* cc
= getConstructController();
37 CHECKPOINT("Testing C::insert(const value_type&)");
40 cc
->expect
<const ValueTp
&>();
41 assert(c
.insert(v
).second
);
42 assert(!cc
->unchecked());
44 DisableAllocationGuard g
;
46 assert(c
.insert(v2
).second
== false);
50 CHECKPOINT("Testing C::insert(value_type&)");
53 cc
->expect
<const ValueTp
&>();
54 assert(c
.insert(v
).second
);
55 assert(!cc
->unchecked());
57 DisableAllocationGuard g
;
59 assert(c
.insert(v2
).second
== false);
63 CHECKPOINT("Testing C::insert(value_type&&)");
66 cc
->expect
<ValueTp
&&>();
67 assert(c
.insert(std::move(v
)).second
);
68 assert(!cc
->unchecked());
70 DisableAllocationGuard g
;
72 assert(c
.insert(std::move(v2
)).second
== false);
76 CHECKPOINT("Testing C::insert(const value_type&&)");
79 cc
->expect
<const ValueTp
&>();
80 assert(c
.insert(std::move(v
)).second
);
81 assert(!cc
->unchecked());
83 DisableAllocationGuard g
;
85 assert(c
.insert(std::move(v2
)).second
== false);
89 CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
91 std::initializer_list
<ValueTp
> il
= { ValueTp(1), ValueTp(2) };
92 cc
->expect
<ValueTp
const&>(2);
94 assert(!cc
->unchecked());
96 DisableAllocationGuard g
;
101 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
103 const ValueTp ValueList
[] = { ValueTp(1), ValueTp(2), ValueTp(3) };
104 cc
->expect
<ValueTp
const&>(3);
105 c
.insert(std::begin(ValueList
), std::end(ValueList
));
106 assert(!cc
->unchecked());
108 DisableAllocationGuard g
;
109 c
.insert(std::begin(ValueList
), std::end(ValueList
));
113 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
115 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
116 cc
->expect
<ValueTp
&&>(3);
117 c
.insert(std::move_iterator
<ValueTp
*>(std::begin(ValueList
)),
118 std::move_iterator
<ValueTp
*>(std::end(ValueList
)));
119 assert(!cc
->unchecked());
121 DisableAllocationGuard g
;
122 ValueTp ValueList2
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
123 c
.insert(std::move_iterator
<ValueTp
*>(std::begin(ValueList2
)),
124 std::move_iterator
<ValueTp
*>(std::end(ValueList2
)));
128 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
130 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
131 cc
->expect
<ValueTp
const&>(3);
132 c
.insert(std::begin(ValueList
), std::end(ValueList
));
133 assert(!cc
->unchecked());
135 DisableAllocationGuard g
;
136 c
.insert(std::begin(ValueList
), std::end(ValueList
));
142 template <class Container
>
143 void testSetEmplace()
145 typedef typename
Container::value_type ValueTp
;
146 ConstructController
* cc
= getConstructController();
149 CHECKPOINT("Testing C::emplace(const value_type&)");
152 cc
->expect
<const ValueTp
&>();
153 assert(c
.emplace(v
).second
);
154 assert(!cc
->unchecked());
156 DisableAllocationGuard g
;
157 const ValueTp
v2(42);
158 assert(c
.emplace(v2
).second
== false);
162 CHECKPOINT("Testing C::emplace(value_type&)");
165 cc
->expect
<ValueTp
&>();
166 assert(c
.emplace(v
).second
);
167 assert(!cc
->unchecked());
169 DisableAllocationGuard g
;
171 assert(c
.emplace(v2
).second
== false);
175 CHECKPOINT("Testing C::emplace(value_type&&)");
178 cc
->expect
<ValueTp
&&>();
179 assert(c
.emplace(std::move(v
)).second
);
180 assert(!cc
->unchecked());
182 DisableAllocationGuard g
;
184 assert(c
.emplace(std::move(v2
)).second
== false);
188 CHECKPOINT("Testing C::emplace(const value_type&&)");
191 cc
->expect
<const ValueTp
&&>();
192 assert(c
.emplace(std::move(v
)).second
);
193 assert(!cc
->unchecked());
195 DisableAllocationGuard g
;
196 const ValueTp
v2(42);
197 assert(c
.emplace(std::move(v2
)).second
== false);
203 template <class Container
>
204 void testSetEmplaceHint()
206 typedef typename
Container::value_type ValueTp
;
208 typedef typename
C::iterator It
;
209 ConstructController
* cc
= getConstructController();
212 CHECKPOINT("Testing C::emplace_hint(p, const value_type&)");
215 cc
->expect
<const ValueTp
&>();
216 It ret
= c
.emplace_hint(c
.end(), v
);
217 assert(ret
!= c
.end());
218 assert(c
.size() == 1);
219 assert(!cc
->unchecked());
221 DisableAllocationGuard g
;
222 const ValueTp
v2(42);
223 It ret2
= c
.emplace_hint(c
.begin(), v2
);
224 assert(&(*ret2
) == &(*ret
));
225 assert(c
.size() == 1);
229 CHECKPOINT("Testing C::emplace_hint(p, value_type&)");
232 cc
->expect
<ValueTp
&>();
233 It ret
= c
.emplace_hint(c
.end(), v
);
234 assert(ret
!= c
.end());
235 assert(c
.size() == 1);
236 assert(!cc
->unchecked());
238 DisableAllocationGuard g
;
240 It ret2
= c
.emplace_hint(c
.begin(), v2
);
241 assert(&(*ret2
) == &(*ret
));
242 assert(c
.size() == 1);
246 CHECKPOINT("Testing C::emplace_hint(p, value_type&&)");
249 cc
->expect
<ValueTp
&&>();
250 It ret
= c
.emplace_hint(c
.end(), std::move(v
));
251 assert(ret
!= c
.end());
252 assert(c
.size() == 1);
253 assert(!cc
->unchecked());
255 DisableAllocationGuard g
;
257 It ret2
= c
.emplace_hint(c
.begin(), std::move(v2
));
258 assert(&(*ret2
) == &(*ret
));
259 assert(c
.size() == 1);
263 CHECKPOINT("Testing C::emplace_hint(p, const value_type&&)");
266 cc
->expect
<const ValueTp
&&>();
267 It ret
= c
.emplace_hint(c
.end(), std::move(v
));
268 assert(ret
!= c
.end());
269 assert(c
.size() == 1);
270 assert(!cc
->unchecked());
272 DisableAllocationGuard g
;
273 const ValueTp
v2(42);
274 It ret2
= c
.emplace_hint(c
.begin(), std::move(v2
));
275 assert(&(*ret2
) == &(*ret
));
276 assert(c
.size() == 1);
282 template <class Container
>
283 void testMultisetInsert()
285 typedef typename
Container::value_type ValueTp
;
286 ConstructController
* cc
= getConstructController();
289 CHECKPOINT("Testing C::insert(const value_type&)");
292 cc
->expect
<const ValueTp
&>();
294 assert(!cc
->unchecked());
297 CHECKPOINT("Testing C::insert(value_type&)");
300 cc
->expect
<const ValueTp
&>();
302 assert(!cc
->unchecked());
305 CHECKPOINT("Testing C::insert(value_type&&)");
308 cc
->expect
<ValueTp
&&>();
309 c
.insert(std::move(v
));
310 assert(!cc
->unchecked());
313 CHECKPOINT("Testing C::insert(std::initializer_list<ValueTp>)");
315 std::initializer_list
<ValueTp
> il
= { ValueTp(1), ValueTp(2) };
316 cc
->expect
<ValueTp
const&>(2);
318 assert(!cc
->unchecked());
321 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type const&");
323 const ValueTp ValueList
[] = { ValueTp(1), ValueTp(2), ValueTp(3) };
324 cc
->expect
<ValueTp
const&>(3);
325 c
.insert(std::begin(ValueList
), std::end(ValueList
));
326 assert(!cc
->unchecked());
329 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&&");
331 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(3) };
332 cc
->expect
<ValueTp
&&>(3);
333 c
.insert(std::move_iterator
<ValueTp
*>(std::begin(ValueList
)),
334 std::move_iterator
<ValueTp
*>(std::end(ValueList
)));
335 assert(!cc
->unchecked());
338 CHECKPOINT("Testing C::insert(Iter, Iter) for *Iter = value_type&");
340 ValueTp ValueList
[] = { ValueTp(1), ValueTp(2) , ValueTp(1) };
341 cc
->expect
<ValueTp
&>(3);
342 c
.insert(std::begin(ValueList
), std::end(ValueList
));
343 assert(!cc
->unchecked());
348 template <class Container
>
349 void testMultisetEmplace()
351 typedef typename
Container::value_type ValueTp
;
352 ConstructController
* cc
= getConstructController();
355 CHECKPOINT("Testing C::emplace(const value_type&)");
358 cc
->expect
<const ValueTp
&>();
360 assert(!cc
->unchecked());
363 CHECKPOINT("Testing C::emplace(value_type&)");
366 cc
->expect
<ValueTp
&>();
368 assert(!cc
->unchecked());
371 CHECKPOINT("Testing C::emplace(value_type&&)");
374 cc
->expect
<ValueTp
&&>();
375 c
.emplace(std::move(v
));
376 assert(!cc
->unchecked());
379 CHECKPOINT("Testing C::emplace(const value_type&&)");
382 cc
->expect
<const ValueTp
&&>();
383 c
.emplace(std::move(v
));
384 assert(!cc
->unchecked());