2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
19 template <class T, class Alloc = allocator<T> >
26 typedef Alloc allocator_type;
27 typedef typename allocator_type::reference reference;
28 typedef typename allocator_type::const_reference const_reference;
29 typedef typename allocator_type::pointer pointer;
30 typedef typename allocator_type::const_pointer const_pointer;
31 typedef implementation-defined iterator;
32 typedef implementation-defined const_iterator;
33 typedef implementation-defined size_type;
34 typedef implementation-defined difference_type;
35 typedef reverse_iterator<iterator> reverse_iterator;
36 typedef reverse_iterator<const_iterator> const_reverse_iterator;
39 noexcept(is_nothrow_default_constructible<allocator_type>::value);
40 explicit list(const allocator_type& a);
41 explicit list(size_type n);
42 explicit list(size_type n, const allocator_type& a); // C++14
43 list(size_type n, const value_type& value);
44 list(size_type n, const value_type& value, const allocator_type& a);
46 list(Iter first, Iter last);
48 list(Iter first, Iter last, const allocator_type& a);
49 template<container-compatible-range<T> R>
50 list(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
52 list(const list&, const allocator_type& a);
54 noexcept(is_nothrow_move_constructible<allocator_type>::value);
55 list(list&&, const allocator_type& a);
56 list(initializer_list<value_type>);
57 list(initializer_list<value_type>, const allocator_type& a);
61 list& operator=(const list& x);
62 list& operator=(list&& x)
64 allocator_type::propagate_on_container_move_assignment::value &&
65 is_nothrow_move_assignable<allocator_type>::value);
66 list& operator=(initializer_list<value_type>);
68 void assign(Iter first, Iter last);
69 template<container-compatible-range<T> R>
70 void assign_range(R&& rg); // C++23
71 void assign(size_type n, const value_type& t);
72 void assign(initializer_list<value_type>);
74 allocator_type get_allocator() const noexcept;
76 iterator begin() noexcept;
77 const_iterator begin() const noexcept;
78 iterator end() noexcept;
79 const_iterator end() const noexcept;
80 reverse_iterator rbegin() noexcept;
81 const_reverse_iterator rbegin() const noexcept;
82 reverse_iterator rend() noexcept;
83 const_reverse_iterator rend() const noexcept;
84 const_iterator cbegin() const noexcept;
85 const_iterator cend() const noexcept;
86 const_reverse_iterator crbegin() const noexcept;
87 const_reverse_iterator crend() const noexcept;
90 const_reference front() const;
92 const_reference back() const;
94 bool empty() const noexcept;
95 size_type size() const noexcept;
96 size_type max_size() const noexcept;
98 template <class... Args>
99 reference emplace_front(Args&&... args); // reference in C++17
101 template <class... Args>
102 reference emplace_back(Args&&... args); // reference in C++17
104 void push_front(const value_type& x);
105 void push_front(value_type&& x);
106 template<container-compatible-range<T> R>
107 void prepend_range(R&& rg); // C++23
108 void push_back(const value_type& x);
109 void push_back(value_type&& x);
110 template<container-compatible-range<T> R>
111 void append_range(R&& rg); // C++23
112 template <class... Args>
113 iterator emplace(const_iterator position, Args&&... args);
114 iterator insert(const_iterator position, const value_type& x);
115 iterator insert(const_iterator position, value_type&& x);
116 iterator insert(const_iterator position, size_type n, const value_type& x);
117 template <class Iter>
118 iterator insert(const_iterator position, Iter first, Iter last);
119 template<container-compatible-range<T> R>
120 iterator insert_range(const_iterator position, R&& rg); // C++23
121 iterator insert(const_iterator position, initializer_list<value_type> il);
123 iterator erase(const_iterator position);
124 iterator erase(const_iterator position, const_iterator last);
126 void resize(size_type sz);
127 void resize(size_type sz, const value_type& c);
130 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
131 void clear() noexcept;
133 void splice(const_iterator position, list& x);
134 void splice(const_iterator position, list&& x);
135 void splice(const_iterator position, list& x, const_iterator i);
136 void splice(const_iterator position, list&& x, const_iterator i);
137 void splice(const_iterator position, list& x, const_iterator first,
138 const_iterator last);
139 void splice(const_iterator position, list&& x, const_iterator first,
140 const_iterator last);
142 size_type remove(const value_type& value); // void before C++20
143 template <class Pred>
144 size_type remove_if(Pred pred); // void before C++20
145 size_type unique(); // void before C++20
146 template <class BinaryPredicate>
147 size_type unique(BinaryPredicate binary_pred); // void before C++20
149 void merge(list&& x);
150 template <class Compare>
151 void merge(list& x, Compare comp);
152 template <class Compare>
153 void merge(list&& x, Compare comp);
155 template <class Compare>
156 void sort(Compare comp);
157 void reverse() noexcept;
161 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
162 list(InputIterator, InputIterator, Allocator = Allocator())
163 -> list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
165 template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
166 list(from_range_t, R&&, Allocator = Allocator())
167 -> list<ranges::range_value_t<R>, Allocator>; // C++23
169 template <class T, class Alloc>
170 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
171 template <class T, class Alloc>
172 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
173 template <class T, class Alloc>
174 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
175 template <class T, class Alloc>
176 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
177 template <class T, class Alloc>
178 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
179 template <class T, class Alloc>
180 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
181 template<class T, class Allocator>
182 synth-three-way-result<T> operator<=>(const list<T, Allocator>& x,
183 const list<T, Allocator>& y); // since C++20
185 template <class T, class Alloc>
186 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
187 noexcept(noexcept(x.swap(y)));
189 template <class T, class Allocator, class U>
190 typename list<T, Allocator>::size_type
191 erase(list<T, Allocator>& c, const U& value); // since C++20
192 template <class T, class Allocator, class Predicate>
193 typename list<T, Allocator>::size_type
194 erase_if(list<T, Allocator>& c, Predicate pred); // since C++20
200 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
201 # include <__cxx03/list>
203 # include <__algorithm/comp.h>
204 # include <__algorithm/equal.h>
205 # include <__algorithm/lexicographical_compare.h>
206 # include <__algorithm/lexicographical_compare_three_way.h>
207 # include <__algorithm/min.h>
210 # include <__format/enable_insertable.h>
211 # include <__iterator/distance.h>
212 # include <__iterator/iterator_traits.h>
213 # include <__iterator/move_iterator.h>
214 # include <__iterator/next.h>
215 # include <__iterator/prev.h>
216 # include <__iterator/reverse_iterator.h>
217 # include <__memory/addressof.h>
218 # include <__memory/allocation_guard.h>
219 # include <__memory/allocator.h>
220 # include <__memory/allocator_traits.h>
221 # include <__memory/compressed_pair.h>
222 # include <__memory/construct_at.h>
223 # include <__memory/pointer_traits.h>
224 # include <__memory/swap_allocator.h>
225 # include <__memory_resource/polymorphic_allocator.h>
226 # include <__new/launder.h>
227 # include <__ranges/access.h>
228 # include <__ranges/concepts.h>
229 # include <__ranges/container_compatible_range.h>
230 # include <__ranges/from_range.h>
231 # include <__type_traits/conditional.h>
232 # include <__type_traits/container_traits.h>
233 # include <__type_traits/enable_if.h>
234 # include <__type_traits/is_allocator.h>
235 # include <__type_traits/is_nothrow_assignable.h>
236 # include <__type_traits/is_nothrow_constructible.h>
237 # include <__type_traits/is_pointer.h>
238 # include <__type_traits/is_same.h>
239 # include <__type_traits/type_identity.h>
240 # include <__utility/forward.h>
241 # include <__utility/move.h>
242 # include <__utility/swap.h>
247 // standard-mandated includes
250 # include <__iterator/access.h>
251 # include <__iterator/data.h>
252 # include <__iterator/empty.h>
253 # include <__iterator/reverse_access.h>
254 # include <__iterator/size.h>
258 # include <initializer_list>
260 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
261 # pragma GCC system_header
265 # include <__undef_macros>
267 _LIBCPP_BEGIN_NAMESPACE_STD
269 template <class _Tp, class _VoidPtr>
271 template <class _Tp, class _VoidPtr>
272 struct __list_node_base;
274 template <class _Tp, class _VoidPtr>
275 struct __list_node_pointer_traits {
276 typedef __rebind_pointer_t<_VoidPtr, __list_node<_Tp, _VoidPtr> > __node_pointer;
277 typedef __rebind_pointer_t<_VoidPtr, __list_node_base<_Tp, _VoidPtr> > __base_pointer;
279 // TODO(LLVM 22): Remove this check
280 # ifndef _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
281 static_assert(sizeof(__node_pointer) == sizeof(__node_pointer) && _LIBCPP_ALIGNOF(__base_pointer) ==
282 _LIBCPP_ALIGNOF(__node_pointer),
283 "It looks like you are using std::list with a fancy pointer type that thas a different representation "
284 "depending on whether it points to a list base pointer or a list node pointer (both of which are "
285 "implementation details of the standard library). This means that your ABI is being broken between "
286 "LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define the "
287 "_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
290 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__base_pointer __p) { return __p; }
292 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__node_pointer __p) {
293 return static_cast<__base_pointer>(static_cast<_VoidPtr>(__p));
297 template <class _Tp, class _VoidPtr>
298 struct __list_node_base {
299 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
300 typedef typename _NodeTraits::__node_pointer __node_pointer;
301 typedef typename _NodeTraits::__base_pointer __base_pointer;
303 __base_pointer __prev_;
304 __base_pointer __next_;
306 _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
308 _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__base_pointer __prev, __base_pointer __next)
309 : __prev_(__prev), __next_(__next) {}
311 _LIBCPP_HIDE_FROM_ABI __base_pointer __self() { return pointer_traits<__base_pointer>::pointer_to(*this); }
313 _LIBCPP_HIDE_FROM_ABI __node_pointer __as_node() { return static_cast<__node_pointer>(__self()); }
316 template <class _Tp, class _VoidPtr>
317 struct __list_node : public __list_node_base<_Tp, _VoidPtr> {
318 // We allow starting the lifetime of nodes without initializing the value held by the node,
319 // since that is handled by the list itself in order to be allocator-aware.
320 # ifndef _LIBCPP_CXX03_LANG
328 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
332 _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)];
335 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); }
338 typedef __list_node_base<_Tp, _VoidPtr> __base;
339 typedef typename __base::__base_pointer __base_pointer;
341 _LIBCPP_HIDE_FROM_ABI explicit __list_node(__base_pointer __prev, __base_pointer __next) : __base(__prev, __next) {}
342 _LIBCPP_HIDE_FROM_ABI ~__list_node() {}
344 _LIBCPP_HIDE_FROM_ABI __base_pointer __as_link() { return __base::__self(); }
347 template <class _Tp, class _Alloc = allocator<_Tp> >
348 class _LIBCPP_TEMPLATE_VIS list;
349 template <class _Tp, class _Alloc>
351 template <class _Tp, class _VoidPtr>
352 class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
354 template <class _Tp, class _VoidPtr>
355 class _LIBCPP_TEMPLATE_VIS __list_iterator {
356 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
357 typedef typename _NodeTraits::__base_pointer __base_pointer;
359 __base_pointer __ptr_;
361 _LIBCPP_HIDE_FROM_ABI explicit __list_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
363 template <class, class>
365 template <class, class>
366 friend class __list_imp;
367 template <class, class>
368 friend class __list_const_iterator;
371 typedef bidirectional_iterator_tag iterator_category;
372 typedef _Tp value_type;
373 typedef value_type& reference;
374 typedef __rebind_pointer_t<_VoidPtr, value_type> pointer;
375 typedef typename pointer_traits<pointer>::difference_type difference_type;
377 _LIBCPP_HIDE_FROM_ABI __list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
379 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __ptr_->__as_node()->__get_value(); }
380 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
381 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
384 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator++() {
385 __ptr_ = __ptr_->__next_;
388 _LIBCPP_HIDE_FROM_ABI __list_iterator operator++(int) {
389 __list_iterator __t(*this);
394 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator--() {
395 __ptr_ = __ptr_->__prev_;
398 _LIBCPP_HIDE_FROM_ABI __list_iterator operator--(int) {
399 __list_iterator __t(*this);
404 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __list_iterator& __x, const __list_iterator& __y) {
405 return __x.__ptr_ == __y.__ptr_;
407 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __list_iterator& __x, const __list_iterator& __y) {
408 return !(__x == __y);
412 template <class _Tp, class _VoidPtr>
413 class _LIBCPP_TEMPLATE_VIS __list_const_iterator {
414 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
415 typedef typename _NodeTraits::__base_pointer __base_pointer;
417 __base_pointer __ptr_;
419 _LIBCPP_HIDE_FROM_ABI explicit __list_const_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
421 template <class, class>
423 template <class, class>
424 friend class __list_imp;
427 typedef bidirectional_iterator_tag iterator_category;
428 typedef _Tp value_type;
429 typedef const value_type& reference;
430 typedef __rebind_pointer_t<_VoidPtr, const value_type> pointer;
431 typedef typename pointer_traits<pointer>::difference_type difference_type;
433 _LIBCPP_HIDE_FROM_ABI __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
434 _LIBCPP_HIDE_FROM_ABI __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
435 : __ptr_(__p.__ptr_) {}
437 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __ptr_->__as_node()->__get_value(); }
438 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
439 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
442 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator++() {
443 __ptr_ = __ptr_->__next_;
446 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator++(int) {
447 __list_const_iterator __t(*this);
452 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator--() {
453 __ptr_ = __ptr_->__prev_;
456 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator--(int) {
457 __list_const_iterator __t(*this);
462 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) {
463 return __x.__ptr_ == __y.__ptr_;
465 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) {
466 return !(__x == __y);
470 template <class _Tp, class _Alloc>
473 __list_imp(const __list_imp&) = delete;
474 __list_imp& operator=(const __list_imp&) = delete;
476 typedef _Alloc allocator_type;
477 typedef allocator_traits<allocator_type> __alloc_traits;
478 typedef typename __alloc_traits::size_type size_type;
481 typedef _Tp value_type;
482 typedef typename __alloc_traits::void_pointer __void_pointer;
483 typedef __list_iterator<value_type, __void_pointer> iterator;
484 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
485 typedef __list_node_base<value_type, __void_pointer> __node_base;
486 typedef __list_node<value_type, __void_pointer> __node_type;
487 typedef __rebind_alloc<__alloc_traits, __node_type> __node_allocator;
488 typedef allocator_traits<__node_allocator> __node_alloc_traits;
489 typedef typename __node_alloc_traits::pointer __node_pointer;
490 typedef typename __node_alloc_traits::pointer __node_const_pointer;
491 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
492 typedef typename __node_pointer_traits::__base_pointer __base_pointer;
493 typedef __base_pointer __link_const_pointer;
494 typedef typename __alloc_traits::pointer pointer;
495 typedef typename __alloc_traits::const_pointer const_pointer;
496 typedef typename __alloc_traits::difference_type difference_type;
498 typedef __rebind_alloc<__alloc_traits, __node_base> __node_base_allocator;
499 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
500 static_assert(!is_same<allocator_type, __node_allocator>::value,
501 "internal allocator type must differ from user-specified type; otherwise overload resolution breaks");
504 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, __node_allocator, __node_alloc_);
506 _LIBCPP_HIDE_FROM_ABI __base_pointer __end_as_link() const _NOEXCEPT {
507 return __node_pointer_traits::__unsafe_link_pointer_cast(const_cast<__node_base&>(__end_).__self());
510 _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT {
511 return __node_alloc_traits::max_size(__node_alloc_);
513 _LIBCPP_HIDE_FROM_ABI static void __unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT;
515 _LIBCPP_HIDE_FROM_ABI __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
516 _LIBCPP_HIDE_FROM_ABI __list_imp(const allocator_type& __a);
517 _LIBCPP_HIDE_FROM_ABI __list_imp(const __node_allocator& __a);
518 # ifndef _LIBCPP_CXX03_LANG
519 _LIBCPP_HIDE_FROM_ABI __list_imp(__node_allocator&& __a) _NOEXCEPT;
521 _LIBCPP_HIDE_FROM_ABI ~__list_imp();
522 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
523 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
525 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__end_.__next_); }
526 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__end_.__next_); }
527 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_as_link()); }
528 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_as_link()); }
530 _LIBCPP_HIDE_FROM_ABI void swap(__list_imp& __c)
531 # if _LIBCPP_STD_VER >= 14
534 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
537 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c) {
539 __c, integral_constant<bool, __node_alloc_traits::propagate_on_container_copy_assignment::value>());
542 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c)
543 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_move_assignment::value ||
544 is_nothrow_move_assignable<__node_allocator>::value) {
546 __c, integral_constant<bool, __node_alloc_traits::propagate_on_container_move_assignment::value>());
549 template <class... _Args>
550 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__base_pointer __prev, __base_pointer __next, _Args&&... __args) {
551 __allocation_guard<__node_allocator> __guard(__node_alloc_, 1);
552 // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
553 // held inside the node, since we need to use the allocator's construct() method for that.
555 // We don't use the allocator's construct() method to construct the node itself since the
556 // Cpp17FooInsertable named requirements don't require the allocator's construct() method
557 // to work on anything other than the value_type.
558 std::__construct_at(std::addressof(*__guard.__get()), __prev, __next);
560 // Now construct the value_type using the allocator's construct() method.
561 __node_alloc_traits::construct(
562 __node_alloc_, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
563 return __guard.__release_ptr();
566 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
567 // For the same reason as above, we use the allocator's destroy() method for the value_type,
568 // but not for the node itself.
569 __node_alloc_traits::destroy(__node_alloc_, std::addressof(__node->__get_value()));
570 std::__destroy_at(std::addressof(*__node));
571 __node_alloc_traits::deallocate(__node_alloc_, __node, 1);
575 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c, true_type) {
576 if (__node_alloc_ != __c.__node_alloc_)
578 __node_alloc_ = __c.__node_alloc_;
581 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp&, false_type) {}
583 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c, true_type)
584 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {
585 __node_alloc_ = std::move(__c.__node_alloc_);
588 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {}
591 // Unlink nodes [__f, __l]
592 template <class _Tp, class _Alloc>
593 inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT {
594 __f->__prev_->__next_ = __l->__next_;
595 __l->__next_->__prev_ = __f->__prev_;
598 template <class _Tp, class _Alloc>
599 inline __list_imp<_Tp, _Alloc>::__list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
602 template <class _Tp, class _Alloc>
603 inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
604 : __size_(0), __node_alloc_(__node_allocator(__a)) {}
606 template <class _Tp, class _Alloc>
607 inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_(0), __node_alloc_(__a) {}
609 # ifndef _LIBCPP_CXX03_LANG
610 template <class _Tp, class _Alloc>
611 inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
613 __node_alloc_(std::move(__a)) {}
616 template <class _Tp, class _Alloc>
617 __list_imp<_Tp, _Alloc>::~__list_imp() {
621 template <class _Tp, class _Alloc>
622 void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
624 __base_pointer __f = __end_.__next_;
625 __base_pointer __l = __end_as_link();
626 __unlink_nodes(__f, __l->__prev_);
629 __node_pointer __np = __f->__as_node();
636 template <class _Tp, class _Alloc>
637 void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
638 # if _LIBCPP_STD_VER >= 14
641 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
644 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
645 __alloc_traits::propagate_on_container_swap::value || this->__node_alloc_ == __c.__node_alloc_,
646 "list::swap: Either propagate_on_container_swap must be true"
647 " or the allocators must compare equal");
649 std::__swap_allocator(__node_alloc_, __c.__node_alloc_);
650 swap(__size_, __c.__size_);
651 swap(__end_, __c.__end_);
653 __end_.__next_ = __end_.__prev_ = __end_as_link();
655 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
656 if (__c.__size_ == 0)
657 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
659 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
662 template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
663 class _LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> {
664 typedef __list_imp<_Tp, _Alloc> __base;
665 typedef typename __base::__node_type __node_type;
666 typedef typename __base::__node_allocator __node_allocator;
667 typedef typename __base::__node_pointer __node_pointer;
668 typedef typename __base::__node_alloc_traits __node_alloc_traits;
669 typedef typename __base::__node_base __node_base;
670 typedef typename __base::__node_base_pointer __node_base_pointer;
671 typedef typename __base::__base_pointer __base_pointer;
674 typedef _Tp value_type;
675 typedef _Alloc allocator_type;
676 static_assert(__check_valid_allocator<allocator_type>::value);
677 static_assert(is_same<value_type, typename allocator_type::value_type>::value,
678 "Allocator::value_type must be same type as value_type");
679 typedef value_type& reference;
680 typedef const value_type& const_reference;
681 typedef typename __base::pointer pointer;
682 typedef typename __base::const_pointer const_pointer;
683 typedef typename __base::size_type size_type;
684 typedef typename __base::difference_type difference_type;
685 typedef typename __base::iterator iterator;
686 typedef typename __base::const_iterator const_iterator;
687 typedef std::reverse_iterator<iterator> reverse_iterator;
688 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
689 # if _LIBCPP_STD_VER >= 20
690 typedef size_type __remove_return_type;
692 typedef void __remove_return_type;
695 _LIBCPP_HIDE_FROM_ABI list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {}
696 _LIBCPP_HIDE_FROM_ABI explicit list(const allocator_type& __a) : __base(__a) {}
697 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n);
698 # if _LIBCPP_STD_VER >= 14
699 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
701 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
702 template <__enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
703 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x, const allocator_type& __a) : __base(__a) {
704 for (; __n > 0; --__n)
708 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
709 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l);
711 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
712 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l, const allocator_type& __a);
714 # if _LIBCPP_STD_VER >= 23
715 template <_ContainerCompatibleRange<_Tp> _Range>
716 _LIBCPP_HIDE_FROM_ABI list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
718 prepend_range(std::forward<_Range>(__range));
722 _LIBCPP_HIDE_FROM_ABI list(const list& __c);
723 _LIBCPP_HIDE_FROM_ABI list(const list& __c, const __type_identity_t<allocator_type>& __a);
724 _LIBCPP_HIDE_FROM_ABI list& operator=(const list& __c);
725 # ifndef _LIBCPP_CXX03_LANG
726 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il);
727 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il, const allocator_type& __a);
729 _LIBCPP_HIDE_FROM_ABI list(list&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
730 _LIBCPP_HIDE_FROM_ABI list(list&& __c, const __type_identity_t<allocator_type>& __a);
731 _LIBCPP_HIDE_FROM_ABI list& operator=(list&& __c)
732 _NOEXCEPT_(__node_alloc_traits::propagate_on_container_move_assignment::value&&
733 is_nothrow_move_assignable<__node_allocator>::value);
735 _LIBCPP_HIDE_FROM_ABI list& operator=(initializer_list<value_type> __il) {
736 assign(__il.begin(), __il.end());
740 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
741 # endif // _LIBCPP_CXX03_LANG
743 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
744 _LIBCPP_HIDE_FROM_ABI void assign(_InpIter __f, _InpIter __l);
746 # if _LIBCPP_STD_VER >= 23
747 template <_ContainerCompatibleRange<_Tp> _Range>
748 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
749 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
753 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
755 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
757 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return this->__size_; }
758 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __base::empty(); }
759 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
760 return std::min<size_type>(this->__node_alloc_max_size(), numeric_limits<difference_type >::max());
763 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __base::begin(); }
764 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __base::begin(); }
765 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __base::end(); }
766 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __base::end(); }
767 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __base::begin(); }
768 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __base::end(); }
770 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
771 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
772 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
773 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
774 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
775 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
777 _LIBCPP_HIDE_FROM_ABI reference front() {
778 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
779 return __base::__end_.__next_->__as_node()->__get_value();
781 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
782 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
783 return __base::__end_.__next_->__as_node()->__get_value();
785 _LIBCPP_HIDE_FROM_ABI reference back() {
786 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
787 return __base::__end_.__prev_->__as_node()->__get_value();
789 _LIBCPP_HIDE_FROM_ABI const_reference back() const {
790 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
791 return __base::__end_.__prev_->__as_node()->__get_value();
794 # ifndef _LIBCPP_CXX03_LANG
795 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
796 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
798 # if _LIBCPP_STD_VER >= 23
799 template <_ContainerCompatibleRange<_Tp> _Range>
800 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
801 insert_range(begin(), std::forward<_Range>(__range));
804 template <_ContainerCompatibleRange<_Tp> _Range>
805 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
806 insert_range(end(), std::forward<_Range>(__range));
810 template <class... _Args>
811 # if _LIBCPP_STD_VER >= 17
812 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
814 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
816 template <class... _Args>
817 # if _LIBCPP_STD_VER >= 17
818 _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
820 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
822 template <class... _Args>
823 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
825 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x);
827 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
828 return insert(__p, __il.begin(), __il.end());
830 # endif // _LIBCPP_CXX03_LANG
832 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __x);
833 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
835 # ifndef _LIBCPP_CXX03_LANG
836 template <class _Arg>
837 _LIBCPP_HIDE_FROM_ABI void __emplace_back(_Arg&& __arg) {
838 emplace_back(std::forward<_Arg>(__arg));
841 _LIBCPP_HIDE_FROM_ABI void __emplace_back(value_type const& __arg) { push_back(__arg); }
844 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x);
845 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __x);
847 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
848 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InpIter __f, _InpIter __l);
850 # if _LIBCPP_STD_VER >= 23
851 template <_ContainerCompatibleRange<_Tp> _Range>
852 _LIBCPP_HIDE_FROM_ABI iterator insert_range(const_iterator __position, _Range&& __range) {
853 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
857 _LIBCPP_HIDE_FROM_ABI void swap(list& __c)
858 # if _LIBCPP_STD_VER >= 14
861 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)
866 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
868 _LIBCPP_HIDE_FROM_ABI void pop_front();
869 _LIBCPP_HIDE_FROM_ABI void pop_back();
871 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
872 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
874 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
875 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __x);
877 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c);
878 # ifndef _LIBCPP_CXX03_LANG
879 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c) { splice(__p, __c); }
880 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __i) { splice(__p, __c, __i); }
881 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {
882 splice(__p, __c, __f, __l);
885 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __i);
886 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
888 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __x);
889 template <class _Pred>
890 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Pred __pred);
891 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
892 template <class _BinaryPred>
893 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPred __binary_pred);
894 _LIBCPP_HIDE_FROM_ABI void merge(list& __c);
895 # ifndef _LIBCPP_CXX03_LANG
896 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c) { merge(__c); }
898 template <class _Comp>
899 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c, _Comp __comp) {
903 template <class _Comp>
904 _LIBCPP_HIDE_FROM_ABI void merge(list& __c, _Comp __comp);
906 _LIBCPP_HIDE_FROM_ABI void sort();
907 template <class _Comp>
908 _LIBCPP_HIDE_FROM_ABI void sort(_Comp __comp);
910 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
912 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
915 template <class _Iterator, class _Sentinel>
916 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __f, _Sentinel __l);
918 template <class _Iterator, class _Sentinel>
919 _LIBCPP_HIDE_FROM_ABI iterator __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
921 _LIBCPP_HIDE_FROM_ABI static void __link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l);
922 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_front(__base_pointer __f, __base_pointer __l);
923 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_back(__base_pointer __f, __base_pointer __l);
924 _LIBCPP_HIDE_FROM_ABI iterator __iterator(size_type __n);
925 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
926 template <class _Comp>
927 _LIBCPP_HIDDEN static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
929 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, true_type)
930 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
931 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, false_type);
934 # if _LIBCPP_STD_VER >= 17
935 template <class _InputIterator,
936 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
937 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
938 class = enable_if_t<__is_allocator<_Alloc>::value> >
939 list(_InputIterator, _InputIterator) -> list<__iter_value_type<_InputIterator>, _Alloc>;
941 template <class _InputIterator,
943 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
944 class = enable_if_t<__is_allocator<_Alloc>::value> >
945 list(_InputIterator, _InputIterator, _Alloc) -> list<__iter_value_type<_InputIterator>, _Alloc>;
948 # if _LIBCPP_STD_VER >= 23
949 template <ranges::input_range _Range,
950 class _Alloc = allocator<ranges::range_value_t<_Range>>,
951 class = enable_if_t<__is_allocator<_Alloc>::value> >
952 list(from_range_t, _Range&&, _Alloc = _Alloc()) -> list<ranges::range_value_t<_Range>, _Alloc>;
955 // Link in nodes [__f, __l] just prior to __p
956 template <class _Tp, class _Alloc>
957 inline void list<_Tp, _Alloc>::__link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l) {
958 __p->__prev_->__next_ = __f;
959 __f->__prev_ = __p->__prev_;
964 // Link in nodes [__f, __l] at the front of the list
965 template <class _Tp, class _Alloc>
966 inline void list<_Tp, _Alloc>::__link_nodes_at_front(__base_pointer __f, __base_pointer __l) {
967 __f->__prev_ = __base::__end_as_link();
968 __l->__next_ = __base::__end_.__next_;
969 __l->__next_->__prev_ = __l;
970 __base::__end_.__next_ = __f;
973 // Link in nodes [__f, __l] at the back of the list
974 template <class _Tp, class _Alloc>
975 inline void list<_Tp, _Alloc>::__link_nodes_at_back(__base_pointer __f, __base_pointer __l) {
976 __l->__next_ = __base::__end_as_link();
977 __f->__prev_ = __base::__end_.__prev_;
978 __f->__prev_->__next_ = __f;
979 __base::__end_.__prev_ = __l;
982 template <class _Tp, class _Alloc>
983 inline typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__iterator(size_type __n) {
984 return __n <= this->__size_ / 2 ? std::next(begin(), __n) : std::prev(end(), this->__size_ - __n);
987 template <class _Tp, class _Alloc>
988 list<_Tp, _Alloc>::list(size_type __n) {
989 for (; __n > 0; --__n)
990 # ifndef _LIBCPP_CXX03_LANG
993 push_back(value_type());
997 # if _LIBCPP_STD_VER >= 14
998 template <class _Tp, class _Alloc>
999 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : __base(__a) {
1000 for (; __n > 0; --__n)
1005 template <class _Tp, class _Alloc>
1006 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) {
1007 for (; __n > 0; --__n)
1011 template <class _Tp, class _Alloc>
1012 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1013 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l) {
1014 for (; __f != __l; ++__f)
1015 __emplace_back(*__f);
1018 template <class _Tp, class _Alloc>
1019 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1020 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a) : __base(__a) {
1021 for (; __f != __l; ++__f)
1022 __emplace_back(*__f);
1025 template <class _Tp, class _Alloc>
1026 list<_Tp, _Alloc>::list(const list& __c)
1027 : __base(__node_alloc_traits::select_on_container_copy_construction(__c.__node_alloc_)) {
1028 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1032 template <class _Tp, class _Alloc>
1033 list<_Tp, _Alloc>::list(const list& __c, const __type_identity_t<allocator_type>& __a) : __base(__a) {
1034 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1038 # ifndef _LIBCPP_CXX03_LANG
1040 template <class _Tp, class _Alloc>
1041 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) : __base(__a) {
1042 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i)
1046 template <class _Tp, class _Alloc>
1047 list<_Tp, _Alloc>::list(initializer_list<value_type> __il) {
1048 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), __e = __il.end(); __i != __e; ++__i)
1052 template <class _Tp, class _Alloc>
1053 inline list<_Tp, _Alloc>::list(list&& __c) noexcept(is_nothrow_move_constructible<__node_allocator>::value)
1054 : __base(std::move(__c.__node_alloc_)) {
1058 template <class _Tp, class _Alloc>
1059 inline list<_Tp, _Alloc>::list(list&& __c, const __type_identity_t<allocator_type>& __a) : __base(__a) {
1060 if (__a == __c.get_allocator())
1063 typedef move_iterator<iterator> _Ip;
1064 assign(_Ip(__c.begin()), _Ip(__c.end()));
1068 template <class _Tp, class _Alloc>
1069 inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(list&& __c) noexcept(
1070 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1071 is_nothrow_move_assignable<__node_allocator>::value) {
1072 __move_assign(__c, integral_constant<bool, __node_alloc_traits::propagate_on_container_move_assignment::value>());
1076 template <class _Tp, class _Alloc>
1077 void list<_Tp, _Alloc>::__move_assign(list& __c, false_type) {
1078 if (this->__node_alloc_ != __c.__node_alloc_) {
1079 typedef move_iterator<iterator> _Ip;
1080 assign(_Ip(__c.begin()), _Ip(__c.end()));
1082 __move_assign(__c, true_type());
1085 template <class _Tp, class _Alloc>
1086 void list<_Tp, _Alloc>::__move_assign(list& __c,
1087 true_type) noexcept(is_nothrow_move_assignable<__node_allocator>::value) {
1089 __base::__move_assign_alloc(__c);
1093 # endif // _LIBCPP_CXX03_LANG
1095 template <class _Tp, class _Alloc>
1096 inline list<_Tp, _Alloc>& list<_Tp, _Alloc>::operator=(const list& __c) {
1097 if (this != std::addressof(__c)) {
1098 __base::__copy_assign_alloc(__c);
1099 assign(__c.begin(), __c.end());
1104 template <class _Tp, class _Alloc>
1105 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1106 void list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l) {
1107 __assign_with_sentinel(__f, __l);
1110 template <class _Tp, class _Alloc>
1111 template <class _Iterator, class _Sentinel>
1112 _LIBCPP_HIDE_FROM_ABI void list<_Tp, _Alloc>::__assign_with_sentinel(_Iterator __f, _Sentinel __l) {
1113 iterator __i = begin();
1114 iterator __e = end();
1115 for (; __f != __l && __i != __e; ++__f, (void)++__i)
1118 __insert_with_sentinel(__e, std::move(__f), std::move(__l));
1123 template <class _Tp, class _Alloc>
1124 void list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) {
1125 iterator __i = begin();
1126 iterator __e = end();
1127 for (; __n > 0 && __i != __e; --__n, (void)++__i)
1130 insert(__e, __n, __x);
1135 template <class _Tp, class _Alloc>
1136 inline _Alloc list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT {
1137 return allocator_type(this->__node_alloc_);
1140 template <class _Tp, class _Alloc>
1141 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) {
1142 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1143 __link_nodes(__p.__ptr_, __node->__as_link(), __node->__as_link());
1145 return iterator(__node->__as_link());
1148 template <class _Tp, class _Alloc>
1149 typename list<_Tp, _Alloc>::iterator
1150 list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) {
1151 iterator __r(__p.__ptr_);
1154 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1156 __r = iterator(__node->__as_link());
1158 # if _LIBCPP_HAS_EXCEPTIONS
1160 # endif // _LIBCPP_HAS_EXCEPTIONS
1161 for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
1162 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
1164 # if _LIBCPP_HAS_EXCEPTIONS
1167 __base_pointer __prev = __e.__ptr_->__prev_;
1168 __node_pointer __current = __e.__ptr_->__as_node();
1169 this->__delete_node(__current);
1172 __e = iterator(__prev);
1176 # endif // _LIBCPP_HAS_EXCEPTIONS
1177 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1178 this->__size_ += __ds;
1183 template <class _Tp, class _Alloc>
1184 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> >
1185 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l) {
1186 return __insert_with_sentinel(__p, __f, __l);
1189 template <class _Tp, class _Alloc>
1190 template <class _Iterator, class _Sentinel>
1191 _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Alloc>::iterator
1192 list<_Tp, _Alloc>::__insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l) {
1193 iterator __r(__p.__ptr_);
1196 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, *__f);
1198 __r = iterator(__node->__as_link());
1200 # if _LIBCPP_HAS_EXCEPTIONS
1202 # endif // _LIBCPP_HAS_EXCEPTIONS
1203 for (++__f; __f != __l; ++__f, (void)++__e, ++__ds) {
1204 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, *__f)->__as_link();
1206 # if _LIBCPP_HAS_EXCEPTIONS
1209 __base_pointer __prev = __e.__ptr_->__prev_;
1210 __node_pointer __current = __e.__ptr_->__as_node();
1211 this->__delete_node(__current);
1214 __e = iterator(__prev);
1218 # endif // _LIBCPP_HAS_EXCEPTIONS
1219 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1220 this->__size_ += __ds;
1225 template <class _Tp, class _Alloc>
1226 void list<_Tp, _Alloc>::push_front(const value_type& __x) {
1227 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1228 __base_pointer __nl = __node->__as_link();
1229 __link_nodes_at_front(__nl, __nl);
1233 template <class _Tp, class _Alloc>
1234 void list<_Tp, _Alloc>::push_back(const value_type& __x) {
1235 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1236 __base_pointer __nl = __node->__as_link();
1237 __link_nodes_at_back(__nl, __nl);
1241 # ifndef _LIBCPP_CXX03_LANG
1243 template <class _Tp, class _Alloc>
1244 void list<_Tp, _Alloc>::push_front(value_type&& __x) {
1245 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
1246 __base_pointer __nl = __node->__as_link();
1247 __link_nodes_at_front(__nl, __nl);
1251 template <class _Tp, class _Alloc>
1252 void list<_Tp, _Alloc>::push_back(value_type&& __x) {
1253 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
1254 __base_pointer __nl = __node->__as_link();
1255 __link_nodes_at_back(__nl, __nl);
1259 template <class _Tp, class _Alloc>
1260 template <class... _Args>
1261 # if _LIBCPP_STD_VER >= 17
1262 typename list<_Tp, _Alloc>::reference
1266 list<_Tp, _Alloc>::emplace_front(_Args&&... __args) {
1267 __node_pointer __node =
1268 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
1269 __base_pointer __nl = __node->__as_link();
1270 __link_nodes_at_front(__nl, __nl);
1272 # if _LIBCPP_STD_VER >= 17
1273 return __node->__get_value();
1277 template <class _Tp, class _Alloc>
1278 template <class... _Args>
1279 # if _LIBCPP_STD_VER >= 17
1280 typename list<_Tp, _Alloc>::reference
1284 list<_Tp, _Alloc>::emplace_back(_Args&&... __args) {
1285 __node_pointer __node =
1286 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
1287 __base_pointer __nl = __node->__as_link();
1288 __link_nodes_at_back(__nl, __nl);
1290 # if _LIBCPP_STD_VER >= 17
1291 return __node->__get_value();
1295 template <class _Tp, class _Alloc>
1296 template <class... _Args>
1297 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) {
1298 __node_pointer __node =
1299 this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::forward<_Args>(__args)...);
1300 __base_pointer __nl = __node->__as_link();
1301 __link_nodes(__p.__ptr_, __nl, __nl);
1303 return iterator(__nl);
1306 template <class _Tp, class _Alloc>
1307 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) {
1308 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, std::move(__x));
1309 __base_pointer __nl = __node->__as_link();
1310 __link_nodes(__p.__ptr_, __nl, __nl);
1312 return iterator(__nl);
1315 # endif // _LIBCPP_CXX03_LANG
1317 template <class _Tp, class _Alloc>
1318 void list<_Tp, _Alloc>::pop_front() {
1319 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_front() called with empty list");
1320 __base_pointer __n = __base::__end_.__next_;
1321 __base::__unlink_nodes(__n, __n);
1323 this->__delete_node(__n->__as_node());
1326 template <class _Tp, class _Alloc>
1327 void list<_Tp, _Alloc>::pop_back() {
1328 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::pop_back() called on an empty list");
1329 __base_pointer __n = __base::__end_.__prev_;
1330 __base::__unlink_nodes(__n, __n);
1332 this->__delete_node(__n->__as_node());
1335 template <class _Tp, class _Alloc>
1336 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __p) {
1337 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(__p != end(), "list::erase(iterator) called with a non-dereferenceable iterator");
1338 __base_pointer __n = __p.__ptr_;
1339 __base_pointer __r = __n->__next_;
1340 __base::__unlink_nodes(__n, __n);
1342 this->__delete_node(__n->__as_node());
1343 return iterator(__r);
1346 template <class _Tp, class _Alloc>
1347 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) {
1349 __base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1350 while (__f != __l) {
1351 __base_pointer __n = __f.__ptr_;
1354 this->__delete_node(__n->__as_node());
1357 return iterator(__l.__ptr_);
1360 template <class _Tp, class _Alloc>
1361 void list<_Tp, _Alloc>::resize(size_type __n) {
1362 if (__n < this->__size_)
1363 erase(__iterator(__n), end());
1364 else if (__n > this->__size_) {
1365 __n -= this->__size_;
1367 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr);
1369 iterator __r = iterator(__node->__as_link());
1371 # if _LIBCPP_HAS_EXCEPTIONS
1373 # endif // _LIBCPP_HAS_EXCEPTIONS
1374 for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
1375 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr)->__as_link();
1377 # if _LIBCPP_HAS_EXCEPTIONS
1380 __base_pointer __prev = __e.__ptr_->__prev_;
1381 __node_pointer __current = __e.__ptr_->__as_node();
1382 this->__delete_node(__current);
1385 __e = iterator(__prev);
1389 # endif // _LIBCPP_HAS_EXCEPTIONS
1390 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1391 this->__size_ += __ds;
1395 template <class _Tp, class _Alloc>
1396 void list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) {
1397 if (__n < this->__size_)
1398 erase(__iterator(__n), end());
1399 else if (__n > this->__size_) {
1400 __n -= this->__size_;
1402 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1404 __base_pointer __nl = __node->__as_link();
1405 iterator __r = iterator(__nl);
1407 # if _LIBCPP_HAS_EXCEPTIONS
1409 # endif // _LIBCPP_HAS_EXCEPTIONS
1410 for (--__n; __n != 0; --__n, (void)++__e, ++__ds) {
1411 __e.__ptr_->__next_ = this->__create_node(/* prev = */ __e.__ptr_, /* next = */ nullptr, __x)->__as_link();
1413 # if _LIBCPP_HAS_EXCEPTIONS
1416 __base_pointer __prev = __e.__ptr_->__prev_;
1417 __node_pointer __current = __e.__ptr_->__as_node();
1418 this->__delete_node(__current);
1421 __e = iterator(__prev);
1425 # endif // _LIBCPP_HAS_EXCEPTIONS
1426 __link_nodes(__base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1427 this->__size_ += __ds;
1431 template <class _Tp, class _Alloc>
1432 void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) {
1433 _LIBCPP_ASSERT_VALID_INPUT_RANGE(
1434 this != std::addressof(__c), "list::splice(iterator, list) called with this == &list");
1436 __base_pointer __f = __c.__end_.__next_;
1437 __base_pointer __l = __c.__end_.__prev_;
1438 __base::__unlink_nodes(__f, __l);
1439 __link_nodes(__p.__ptr_, __f, __l);
1440 this->__size_ += __c.__size_;
1445 template <class _Tp, class _Alloc>
1446 void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) {
1447 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) {
1448 __base_pointer __f = __i.__ptr_;
1449 __base::__unlink_nodes(__f, __f);
1450 __link_nodes(__p.__ptr_, __f, __f);
1456 template <class _Tp, class _Alloc>
1457 void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) {
1459 __base_pointer __first = __f.__ptr_;
1461 __base_pointer __last = __l.__ptr_;
1462 if (this != std::addressof(__c)) {
1463 size_type __s = std::distance(__f, __l) + 1;
1465 this->__size_ += __s;
1467 __base::__unlink_nodes(__first, __last);
1468 __link_nodes(__p.__ptr_, __first, __last);
1472 template <class _Tp, class _Alloc>
1473 typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove(const value_type& __x) {
1474 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
1475 for (const_iterator __i = begin(), __e = end(); __i != __e;) {
1477 const_iterator __j = std::next(__i);
1478 for (; __j != __e && *__j == __x; ++__j)
1480 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
1488 return (__remove_return_type)__deleted_nodes.size();
1491 template <class _Tp, class _Alloc>
1492 template <class _Pred>
1493 typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::remove_if(_Pred __pred) {
1494 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
1495 for (iterator __i = begin(), __e = end(); __i != __e;) {
1497 iterator __j = std::next(__i);
1498 for (; __j != __e && __pred(*__j); ++__j)
1500 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
1508 return (__remove_return_type)__deleted_nodes.size();
1511 template <class _Tp, class _Alloc>
1512 template <class _BinaryPred>
1513 typename list<_Tp, _Alloc>::__remove_return_type list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) {
1514 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
1515 for (iterator __i = begin(), __e = end(); __i != __e;) {
1516 iterator __j = std::next(__i);
1517 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
1520 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
1525 return (__remove_return_type)__deleted_nodes.size();
1528 template <class _Tp, class _Alloc>
1529 inline void list<_Tp, _Alloc>::merge(list& __c) {
1530 merge(__c, __less<>());
1533 template <class _Tp, class _Alloc>
1534 template <class _Comp>
1535 void list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) {
1536 if (this != std::addressof(__c)) {
1537 iterator __f1 = begin();
1538 iterator __e1 = end();
1539 iterator __f2 = __c.begin();
1540 iterator __e2 = __c.end();
1541 while (__f1 != __e1 && __f2 != __e2) {
1542 if (__comp(*__f2, *__f1)) {
1544 iterator __m2 = std::next(__f2);
1545 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void)++__ds)
1547 this->__size_ += __ds;
1548 __c.__size_ -= __ds;
1549 __base_pointer __f = __f2.__ptr_;
1550 __base_pointer __l = __m2.__ptr_->__prev_;
1552 __base::__unlink_nodes(__f, __l);
1553 __m2 = std::next(__f1);
1554 __link_nodes(__f1.__ptr_, __f, __l);
1563 template <class _Tp, class _Alloc>
1564 inline void list<_Tp, _Alloc>::sort() {
1568 template <class _Tp, class _Alloc>
1569 template <class _Comp>
1570 inline void list<_Tp, _Alloc>::sort(_Comp __comp) {
1571 __sort(begin(), end(), this->__size_, __comp);
1574 template <class _Tp, class _Alloc>
1575 template <class _Comp>
1576 typename list<_Tp, _Alloc>::iterator
1577 list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) {
1583 if (__comp(*--__e2, *__f1)) {
1584 __base_pointer __f = __e2.__ptr_;
1585 __base::__unlink_nodes(__f, __f);
1586 __link_nodes(__f1.__ptr_, __f, __f);
1591 size_type __n2 = __n / 2;
1592 iterator __e1 = std::next(__f1, __n2);
1593 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
1594 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
1595 if (__comp(*__f2, *__f1)) {
1596 iterator __m2 = std::next(__f2);
1597 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
1599 __base_pointer __f = __f2.__ptr_;
1600 __base_pointer __l = __m2.__ptr_->__prev_;
1603 __base::__unlink_nodes(__f, __l);
1604 __m2 = std::next(__f1);
1605 __link_nodes(__f1.__ptr_, __f, __l);
1609 while (__f1 != __e1 && __f2 != __e2) {
1610 if (__comp(*__f2, *__f1)) {
1611 iterator __m2 = std::next(__f2);
1612 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
1614 __base_pointer __f = __f2.__ptr_;
1615 __base_pointer __l = __m2.__ptr_->__prev_;
1619 __base::__unlink_nodes(__f, __l);
1620 __m2 = std::next(__f1);
1621 __link_nodes(__f1.__ptr_, __f, __l);
1629 template <class _Tp, class _Alloc>
1630 void list<_Tp, _Alloc>::reverse() _NOEXCEPT {
1631 if (this->__size_ > 1) {
1632 iterator __e = end();
1633 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) {
1634 std::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
1635 __i.__ptr_ = __i.__ptr_->__prev_;
1637 std::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
1641 template <class _Tp, class _Alloc>
1642 bool list<_Tp, _Alloc>::__invariants() const {
1643 return size() == std::distance(begin(), end());
1646 template <class _Tp, class _Alloc>
1647 inline _LIBCPP_HIDE_FROM_ABI bool operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1648 return __x.size() == __y.size() && std::equal(__x.begin(), __x.end(), __y.begin());
1651 # if _LIBCPP_STD_VER <= 17
1653 template <class _Tp, class _Alloc>
1654 inline _LIBCPP_HIDE_FROM_ABI bool operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1655 return std::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
1658 template <class _Tp, class _Alloc>
1659 inline _LIBCPP_HIDE_FROM_ABI bool operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1660 return !(__x == __y);
1663 template <class _Tp, class _Alloc>
1664 inline _LIBCPP_HIDE_FROM_ABI bool operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1668 template <class _Tp, class _Alloc>
1669 inline _LIBCPP_HIDE_FROM_ABI bool operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1670 return !(__x < __y);
1673 template <class _Tp, class _Alloc>
1674 inline _LIBCPP_HIDE_FROM_ABI bool operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1675 return !(__y < __x);
1678 # else // _LIBCPP_STD_VER <= 17
1680 template <class _Tp, class _Allocator>
1681 _LIBCPP_HIDE_FROM_ABI __synth_three_way_result<_Tp>
1682 operator<=>(const list<_Tp, _Allocator>& __x, const list<_Tp, _Allocator>& __y) {
1683 return std::lexicographical_compare_three_way(__x.begin(), __x.end(), __y.begin(), __y.end(), std::__synth_three_way);
1686 # endif // _LIBCPP_STD_VER <= 17
1688 template <class _Tp, class _Alloc>
1689 inline _LIBCPP_HIDE_FROM_ABI void swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
1690 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) {
1694 # if _LIBCPP_STD_VER >= 20
1695 template <class _Tp, class _Allocator, class _Predicate>
1696 inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
1697 erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred) {
1698 return __c.remove_if(__pred);
1701 template <class _Tp, class _Allocator, class _Up>
1702 inline _LIBCPP_HIDE_FROM_ABI typename list<_Tp, _Allocator>::size_type
1703 erase(list<_Tp, _Allocator>& __c, const _Up& __v) {
1704 return std::erase_if(__c, [&](auto& __elem) { return __elem == __v; });
1708 inline constexpr bool __format::__enable_insertable<std::list<char>> = true;
1709 # if _LIBCPP_HAS_WIDE_CHARACTERS
1711 inline constexpr bool __format::__enable_insertable<std::list<wchar_t>> = true;
1714 # endif // _LIBCPP_STD_VER >= 20
1716 template <class _Tp, class _Allocator>
1717 struct __container_traits<list<_Tp, _Allocator> > {
1718 // http://eel.is/c++draft/container.reqmts
1719 // Unless otherwise specified (see [associative.reqmts.except], [unord.req.except], [deque.modifiers],
1720 // [inplace.vector.modifiers], and [vector.modifiers]) all container types defined in this Clause meet the following
1721 // additional requirements:
1722 // - If an exception is thrown by an insert() or emplace() function while inserting a single element, that
1723 // function has no effects.
1724 static _LIBCPP_CONSTEXPR const bool __emplacement_has_strong_exception_safety_guarantee = true;
1727 _LIBCPP_END_NAMESPACE_STD
1729 # if _LIBCPP_STD_VER >= 17
1730 _LIBCPP_BEGIN_NAMESPACE_STD
1732 template <class _ValueT>
1733 using list _LIBCPP_AVAILABILITY_PMR = std::list<_ValueT, polymorphic_allocator<_ValueT>>;
1735 _LIBCPP_END_NAMESPACE_STD
1740 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1741 # include <algorithm>
1743 # include <concepts>
1746 # include <functional>
1748 # include <iterator>
1749 # include <stdexcept>
1750 # include <type_traits>
1751 # include <typeinfo>
1753 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1755 #endif // _LIBCPP_LIST