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 // UNSUPPORTED: c++03, no-exceptions
14 // - throwing upon moving;
15 // - initializer lists;
16 // - throwing when constructing the element in place.
18 // list(size_type n, const value_type& v);
19 // list(size_type n, const value_type& v, const allocator_type& a);
20 // template <class InputIterator>
21 // list(InputIterator first, InputIterator last);
22 // template <class InputIterator>
23 // list(InputIterator first, InputIterator last, const allocator_type& a);
24 // template<container-compatible-range<T> R>
25 // list(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
26 // list(const list& x);
27 // list(const list& x, const allocator_type& a);
29 // list& operator=(const list& x);
31 // template <class InputIterator>
32 // void assign(InputIterator first, InputIterator last);
33 // void assign(size_type n, const value_type& v);
34 // template<container-compatible-range<T> R>
35 // void assign_range(R&& rg); // C++23
37 // template<container-compatible-range<T> R>
38 // void prepend_range(R&& rg); // C++23
39 // void push_back(const value_type& x);
40 // template<container-compatible-range<T> R>
41 // void append_range(R&& rg); // C++23
42 // void push_front(const value_type& v);
44 // iterator insert(const_iterator p, const value_type& v);
45 // iterator insert(const_iterator p, size_type n, const value_type& v);
46 // template <class InputIterator>
47 // iterator insert(const_iterator p,
48 // InputIterator first, InputIterator last);
49 // template<container-compatible-range<T> R>
50 // iterator insert_range(const_iterator position, R&& rg); // C++23
52 // void resize(size_type n, const value_type& v);
57 #include "../../exception_safety_helpers.h"
58 #include "test_macros.h"
60 #if TEST_STD_VER >= 23
64 int main(int, char**) {
66 constexpr int ThrowOn
= 1;
67 constexpr int Size
= 1;
68 using T
= ThrowingCopy
<ThrowOn
>;
70 // void push_front(const value_type& v);
71 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*){
76 // void push_back(const value_type& v);
77 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*){
82 // iterator insert(const_iterator p, const value_type& v);
83 test_exception_safety_throwing_copy
</*ThrowOn=*/1, Size
>([](T
* from
, T
*){
85 c
.insert(c
.end(), *from
);
90 constexpr int ThrowOn
= 3;
91 constexpr int Size
= 5;
92 using T
= ThrowingCopy
<ThrowOn
>;
93 using C
= std::list
<T
>;
94 using Alloc
= std::allocator
<T
>;
96 // list(size_type n, const value_type& v);
97 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*){
98 std::list
<T
> c(Size
, *from
);
102 // list(size_type n, const value_type& v, const allocator_type& a);
103 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*){
104 std::list
<T
> c(Size
, *from
, Alloc());
108 // template <class InputIterator>
109 // list(InputIterator first, InputIterator last);
110 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
){
111 std::list
<T
> c(from
, to
);
115 // template <class InputIterator>
116 // list(InputIterator first, InputIterator last, const allocator_type& a);
117 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
){
118 std::list
<T
> c(from
, to
, Alloc());
122 #if TEST_STD_VER >= 23
123 // template<container-compatible-range<T> R>
124 // list(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
125 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
){
127 std::list
<T
> c(std::from_range
, std::ranges::subrange(from
, to
));
132 std::list
<T
> c(std::from_range
, std::ranges::subrange(from
, to
), Alloc());
138 // list(const list& x);
139 test_exception_safety_throwing_copy_container
<C
, ThrowOn
, Size
>([](C
&& in
) {
144 // list(const list& x, const allocator_type& a);
145 test_exception_safety_throwing_copy_container
<C
, ThrowOn
, Size
>([](C
&& in
) {
146 std::list
<T
> c(in
, Alloc());
150 // list& operator=(const list& x);
151 test_exception_safety_throwing_copy_container
<C
, ThrowOn
, Size
>([](C
&& in
) {
156 // template <class InputIterator>
157 // void assign(InputIterator first, InputIterator last);
158 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
) {
163 #if TEST_STD_VER >= 23
164 // template<container-compatible-range<T> R>
165 // void assign_range(R&& rg); // C++23
166 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
) {
168 c
.assign_range(std::ranges::subrange(from
, to
));
172 // void assign(size_type n, const value_type& v);
173 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*) {
175 c
.assign(Size
, *from
);
178 #if TEST_STD_VER >= 23
179 // template<container-compatible-range<T> R>
180 // void prepend_range(R&& rg); // C++23
181 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
) {
183 c
.prepend_range(std::ranges::subrange(from
, to
));
186 // template<container-compatible-range<T> R>
187 // void append_range(R&& rg); // C++23
188 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
) {
190 c
.append_range(std::ranges::subrange(from
, to
));
194 // iterator insert(const_iterator p, size_type n, const value_type& v);
195 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*) {
197 c
.insert(c
.end(), Size
, *from
);
200 // template <class InputIterator>
201 // iterator insert(const_iterator p,
202 // InputIterator first, InputIterator last);
203 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
) {
205 c
.insert(c
.end(), from
, to
);
208 #if TEST_STD_VER >= 23
209 // template<container-compatible-range<T> R>
210 // iterator insert_range(const_iterator position, R&& rg); // C++23
211 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
* to
) {
213 c
.insert_range(c
.end(), std::ranges::subrange(from
, to
));
217 // void resize(size_type n, const value_type& v);
218 test_exception_safety_throwing_copy
<ThrowOn
, Size
>([](T
* from
, T
*) {
220 c
.resize(Size
, *from
);