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// <forward_list>
10
11// forward_list& operator=(const forward_list& x); // constexpr since C++26
12
13#include <forward_list>
14#include <cassert>
15#include <iterator>
16
17#include "test_macros.h"
18#include "test_allocator.h"
19#include "min_allocator.h"
20
21TEST_CONSTEXPR_CXX26 bool test() {
22 {
23 typedef int T;
24 typedef test_allocator<int> A;
25 typedef std::forward_list<T, A> C;
26 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
27 const T t1[] = {10, 11, 12, 13};
28 C c0(std::begin(t0), std::end(t0), A(10));
29 C c1(std::begin(arr: t1), std::end(arr: t1), A(10));
30 c1 = c0;
31 assert(c1 == c0);
32 assert(c1.get_allocator() == A(10));
33 }
34 {
35 typedef int T;
36 typedef test_allocator<int> A;
37 typedef std::forward_list<T, A> C;
38 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
39 const T t1[] = {10, 11, 12, 13};
40 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
41 C c1(std::begin(arr: t1), std::end(arr: t1), A(11));
42 c1 = c0;
43 assert(c1 == c0);
44 assert(c1.get_allocator() == A(11));
45 }
46 {
47 typedef int T;
48 typedef test_allocator<int> A;
49 typedef std::forward_list<T, A> C;
50 const T t0[] = {10, 11, 12, 13};
51 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
52 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
53 C c1(std::begin(arr: t1), std::end(arr: t1), A(10));
54 c1 = c0;
55 assert(c1 == c0);
56 assert(c1.get_allocator() == A(10));
57 }
58 {
59 typedef int T;
60 typedef test_allocator<int> A;
61 typedef std::forward_list<T, A> C;
62 const T t0[] = {10, 11, 12, 13};
63 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
64 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
65 C c1(std::begin(arr: t1), std::end(arr: t1), A(11));
66 c1 = c0;
67 assert(c1 == c0);
68 assert(c1.get_allocator() == A(11));
69 }
70
71 {
72 typedef int T;
73 typedef other_allocator<int> A;
74 typedef std::forward_list<T, A> C;
75 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
76 const T t1[] = {10, 11, 12, 13};
77 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
78 C c1(std::begin(arr: t1), std::end(arr: t1), A(10));
79 c1 = c0;
80 assert(c1 == c0);
81 assert(c1.get_allocator() == A(10));
82 }
83 {
84 typedef int T;
85 typedef other_allocator<int> A;
86 typedef std::forward_list<T, A> C;
87 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
88 const T t1[] = {10, 11, 12, 13};
89 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
90 C c1(std::begin(arr: t1), std::end(arr: t1), A(11));
91 c1 = c0;
92 assert(c1 == c0);
93 assert(c1.get_allocator() == A(10));
94 }
95 {
96 typedef int T;
97 typedef other_allocator<int> A;
98 typedef std::forward_list<T, A> C;
99 const T t0[] = {10, 11, 12, 13};
100 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
101 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
102 C c1(std::begin(arr: t1), std::end(arr: t1), A(10));
103 c1 = c0;
104 assert(c1 == c0);
105 assert(c1.get_allocator() == A(10));
106 }
107 {
108 typedef int T;
109 typedef other_allocator<int> A;
110 typedef std::forward_list<T, A> C;
111 const T t0[] = {10, 11, 12, 13};
112 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
113 C c0(std::begin(arr: t0), std::end(arr: t0), A(10));
114 C c1(std::begin(arr: t1), std::end(arr: t1), A(11));
115 c1 = c0;
116 assert(c1 == c0);
117 assert(c1.get_allocator() == A(10));
118 }
119#if TEST_STD_VER >= 11
120 {
121 typedef int T;
122 typedef min_allocator<int> A;
123 typedef std::forward_list<T, A> C;
124 const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
125 const T t1[] = {10, 11, 12, 13};
126 C c0(std::begin(t0), std::end(t0), A());
127 C c1(std::begin(t1), std::end(t1), A());
128 c1 = c0;
129 assert(c1 == c0);
130 assert(c1.get_allocator() == A());
131 }
132 {
133 typedef int T;
134 typedef min_allocator<int> A;
135 typedef std::forward_list<T, A> C;
136 const T t0[] = {10, 11, 12, 13};
137 const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
138 C c0(std::begin(t0), std::end(t0), A());
139 C c1(std::begin(t1), std::end(t1), A());
140 c1 = c0;
141 assert(c1 == c0);
142 assert(c1.get_allocator() == A());
143 }
144#endif
145
146 return true;
147}
148
149int main(int, char**) {
150 assert(test());
151#if TEST_STD_VER >= 26
152 static_assert(test());
153#endif
154
155 return 0;
156}
157

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