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

source code of libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/assign_move.pass.cpp