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 | // UNSUPPORTED: c++03 |
10 | |
11 | // <forward_list> |
12 | |
13 | // forward_list& operator=(forward_list&& x); |
14 | |
15 | #include <forward_list> |
16 | #include <cassert> |
17 | #include <iterator> |
18 | |
19 | #include "test_macros.h" |
20 | #include "test_allocator.h" |
21 | #include "MoveOnly.h" |
22 | #include "min_allocator.h" |
23 | |
24 | int main(int, char**) |
25 | { |
26 | { |
27 | typedef MoveOnly T; |
28 | typedef test_allocator<T> A; |
29 | typedef std::forward_list<T, A> C; |
30 | T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
31 | T t1[] = {10, 11, 12, 13}; |
32 | typedef std::move_iterator<T*> I; |
33 | C c0(I(std::begin(t0)), I(std::end(t0)), A(10)); |
34 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(10)); |
35 | c1 = std::move(c0); |
36 | int n = 0; |
37 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
38 | assert(*i == n); |
39 | assert(n == 10); |
40 | assert(c1.get_allocator() == A(10)); |
41 | assert(c0.empty()); |
42 | } |
43 | { |
44 | typedef MoveOnly T; |
45 | typedef test_allocator<T> A; |
46 | typedef std::forward_list<T, A> C; |
47 | T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
48 | T t1[] = {10, 11, 12, 13}; |
49 | typedef std::move_iterator<T*> I; |
50 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
51 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(11)); |
52 | c1 = std::move(c0); |
53 | int n = 0; |
54 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
55 | assert(*i == n); |
56 | assert(n == 10); |
57 | assert(c1.get_allocator() == A(11)); |
58 | assert(!c0.empty()); |
59 | } |
60 | { |
61 | typedef MoveOnly T; |
62 | typedef test_allocator<T> A; |
63 | typedef std::forward_list<T, A> C; |
64 | T t0[] = {10, 11, 12, 13}; |
65 | T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
66 | typedef std::move_iterator<T*> I; |
67 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
68 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(10)); |
69 | c1 = std::move(c0); |
70 | int n = 0; |
71 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
72 | assert(*i == 10+n); |
73 | assert(n == 4); |
74 | assert(c1.get_allocator() == A(10)); |
75 | assert(c0.empty()); |
76 | } |
77 | { |
78 | typedef MoveOnly T; |
79 | typedef test_allocator<T> A; |
80 | typedef std::forward_list<T, A> C; |
81 | T t0[] = {10, 11, 12, 13}; |
82 | T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
83 | typedef std::move_iterator<T*> I; |
84 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
85 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(11)); |
86 | c1 = std::move(c0); |
87 | int n = 0; |
88 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
89 | assert(*i == 10+n); |
90 | assert(n == 4); |
91 | assert(c1.get_allocator() == A(11)); |
92 | assert(!c0.empty()); |
93 | } |
94 | |
95 | { |
96 | typedef MoveOnly T; |
97 | typedef other_allocator<T> A; |
98 | typedef std::forward_list<T, A> C; |
99 | T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
100 | T t1[] = {10, 11, 12, 13}; |
101 | typedef std::move_iterator<T*> I; |
102 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
103 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(10)); |
104 | c1 = std::move(c0); |
105 | int n = 0; |
106 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
107 | assert(*i == n); |
108 | assert(n == 10); |
109 | assert(c1.get_allocator() == A(10)); |
110 | assert(c0.empty()); |
111 | } |
112 | { |
113 | typedef MoveOnly T; |
114 | typedef other_allocator<T> A; |
115 | typedef std::forward_list<T, A> C; |
116 | T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
117 | T t1[] = {10, 11, 12, 13}; |
118 | typedef std::move_iterator<T*> I; |
119 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
120 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(11)); |
121 | c1 = std::move(c0); |
122 | int n = 0; |
123 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
124 | assert(*i == n); |
125 | assert(n == 10); |
126 | assert(c1.get_allocator() == A(10)); |
127 | assert(c0.empty()); |
128 | } |
129 | { |
130 | typedef MoveOnly T; |
131 | typedef other_allocator<T> A; |
132 | typedef std::forward_list<T, A> C; |
133 | T t0[] = {10, 11, 12, 13}; |
134 | T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
135 | typedef std::move_iterator<T*> I; |
136 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
137 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(10)); |
138 | c1 = std::move(c0); |
139 | int n = 0; |
140 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
141 | assert(*i == 10+n); |
142 | assert(n == 4); |
143 | assert(c1.get_allocator() == A(10)); |
144 | assert(c0.empty()); |
145 | } |
146 | { |
147 | typedef MoveOnly T; |
148 | typedef other_allocator<T> A; |
149 | typedef std::forward_list<T, A> C; |
150 | T t0[] = {10, 11, 12, 13}; |
151 | T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
152 | typedef std::move_iterator<T*> I; |
153 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A(10)); |
154 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A(11)); |
155 | c1 = std::move(c0); |
156 | int n = 0; |
157 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
158 | assert(*i == 10+n); |
159 | assert(n == 4); |
160 | assert(c1.get_allocator() == A(10)); |
161 | assert(c0.empty()); |
162 | } |
163 | { |
164 | typedef MoveOnly T; |
165 | typedef min_allocator<T> A; |
166 | typedef std::forward_list<T, A> C; |
167 | T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
168 | T t1[] = {10, 11, 12, 13}; |
169 | typedef std::move_iterator<T*> I; |
170 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A()); |
171 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A()); |
172 | c1 = std::move(c0); |
173 | int n = 0; |
174 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
175 | assert(*i == n); |
176 | assert(n == 10); |
177 | assert(c1.get_allocator() == A()); |
178 | assert(c0.empty()); |
179 | } |
180 | { |
181 | typedef MoveOnly T; |
182 | typedef min_allocator<T> A; |
183 | typedef std::forward_list<T, A> C; |
184 | T t0[] = {10, 11, 12, 13}; |
185 | T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; |
186 | typedef std::move_iterator<T*> I; |
187 | C c0(I(std::begin(arr&: t0)), I(std::end(arr&: t0)), A()); |
188 | C c1(I(std::begin(arr&: t1)), I(std::end(arr&: t1)), A()); |
189 | c1 = std::move(c0); |
190 | int n = 0; |
191 | for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, (void) ++n) |
192 | assert(*i == 10+n); |
193 | assert(n == 4); |
194 | assert(c1.get_allocator() == A()); |
195 | assert(c0.empty()); |
196 | } |
197 | |
198 | return 0; |
199 | } |
200 | |