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// <list>
10
11// void splice(const_iterator position, list& x);
12
13#include <list>
14#include <cassert>
15
16#include "test_macros.h"
17#include "min_allocator.h"
18
19int main(int, char**)
20{
21 int a1[] = {1, 2, 3};
22 int a2[] = {4, 5, 6};
23 {
24 std::list<int> l1;
25 std::list<int> l2;
26 l1.splice(position: l1.end(), x&: l2);
27 assert(l1.size() == 0);
28 assert(std::distance(l1.begin(), l1.end()) == 0);
29 assert(l2.size() == 0);
30 assert(std::distance(l2.begin(), l2.end()) == 0);
31 }
32 {
33 std::list<int> l1;
34 std::list<int> l2(a2, a2+1);
35 l1.splice(position: l1.end(), x&: l2);
36 assert(l1.size() == 1);
37 assert(std::distance(l1.begin(), l1.end()) == 1);
38 assert(l2.size() == 0);
39 assert(std::distance(l2.begin(), l2.end()) == 0);
40 std::list<int>::const_iterator i = l1.begin();
41 assert(*i == 4);
42 }
43 {
44 std::list<int> l1;
45 std::list<int> l2(a2, a2+2);
46 l1.splice(position: l1.end(), x&: l2);
47 assert(l1.size() == 2);
48 assert(std::distance(l1.begin(), l1.end()) == 2);
49 assert(l2.size() == 0);
50 assert(std::distance(l2.begin(), l2.end()) == 0);
51 std::list<int>::const_iterator i = l1.begin();
52 assert(*i == 4);
53 ++i;
54 assert(*i == 5);
55 }
56 {
57 std::list<int> l1;
58 std::list<int> l2(a2, a2+3);
59 l1.splice(position: l1.end(), x&: l2);
60 assert(l1.size() == 3);
61 assert(std::distance(l1.begin(), l1.end()) == 3);
62 assert(l2.size() == 0);
63 assert(std::distance(l2.begin(), l2.end()) == 0);
64 std::list<int>::const_iterator i = l1.begin();
65 assert(*i == 4);
66 ++i;
67 assert(*i == 5);
68 ++i;
69 assert(*i == 6);
70 }
71 {
72 std::list<int> l1(a1, a1+1);
73 std::list<int> l2;
74 l1.splice(position: l1.begin(), x&: l2);
75 assert(l1.size() == 1);
76 assert(std::distance(l1.begin(), l1.end()) == 1);
77 assert(l2.size() == 0);
78 assert(std::distance(l2.begin(), l2.end()) == 0);
79 std::list<int>::const_iterator i = l1.begin();
80 assert(*i == 1);
81 }
82 {
83 std::list<int> l1(a1, a1+1);
84 std::list<int> l2;
85 l1.splice(position: l1.end(), x&: l2);
86 assert(l1.size() == 1);
87 assert(std::distance(l1.begin(), l1.end()) == 1);
88 assert(l2.size() == 0);
89 assert(std::distance(l2.begin(), l2.end()) == 0);
90 std::list<int>::const_iterator i = l1.begin();
91 assert(*i == 1);
92 }
93 {
94 std::list<int> l1(a1, a1+1);
95 std::list<int> l2(a2, a2+1);
96 l1.splice(position: l1.begin(), x&: l2);
97 assert(l1.size() == 2);
98 assert(std::distance(l1.begin(), l1.end()) == 2);
99 assert(l2.size() == 0);
100 assert(std::distance(l2.begin(), l2.end()) == 0);
101 std::list<int>::const_iterator i = l1.begin();
102 assert(*i == 4);
103 ++i;
104 assert(*i == 1);
105 }
106 {
107 std::list<int> l1(a1, a1+1);
108 std::list<int> l2(a2, a2+1);
109 l1.splice(position: l1.end(), x&: l2);
110 assert(l1.size() == 2);
111 assert(std::distance(l1.begin(), l1.end()) == 2);
112 assert(l2.size() == 0);
113 assert(std::distance(l2.begin(), l2.end()) == 0);
114 std::list<int>::const_iterator i = l1.begin();
115 assert(*i == 1);
116 ++i;
117 assert(*i == 4);
118 }
119 {
120 std::list<int> l1(a1, a1+1);
121 std::list<int> l2(a2, a2+2);
122 l1.splice(position: l1.begin(), x&: l2);
123 assert(l1.size() == 3);
124 assert(std::distance(l1.begin(), l1.end()) == 3);
125 assert(l2.size() == 0);
126 assert(std::distance(l2.begin(), l2.end()) == 0);
127 std::list<int>::const_iterator i = l1.begin();
128 assert(*i == 4);
129 ++i;
130 assert(*i == 5);
131 ++i;
132 assert(*i == 1);
133 }
134 {
135 std::list<int> l1(a1, a1+1);
136 std::list<int> l2(a2, a2+2);
137 l1.splice(position: l1.end(), x&: l2);
138 assert(l1.size() == 3);
139 assert(std::distance(l1.begin(), l1.end()) == 3);
140 assert(l2.size() == 0);
141 assert(std::distance(l2.begin(), l2.end()) == 0);
142 std::list<int>::const_iterator i = l1.begin();
143 assert(*i == 1);
144 ++i;
145 assert(*i == 4);
146 ++i;
147 assert(*i == 5);
148 }
149 {
150 std::list<int> l1(a1, a1+1);
151 std::list<int> l2(a2, a2+3);
152 l1.splice(position: l1.begin(), x&: l2);
153 assert(l1.size() == 4);
154 assert(std::distance(l1.begin(), l1.end()) == 4);
155 assert(l2.size() == 0);
156 assert(std::distance(l2.begin(), l2.end()) == 0);
157 std::list<int>::const_iterator i = l1.begin();
158 assert(*i == 4);
159 ++i;
160 assert(*i == 5);
161 ++i;
162 assert(*i == 6);
163 ++i;
164 assert(*i == 1);
165 }
166 {
167 std::list<int> l1(a1, a1+1);
168 std::list<int> l2(a2, a2+3);
169 l1.splice(position: l1.end(), x&: l2);
170 assert(l1.size() == 4);
171 assert(std::distance(l1.begin(), l1.end()) == 4);
172 assert(l2.size() == 0);
173 assert(std::distance(l2.begin(), l2.end()) == 0);
174 std::list<int>::const_iterator i = l1.begin();
175 assert(*i == 1);
176 ++i;
177 assert(*i == 4);
178 ++i;
179 assert(*i == 5);
180 ++i;
181 assert(*i == 6);
182 }
183 {
184 std::list<int> l1(a1, a1+2);
185 std::list<int> l2;
186 l1.splice(position: l1.begin(), x&: l2);
187 assert(l1.size() == 2);
188 assert(std::distance(l1.begin(), l1.end()) == 2);
189 assert(l2.size() == 0);
190 assert(std::distance(l2.begin(), l2.end()) == 0);
191 std::list<int>::const_iterator i = l1.begin();
192 assert(*i == 1);
193 ++i;
194 assert(*i == 2);
195 }
196 {
197 std::list<int> l1(a1, a1+2);
198 std::list<int> l2;
199 l1.splice(position: std::next(x: l1.begin()), x&: l2);
200 assert(l1.size() == 2);
201 assert(std::distance(l1.begin(), l1.end()) == 2);
202 assert(l2.size() == 0);
203 assert(std::distance(l2.begin(), l2.end()) == 0);
204 std::list<int>::const_iterator i = l1.begin();
205 assert(*i == 1);
206 ++i;
207 assert(*i == 2);
208 }
209 {
210 std::list<int> l1(a1, a1+2);
211 std::list<int> l2;
212 l1.splice(position: std::next(x: l1.begin(), n: 2), x&: l2);
213 assert(l1.size() == 2);
214 assert(std::distance(l1.begin(), l1.end()) == 2);
215 assert(l2.size() == 0);
216 assert(std::distance(l2.begin(), l2.end()) == 0);
217 std::list<int>::const_iterator i = l1.begin();
218 assert(*i == 1);
219 ++i;
220 assert(*i == 2);
221 }
222 {
223 std::list<int> l1(a1, a1+2);
224 std::list<int> l2(a2, a2+1);
225 l1.splice(position: l1.begin(), x&: l2);
226 assert(l1.size() == 3);
227 assert(std::distance(l1.begin(), l1.end()) == 3);
228 assert(l2.size() == 0);
229 assert(std::distance(l2.begin(), l2.end()) == 0);
230 std::list<int>::const_iterator i = l1.begin();
231 assert(*i == 4);
232 ++i;
233 assert(*i == 1);
234 ++i;
235 assert(*i == 2);
236 }
237 {
238 std::list<int> l1(a1, a1+2);
239 std::list<int> l2(a2, a2+1);
240 l1.splice(position: std::next(x: l1.begin()), x&: l2);
241 assert(l1.size() == 3);
242 assert(std::distance(l1.begin(), l1.end()) == 3);
243 assert(l2.size() == 0);
244 assert(std::distance(l2.begin(), l2.end()) == 0);
245 std::list<int>::const_iterator i = l1.begin();
246 assert(*i == 1);
247 ++i;
248 assert(*i == 4);
249 ++i;
250 assert(*i == 2);
251 }
252 {
253 std::list<int> l1(a1, a1+2);
254 std::list<int> l2(a2, a2+1);
255 l1.splice(position: std::next(x: l1.begin(), n: 2), x&: l2);
256 assert(l1.size() == 3);
257 assert(std::distance(l1.begin(), l1.end()) == 3);
258 assert(l2.size() == 0);
259 assert(std::distance(l2.begin(), l2.end()) == 0);
260 std::list<int>::const_iterator i = l1.begin();
261 assert(*i == 1);
262 ++i;
263 assert(*i == 2);
264 ++i;
265 assert(*i == 4);
266 }
267 {
268 std::list<int> l1(a1, a1+2);
269 std::list<int> l2(a2, a2+2);
270 l1.splice(position: l1.begin(), x&: l2);
271 assert(l1.size() == 4);
272 assert(std::distance(l1.begin(), l1.end()) == 4);
273 assert(l2.size() == 0);
274 assert(std::distance(l2.begin(), l2.end()) == 0);
275 std::list<int>::const_iterator i = l1.begin();
276 assert(*i == 4);
277 ++i;
278 assert(*i == 5);
279 ++i;
280 assert(*i == 1);
281 ++i;
282 assert(*i == 2);
283 }
284 {
285 std::list<int> l1(a1, a1+2);
286 std::list<int> l2(a2, a2+2);
287 l1.splice(position: std::next(x: l1.begin()), x&: l2);
288 assert(l1.size() == 4);
289 assert(std::distance(l1.begin(), l1.end()) == 4);
290 assert(l2.size() == 0);
291 assert(std::distance(l2.begin(), l2.end()) == 0);
292 std::list<int>::const_iterator i = l1.begin();
293 assert(*i == 1);
294 ++i;
295 assert(*i == 4);
296 ++i;
297 assert(*i == 5);
298 ++i;
299 assert(*i == 2);
300 }
301 {
302 std::list<int> l1(a1, a1+2);
303 std::list<int> l2(a2, a2+2);
304 l1.splice(position: std::next(x: l1.begin(), n: 2), x&: l2);
305 assert(l1.size() == 4);
306 assert(std::distance(l1.begin(), l1.end()) == 4);
307 assert(l2.size() == 0);
308 assert(std::distance(l2.begin(), l2.end()) == 0);
309 std::list<int>::const_iterator i = l1.begin();
310 assert(*i == 1);
311 ++i;
312 assert(*i == 2);
313 ++i;
314 assert(*i == 4);
315 ++i;
316 assert(*i == 5);
317 }
318 {
319 std::list<int> l1(a1, a1+3);
320 std::list<int> l2(a2, a2+3);
321 l1.splice(position: l1.begin(), x&: l2);
322 assert(l1.size() == 6);
323 assert(std::distance(l1.begin(), l1.end()) == 6);
324 assert(l2.size() == 0);
325 assert(std::distance(l2.begin(), l2.end()) == 0);
326 std::list<int>::const_iterator i = l1.begin();
327 assert(*i == 4);
328 ++i;
329 assert(*i == 5);
330 ++i;
331 assert(*i == 6);
332 ++i;
333 assert(*i == 1);
334 ++i;
335 assert(*i == 2);
336 ++i;
337 assert(*i == 3);
338 }
339 {
340 std::list<int> l1(a1, a1+3);
341 std::list<int> l2(a2, a2+3);
342 l1.splice(position: std::next(x: l1.begin()), x&: l2);
343 assert(l1.size() == 6);
344 assert(std::distance(l1.begin(), l1.end()) == 6);
345 assert(l2.size() == 0);
346 assert(std::distance(l2.begin(), l2.end()) == 0);
347 std::list<int>::const_iterator i = l1.begin();
348 assert(*i == 1);
349 ++i;
350 assert(*i == 4);
351 ++i;
352 assert(*i == 5);
353 ++i;
354 assert(*i == 6);
355 ++i;
356 assert(*i == 2);
357 ++i;
358 assert(*i == 3);
359 }
360 {
361 std::list<int> l1(a1, a1+3);
362 std::list<int> l2(a2, a2+3);
363 l1.splice(position: std::next(x: l1.begin(), n: 2), x&: l2);
364 assert(l1.size() == 6);
365 assert(std::distance(l1.begin(), l1.end()) == 6);
366 assert(l2.size() == 0);
367 assert(std::distance(l2.begin(), l2.end()) == 0);
368 std::list<int>::const_iterator i = l1.begin();
369 assert(*i == 1);
370 ++i;
371 assert(*i == 2);
372 ++i;
373 assert(*i == 4);
374 ++i;
375 assert(*i == 5);
376 ++i;
377 assert(*i == 6);
378 ++i;
379 assert(*i == 3);
380 }
381 {
382 std::list<int> l1(a1, a1+3);
383 std::list<int> l2(a2, a2+3);
384 l1.splice(position: std::next(x: l1.begin(), n: 3), x&: l2);
385 assert(l1.size() == 6);
386 assert(std::distance(l1.begin(), l1.end()) == 6);
387 assert(l2.size() == 0);
388 assert(std::distance(l2.begin(), l2.end()) == 0);
389 std::list<int>::const_iterator i = l1.begin();
390 assert(*i == 1);
391 ++i;
392 assert(*i == 2);
393 ++i;
394 assert(*i == 3);
395 ++i;
396 assert(*i == 4);
397 ++i;
398 assert(*i == 5);
399 ++i;
400 assert(*i == 6);
401 }
402#if TEST_STD_VER >= 11
403 {
404 std::list<int, min_allocator<int>> l1;
405 std::list<int, min_allocator<int>> l2;
406 l1.splice(l1.end(), l2);
407 assert(l1.size() == 0);
408 assert(std::distance(l1.begin(), l1.end()) == 0);
409 assert(l2.size() == 0);
410 assert(std::distance(l2.begin(), l2.end()) == 0);
411 }
412 {
413 std::list<int, min_allocator<int>> l1;
414 std::list<int, min_allocator<int>> l2(a2, a2+1);
415 l1.splice(l1.end(), l2);
416 assert(l1.size() == 1);
417 assert(std::distance(l1.begin(), l1.end()) == 1);
418 assert(l2.size() == 0);
419 assert(std::distance(l2.begin(), l2.end()) == 0);
420 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
421 assert(*i == 4);
422 }
423 {
424 std::list<int, min_allocator<int>> l1;
425 std::list<int, min_allocator<int>> l2(a2, a2+2);
426 l1.splice(l1.end(), l2);
427 assert(l1.size() == 2);
428 assert(std::distance(l1.begin(), l1.end()) == 2);
429 assert(l2.size() == 0);
430 assert(std::distance(l2.begin(), l2.end()) == 0);
431 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
432 assert(*i == 4);
433 ++i;
434 assert(*i == 5);
435 }
436 {
437 std::list<int, min_allocator<int>> l1;
438 std::list<int, min_allocator<int>> l2(a2, a2+3);
439 l1.splice(l1.end(), l2);
440 assert(l1.size() == 3);
441 assert(std::distance(l1.begin(), l1.end()) == 3);
442 assert(l2.size() == 0);
443 assert(std::distance(l2.begin(), l2.end()) == 0);
444 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
445 assert(*i == 4);
446 ++i;
447 assert(*i == 5);
448 ++i;
449 assert(*i == 6);
450 }
451 {
452 std::list<int, min_allocator<int>> l1(a1, a1+1);
453 std::list<int, min_allocator<int>> l2;
454 l1.splice(l1.begin(), l2);
455 assert(l1.size() == 1);
456 assert(std::distance(l1.begin(), l1.end()) == 1);
457 assert(l2.size() == 0);
458 assert(std::distance(l2.begin(), l2.end()) == 0);
459 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
460 assert(*i == 1);
461 }
462 {
463 std::list<int, min_allocator<int>> l1(a1, a1+1);
464 std::list<int, min_allocator<int>> l2;
465 l1.splice(l1.end(), l2);
466 assert(l1.size() == 1);
467 assert(std::distance(l1.begin(), l1.end()) == 1);
468 assert(l2.size() == 0);
469 assert(std::distance(l2.begin(), l2.end()) == 0);
470 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
471 assert(*i == 1);
472 }
473 {
474 std::list<int, min_allocator<int>> l1(a1, a1+1);
475 std::list<int, min_allocator<int>> l2(a2, a2+1);
476 l1.splice(l1.begin(), l2);
477 assert(l1.size() == 2);
478 assert(std::distance(l1.begin(), l1.end()) == 2);
479 assert(l2.size() == 0);
480 assert(std::distance(l2.begin(), l2.end()) == 0);
481 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
482 assert(*i == 4);
483 ++i;
484 assert(*i == 1);
485 }
486 {
487 std::list<int, min_allocator<int>> l1(a1, a1+1);
488 std::list<int, min_allocator<int>> l2(a2, a2+1);
489 l1.splice(l1.end(), l2);
490 assert(l1.size() == 2);
491 assert(std::distance(l1.begin(), l1.end()) == 2);
492 assert(l2.size() == 0);
493 assert(std::distance(l2.begin(), l2.end()) == 0);
494 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
495 assert(*i == 1);
496 ++i;
497 assert(*i == 4);
498 }
499 {
500 std::list<int, min_allocator<int>> l1(a1, a1+1);
501 std::list<int, min_allocator<int>> l2(a2, a2+2);
502 l1.splice(l1.begin(), l2);
503 assert(l1.size() == 3);
504 assert(std::distance(l1.begin(), l1.end()) == 3);
505 assert(l2.size() == 0);
506 assert(std::distance(l2.begin(), l2.end()) == 0);
507 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
508 assert(*i == 4);
509 ++i;
510 assert(*i == 5);
511 ++i;
512 assert(*i == 1);
513 }
514 {
515 std::list<int, min_allocator<int>> l1(a1, a1+1);
516 std::list<int, min_allocator<int>> l2(a2, a2+2);
517 l1.splice(l1.end(), l2);
518 assert(l1.size() == 3);
519 assert(std::distance(l1.begin(), l1.end()) == 3);
520 assert(l2.size() == 0);
521 assert(std::distance(l2.begin(), l2.end()) == 0);
522 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
523 assert(*i == 1);
524 ++i;
525 assert(*i == 4);
526 ++i;
527 assert(*i == 5);
528 }
529 {
530 std::list<int, min_allocator<int>> l1(a1, a1+1);
531 std::list<int, min_allocator<int>> l2(a2, a2+3);
532 l1.splice(l1.begin(), l2);
533 assert(l1.size() == 4);
534 assert(std::distance(l1.begin(), l1.end()) == 4);
535 assert(l2.size() == 0);
536 assert(std::distance(l2.begin(), l2.end()) == 0);
537 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
538 assert(*i == 4);
539 ++i;
540 assert(*i == 5);
541 ++i;
542 assert(*i == 6);
543 ++i;
544 assert(*i == 1);
545 }
546 {
547 std::list<int, min_allocator<int>> l1(a1, a1+1);
548 std::list<int, min_allocator<int>> l2(a2, a2+3);
549 l1.splice(l1.end(), l2);
550 assert(l1.size() == 4);
551 assert(std::distance(l1.begin(), l1.end()) == 4);
552 assert(l2.size() == 0);
553 assert(std::distance(l2.begin(), l2.end()) == 0);
554 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
555 assert(*i == 1);
556 ++i;
557 assert(*i == 4);
558 ++i;
559 assert(*i == 5);
560 ++i;
561 assert(*i == 6);
562 }
563 {
564 std::list<int, min_allocator<int>> l1(a1, a1+2);
565 std::list<int, min_allocator<int>> l2;
566 l1.splice(l1.begin(), l2);
567 assert(l1.size() == 2);
568 assert(std::distance(l1.begin(), l1.end()) == 2);
569 assert(l2.size() == 0);
570 assert(std::distance(l2.begin(), l2.end()) == 0);
571 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
572 assert(*i == 1);
573 ++i;
574 assert(*i == 2);
575 }
576 {
577 std::list<int, min_allocator<int>> l1(a1, a1+2);
578 std::list<int, min_allocator<int>> l2;
579 l1.splice(std::next(l1.begin()), l2);
580 assert(l1.size() == 2);
581 assert(std::distance(l1.begin(), l1.end()) == 2);
582 assert(l2.size() == 0);
583 assert(std::distance(l2.begin(), l2.end()) == 0);
584 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
585 assert(*i == 1);
586 ++i;
587 assert(*i == 2);
588 }
589 {
590 std::list<int, min_allocator<int>> l1(a1, a1+2);
591 std::list<int, min_allocator<int>> l2;
592 l1.splice(std::next(l1.begin(), 2), l2);
593 assert(l1.size() == 2);
594 assert(std::distance(l1.begin(), l1.end()) == 2);
595 assert(l2.size() == 0);
596 assert(std::distance(l2.begin(), l2.end()) == 0);
597 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
598 assert(*i == 1);
599 ++i;
600 assert(*i == 2);
601 }
602 {
603 std::list<int, min_allocator<int>> l1(a1, a1+2);
604 std::list<int, min_allocator<int>> l2(a2, a2+1);
605 l1.splice(l1.begin(), l2);
606 assert(l1.size() == 3);
607 assert(std::distance(l1.begin(), l1.end()) == 3);
608 assert(l2.size() == 0);
609 assert(std::distance(l2.begin(), l2.end()) == 0);
610 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
611 assert(*i == 4);
612 ++i;
613 assert(*i == 1);
614 ++i;
615 assert(*i == 2);
616 }
617 {
618 std::list<int, min_allocator<int>> l1(a1, a1+2);
619 std::list<int, min_allocator<int>> l2(a2, a2+1);
620 l1.splice(std::next(l1.begin()), l2);
621 assert(l1.size() == 3);
622 assert(std::distance(l1.begin(), l1.end()) == 3);
623 assert(l2.size() == 0);
624 assert(std::distance(l2.begin(), l2.end()) == 0);
625 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
626 assert(*i == 1);
627 ++i;
628 assert(*i == 4);
629 ++i;
630 assert(*i == 2);
631 }
632 {
633 std::list<int, min_allocator<int>> l1(a1, a1+2);
634 std::list<int, min_allocator<int>> l2(a2, a2+1);
635 l1.splice(std::next(l1.begin(), 2), l2);
636 assert(l1.size() == 3);
637 assert(std::distance(l1.begin(), l1.end()) == 3);
638 assert(l2.size() == 0);
639 assert(std::distance(l2.begin(), l2.end()) == 0);
640 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
641 assert(*i == 1);
642 ++i;
643 assert(*i == 2);
644 ++i;
645 assert(*i == 4);
646 }
647 {
648 std::list<int, min_allocator<int>> l1(a1, a1+2);
649 std::list<int, min_allocator<int>> l2(a2, a2+2);
650 l1.splice(l1.begin(), l2);
651 assert(l1.size() == 4);
652 assert(std::distance(l1.begin(), l1.end()) == 4);
653 assert(l2.size() == 0);
654 assert(std::distance(l2.begin(), l2.end()) == 0);
655 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
656 assert(*i == 4);
657 ++i;
658 assert(*i == 5);
659 ++i;
660 assert(*i == 1);
661 ++i;
662 assert(*i == 2);
663 }
664 {
665 std::list<int, min_allocator<int>> l1(a1, a1+2);
666 std::list<int, min_allocator<int>> l2(a2, a2+2);
667 l1.splice(std::next(l1.begin()), l2);
668 assert(l1.size() == 4);
669 assert(std::distance(l1.begin(), l1.end()) == 4);
670 assert(l2.size() == 0);
671 assert(std::distance(l2.begin(), l2.end()) == 0);
672 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
673 assert(*i == 1);
674 ++i;
675 assert(*i == 4);
676 ++i;
677 assert(*i == 5);
678 ++i;
679 assert(*i == 2);
680 }
681 {
682 std::list<int, min_allocator<int>> l1(a1, a1+2);
683 std::list<int, min_allocator<int>> l2(a2, a2+2);
684 l1.splice(std::next(l1.begin(), 2), l2);
685 assert(l1.size() == 4);
686 assert(std::distance(l1.begin(), l1.end()) == 4);
687 assert(l2.size() == 0);
688 assert(std::distance(l2.begin(), l2.end()) == 0);
689 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
690 assert(*i == 1);
691 ++i;
692 assert(*i == 2);
693 ++i;
694 assert(*i == 4);
695 ++i;
696 assert(*i == 5);
697 }
698 {
699 std::list<int, min_allocator<int>> l1(a1, a1+3);
700 std::list<int, min_allocator<int>> l2(a2, a2+3);
701 l1.splice(l1.begin(), l2);
702 assert(l1.size() == 6);
703 assert(std::distance(l1.begin(), l1.end()) == 6);
704 assert(l2.size() == 0);
705 assert(std::distance(l2.begin(), l2.end()) == 0);
706 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
707 assert(*i == 4);
708 ++i;
709 assert(*i == 5);
710 ++i;
711 assert(*i == 6);
712 ++i;
713 assert(*i == 1);
714 ++i;
715 assert(*i == 2);
716 ++i;
717 assert(*i == 3);
718 }
719 {
720 std::list<int, min_allocator<int>> l1(a1, a1+3);
721 std::list<int, min_allocator<int>> l2(a2, a2+3);
722 l1.splice(std::next(l1.begin()), l2);
723 assert(l1.size() == 6);
724 assert(std::distance(l1.begin(), l1.end()) == 6);
725 assert(l2.size() == 0);
726 assert(std::distance(l2.begin(), l2.end()) == 0);
727 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
728 assert(*i == 1);
729 ++i;
730 assert(*i == 4);
731 ++i;
732 assert(*i == 5);
733 ++i;
734 assert(*i == 6);
735 ++i;
736 assert(*i == 2);
737 ++i;
738 assert(*i == 3);
739 }
740 {
741 std::list<int, min_allocator<int>> l1(a1, a1+3);
742 std::list<int, min_allocator<int>> l2(a2, a2+3);
743 l1.splice(std::next(l1.begin(), 2), l2);
744 assert(l1.size() == 6);
745 assert(std::distance(l1.begin(), l1.end()) == 6);
746 assert(l2.size() == 0);
747 assert(std::distance(l2.begin(), l2.end()) == 0);
748 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
749 assert(*i == 1);
750 ++i;
751 assert(*i == 2);
752 ++i;
753 assert(*i == 4);
754 ++i;
755 assert(*i == 5);
756 ++i;
757 assert(*i == 6);
758 ++i;
759 assert(*i == 3);
760 }
761 {
762 std::list<int, min_allocator<int>> l1(a1, a1+3);
763 std::list<int, min_allocator<int>> l2(a2, a2+3);
764 l1.splice(std::next(l1.begin(), 3), l2);
765 assert(l1.size() == 6);
766 assert(std::distance(l1.begin(), l1.end()) == 6);
767 assert(l2.size() == 0);
768 assert(std::distance(l2.begin(), l2.end()) == 0);
769 std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
770 assert(*i == 1);
771 ++i;
772 assert(*i == 2);
773 ++i;
774 assert(*i == 3);
775 ++i;
776 assert(*i == 4);
777 ++i;
778 assert(*i == 5);
779 ++i;
780 assert(*i == 6);
781 }
782#endif
783
784 return 0;
785}
786

source code of libcxx/test/std/containers/sequences/list/list.ops/splice_pos_list.pass.cpp