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 //===----------------------------------------------------------------------===//
11 // template <class T, class Alloc>
12 // void swap(list<T,Alloc>& x, list<T,Alloc>& y);
16 #include "test_macros.h"
17 #include "test_allocator.h"
18 #include "min_allocator.h"
23 int a1
[] = {1, 3, 7, 9, 10};
24 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
25 std::list
<int> c1(a1
, a1
+ 5);
26 std::list
<int> c2(a2
, a2
+ 7);
27 std::list
<int>::iterator it1
= c1
.begin();
28 std::list
<int>::const_iterator it2
= c2
.begin();
30 assert(c1
== std::list
<int>(a2
, a2
+ 7));
31 assert(c2
== std::list
<int>(a1
, a1
+ 5));
32 assert(it1
== c2
.begin()); // Iterators remain valid
33 assert(it2
== c1
.begin()); // Iterators remain valid
36 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
38 std::list
<int> c2(a2
, a2
+ 7);
40 assert(c1
== std::list
<int>(a2
, a2
+ 7));
42 assert(std::distance(c2
.begin(), c2
.end()) == 0);
45 int a1
[] = {1, 3, 7, 9, 10};
46 std::list
<int> c1(a1
, a1
+ 5);
50 assert(std::distance(c1
.begin(), c1
.end()) == 0);
51 assert(c2
== std::list
<int>(a1
, a1
+ 5));
58 assert(std::distance(c1
.begin(), c1
.end()) == 0);
60 assert(std::distance(c2
.begin(), c2
.end()) == 0);
63 int a1
[] = {1, 3, 7, 9, 10};
64 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
65 typedef test_allocator
<int> A
;
66 std::list
<int, A
> c1(a1
, a1
+ 5, A(1));
67 std::list
<int, A
> c2(a2
, a2
+ 7, A(1));
69 assert((c1
== std::list
<int, A
>(a2
, a2
+ 7)));
70 assert(c1
.get_allocator() == A(1));
71 assert((c2
== std::list
<int, A
>(a1
, a1
+ 5)));
72 assert(c2
.get_allocator() == A(1));
75 int a1
[] = {1, 3, 7, 9, 10};
76 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
77 typedef other_allocator
<int> A
;
78 std::list
<int, A
> c1(a1
, a1
+ 5, A(1));
79 std::list
<int, A
> c2(a2
, a2
+ 7, A(2));
81 assert((c1
== std::list
<int, A
>(a2
, a2
+ 7)));
82 assert(c1
.get_allocator() == A(2));
83 assert((c2
== std::list
<int, A
>(a1
, a1
+ 5)));
84 assert(c2
.get_allocator() == A(1));
86 #if TEST_STD_VER >= 11
88 int a1
[] = {1, 3, 7, 9, 10};
89 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
90 std::list
<int, min_allocator
<int>> c1(a1
, a1
+ 5);
91 std::list
<int, min_allocator
<int>> c2(a2
, a2
+ 7);
93 assert((c1
== std::list
<int, min_allocator
<int>>(a2
, a2
+ 7)));
94 assert((c2
== std::list
<int, min_allocator
<int>>(a1
, a1
+ 5)));
97 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
98 std::list
<int, min_allocator
<int>> c1
;
99 std::list
<int, min_allocator
<int>> c2(a2
, a2
+ 7);
101 assert((c1
== std::list
<int, min_allocator
<int>>(a2
, a2
+ 7)));
103 assert(std::distance(c2
.begin(), c2
.end()) == 0);
106 int a1
[] = {1, 3, 7, 9, 10};
107 std::list
<int, min_allocator
<int>> c1(a1
, a1
+ 5);
108 std::list
<int, min_allocator
<int>> c2
;
111 assert(std::distance(c1
.begin(), c1
.end()) == 0);
112 assert((c2
== std::list
<int, min_allocator
<int>>(a1
, a1
+ 5)));
115 std::list
<int, min_allocator
<int>> c1
;
116 std::list
<int, min_allocator
<int>> c2
;
119 assert(std::distance(c1
.begin(), c1
.end()) == 0);
121 assert(std::distance(c2
.begin(), c2
.end()) == 0);
124 int a1
[] = {1, 3, 7, 9, 10};
125 int a2
[] = {0, 2, 4, 5, 6, 8, 11};
126 typedef min_allocator
<int> A
;
127 std::list
<int, A
> c1(a1
, a1
+ 5, A());
128 std::list
<int, A
> c2(a2
, a2
+ 7, A());
130 assert((c1
== std::list
<int, A
>(a2
, a2
+ 7)));
131 assert(c1
.get_allocator() == A());
132 assert((c2
== std::list
<int, A
>(a1
, a1
+ 5)));
133 assert(c2
.get_allocator() == A());