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#ifndef SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
10#define SET_ALLOCATOR_REQUIREMENT_TEST_TEMPLATES_H
11
12// <set>
13// <unordered_set>
14
15// class set
16// class unordered_set
17
18// insert(...);
19// emplace(...);
20// emplace_hint(...);
21
22#include <cassert>
23#include <iterator>
24
25#include "test_macros.h"
26#include "count_new.h"
27#include "container_test_types.h"
28
29template <class Container>
30void testSetInsert() {
31 typedef typename Container::value_type ValueTp;
32 ConstructController* cc = getConstructController();
33 cc->reset();
34 {
35 // Testing C::insert(const value_type&)"
36 Container c;
37 const ValueTp v(42);
38 cc->expect<const ValueTp&>();
39 assert(c.insert(v).second);
40 assert(!cc->unchecked());
41 {
42 DisableAllocationGuard g;
43 const ValueTp v2(42);
44 assert(c.insert(v2).second == false);
45 }
46 }
47 {
48 // Testing C::insert(value_type&)"
49 Container c;
50 ValueTp v(42);
51 cc->expect<const ValueTp&>();
52 assert(c.insert(v).second);
53 assert(!cc->unchecked());
54 {
55 DisableAllocationGuard g;
56 ValueTp v2(42);
57 assert(c.insert(v2).second == false);
58 }
59 }
60 {
61 // Testing C::insert(value_type&&)"
62 Container c;
63 ValueTp v(42);
64 cc->expect<ValueTp&&>();
65 assert(c.insert(std::move(v)).second);
66 assert(!cc->unchecked());
67 {
68 DisableAllocationGuard g;
69 ValueTp v2(42);
70 assert(c.insert(std::move(v2)).second == false);
71 }
72 }
73 {
74 // Testing C::insert(const value_type&&)"
75 Container c;
76 const ValueTp v(42);
77 cc->expect<const ValueTp&>();
78 assert(c.insert(std::move(v)).second);
79 assert(!cc->unchecked());
80 {
81 DisableAllocationGuard g;
82 const ValueTp v2(42);
83 assert(c.insert(std::move(v2)).second == false);
84 }
85 }
86 {
87 // Testing C::insert(std::initializer_list<ValueTp>)"
88 Container c;
89 std::initializer_list<ValueTp> il = {ValueTp(1), ValueTp(2)};
90 cc->expect<ValueTp const&>(2);
91 c.insert(il);
92 assert(!cc->unchecked());
93 {
94 DisableAllocationGuard g;
95 c.insert(il);
96 }
97 }
98 {
99 // Testing C::insert(Iter, Iter) for *Iter = value_type const&"
100 Container c;
101 const ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
102 cc->expect<ValueTp const&>(3);
103 c.insert(std::begin(ValueList), std::end(ValueList));
104 assert(!cc->unchecked());
105 {
106 DisableAllocationGuard g;
107 c.insert(std::begin(ValueList), std::end(ValueList));
108 }
109 }
110 {
111 // Testing C::insert(Iter, Iter) for *Iter = value_type&&"
112 Container c;
113 ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
114 cc->expect<ValueTp&&>(3);
115 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)), std::move_iterator<ValueTp*>(std::end(ValueList)));
116 assert(!cc->unchecked());
117 {
118 DisableAllocationGuard g;
119 ValueTp ValueList2[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
120 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList2)),
121 std::move_iterator<ValueTp*>(std::end(ValueList2)));
122 }
123 }
124 {
125 // Testing C::insert(Iter, Iter) for *Iter = value_type&"
126 Container c;
127 ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
128 cc->expect<ValueTp const&>(3);
129 c.insert(std::begin(ValueList), std::end(ValueList));
130 assert(!cc->unchecked());
131 {
132 DisableAllocationGuard g;
133 c.insert(std::begin(ValueList), std::end(ValueList));
134 }
135 }
136}
137
138template <class Container>
139void testSetEmplace() {
140 typedef typename Container::value_type ValueTp;
141 ConstructController* cc = getConstructController();
142 cc->reset();
143 {
144 // Testing C::emplace(const value_type&)"
145 Container c;
146 const ValueTp v(42);
147 cc->expect<const ValueTp&>();
148 assert(c.emplace(v).second);
149 assert(!cc->unchecked());
150 {
151 DisableAllocationGuard g;
152 const ValueTp v2(42);
153 assert(c.emplace(v2).second == false);
154 }
155 }
156 {
157 // Testing C::emplace(value_type&)"
158 Container c;
159 ValueTp v(42);
160 cc->expect<ValueTp&>();
161 assert(c.emplace(v).second);
162 assert(!cc->unchecked());
163 {
164 DisableAllocationGuard g;
165 ValueTp v2(42);
166 assert(c.emplace(v2).second == false);
167 }
168 }
169 {
170 // Testing C::emplace(value_type&&)"
171 Container c;
172 ValueTp v(42);
173 cc->expect<ValueTp&&>();
174 assert(c.emplace(std::move(v)).second);
175 assert(!cc->unchecked());
176 {
177 DisableAllocationGuard g;
178 ValueTp v2(42);
179 assert(c.emplace(std::move(v2)).second == false);
180 }
181 }
182 {
183 // Testing C::emplace(const value_type&&)"
184 Container c;
185 const ValueTp v(42);
186 cc->expect<const ValueTp&&>();
187 assert(c.emplace(std::move(v)).second);
188 assert(!cc->unchecked());
189 {
190 DisableAllocationGuard g;
191 const ValueTp v2(42);
192 assert(c.emplace(std::move(v2)).second == false);
193 }
194 }
195}
196
197template <class Container>
198void testSetEmplaceHint() {
199 typedef typename Container::value_type ValueTp;
200 typedef Container C;
201 typedef typename C::iterator It;
202 ConstructController* cc = getConstructController();
203 cc->reset();
204 {
205 // Testing C::emplace_hint(p, const value_type&)"
206 Container c;
207 const ValueTp v(42);
208 cc->expect<const ValueTp&>();
209 It ret = c.emplace_hint(c.end(), v);
210 assert(ret != c.end());
211 assert(c.size() == 1);
212 assert(!cc->unchecked());
213 {
214 DisableAllocationGuard g;
215 const ValueTp v2(42);
216 It ret2 = c.emplace_hint(c.begin(), v2);
217 assert(&(*ret2) == &(*ret));
218 assert(c.size() == 1);
219 }
220 }
221 {
222 // Testing C::emplace_hint(p, value_type&)"
223 Container c;
224 ValueTp v(42);
225 cc->expect<ValueTp&>();
226 It ret = c.emplace_hint(c.end(), v);
227 assert(ret != c.end());
228 assert(c.size() == 1);
229 assert(!cc->unchecked());
230 {
231 DisableAllocationGuard g;
232 ValueTp v2(42);
233 It ret2 = c.emplace_hint(c.begin(), v2);
234 assert(&(*ret2) == &(*ret));
235 assert(c.size() == 1);
236 }
237 }
238 {
239 // Testing C::emplace_hint(p, value_type&&)"
240 Container c;
241 ValueTp v(42);
242 cc->expect<ValueTp&&>();
243 It ret = c.emplace_hint(c.end(), std::move(v));
244 assert(ret != c.end());
245 assert(c.size() == 1);
246 assert(!cc->unchecked());
247 {
248 DisableAllocationGuard g;
249 ValueTp v2(42);
250 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
251 assert(&(*ret2) == &(*ret));
252 assert(c.size() == 1);
253 }
254 }
255 {
256 // Testing C::emplace_hint(p, const value_type&&)"
257 Container c;
258 const ValueTp v(42);
259 cc->expect<const ValueTp&&>();
260 It ret = c.emplace_hint(c.end(), std::move(v));
261 assert(ret != c.end());
262 assert(c.size() == 1);
263 assert(!cc->unchecked());
264 {
265 DisableAllocationGuard g;
266 const ValueTp v2(42);
267 It ret2 = c.emplace_hint(c.begin(), std::move(v2));
268 assert(&(*ret2) == &(*ret));
269 assert(c.size() == 1);
270 }
271 }
272}
273
274template <class Container>
275void testMultisetInsert() {
276 typedef typename Container::value_type ValueTp;
277 ConstructController* cc = getConstructController();
278 cc->reset();
279 {
280 // Testing C::insert(const value_type&)"
281 Container c;
282 const ValueTp v(42);
283 cc->expect<const ValueTp&>();
284 c.insert(v);
285 assert(!cc->unchecked());
286 }
287 {
288 // Testing C::insert(value_type&)"
289 Container c;
290 ValueTp v(42);
291 cc->expect<const ValueTp&>();
292 c.insert(v);
293 assert(!cc->unchecked());
294 }
295 {
296 // Testing C::insert(value_type&&)"
297 Container c;
298 ValueTp v(42);
299 cc->expect<ValueTp&&>();
300 c.insert(std::move(v));
301 assert(!cc->unchecked());
302 }
303 {
304 // Testing C::insert(std::initializer_list<ValueTp>)"
305 Container c;
306 std::initializer_list<ValueTp> il = {ValueTp(1), ValueTp(2)};
307 cc->expect<ValueTp const&>(2);
308 c.insert(il);
309 assert(!cc->unchecked());
310 }
311 {
312 // Testing C::insert(Iter, Iter) for *Iter = value_type const&"
313 Container c;
314 const ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
315 cc->expect<ValueTp const&>(3);
316 c.insert(std::begin(ValueList), std::end(ValueList));
317 assert(!cc->unchecked());
318 }
319 {
320 // Testing C::insert(Iter, Iter) for *Iter = value_type&&"
321 Container c;
322 ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(3)};
323 cc->expect<ValueTp&&>(3);
324 c.insert(std::move_iterator<ValueTp*>(std::begin(ValueList)), std::move_iterator<ValueTp*>(std::end(ValueList)));
325 assert(!cc->unchecked());
326 }
327 {
328 // Testing C::insert(Iter, Iter) for *Iter = value_type&"
329 Container c;
330 ValueTp ValueList[] = {ValueTp(1), ValueTp(2), ValueTp(1)};
331 cc->expect<ValueTp&>(3);
332 c.insert(std::begin(ValueList), std::end(ValueList));
333 assert(!cc->unchecked());
334 }
335}
336
337template <class Container>
338void testMultisetEmplace() {
339 typedef typename Container::value_type ValueTp;
340 ConstructController* cc = getConstructController();
341 cc->reset();
342 {
343 // Testing C::emplace(const value_type&)"
344 Container c;
345 const ValueTp v(42);
346 cc->expect<const ValueTp&>();
347 c.emplace(v);
348 assert(!cc->unchecked());
349 }
350 {
351 // Testing C::emplace(value_type&)"
352 Container c;
353 ValueTp v(42);
354 cc->expect<ValueTp&>();
355 c.emplace(v);
356 assert(!cc->unchecked());
357 }
358 {
359 // Testing C::emplace(value_type&&)"
360 Container c;
361 ValueTp v(42);
362 cc->expect<ValueTp&&>();
363 c.emplace(std::move(v));
364 assert(!cc->unchecked());
365 }
366 {
367 // Testing C::emplace(const value_type&&)"
368 Container c;
369 const ValueTp v(42);
370 cc->expect<const ValueTp&&>();
371 c.emplace(std::move(v));
372 assert(!cc->unchecked());
373 }
374}
375
376#endif
377

Provided by KDAB

Privacy Policy
Improve your Profiling and Debugging skills
Find out more

source code of libcxx/test/std/containers/set_allocator_requirement_test_templates.h