Warning, /include/c++/v1/list is written in an unsupported language. File is not indexed.
0001 // -*- C++ -*-
0002 //===----------------------------------------------------------------------===//
0003 //
0004 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0005 // See https://llvm.org/LICENSE.txt for license information.
0006 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0007 //
0008 //===----------------------------------------------------------------------===//
0009
0010 #ifndef _LIBCPP_LIST
0011 #define _LIBCPP_LIST
0012
0013 /*
0014 list synopsis
0015
0016 namespace std
0017 {
0018
0019 template <class T, class Alloc = allocator<T> >
0020 class list
0021 {
0022 public:
0023
0024 // types:
0025 typedef T value_type;
0026 typedef Alloc allocator_type;
0027 typedef typename allocator_type::reference reference;
0028 typedef typename allocator_type::const_reference const_reference;
0029 typedef typename allocator_type::pointer pointer;
0030 typedef typename allocator_type::const_pointer const_pointer;
0031 typedef implementation-defined iterator;
0032 typedef implementation-defined const_iterator;
0033 typedef implementation-defined size_type;
0034 typedef implementation-defined difference_type;
0035 typedef reverse_iterator<iterator> reverse_iterator;
0036 typedef reverse_iterator<const_iterator> const_reverse_iterator;
0037
0038 list()
0039 noexcept(is_nothrow_default_constructible<allocator_type>::value);
0040 explicit list(const allocator_type& a);
0041 explicit list(size_type n);
0042 explicit list(size_type n, const allocator_type& a); // C++14
0043 list(size_type n, const value_type& value);
0044 list(size_type n, const value_type& value, const allocator_type& a);
0045 template <class Iter>
0046 list(Iter first, Iter last);
0047 template <class Iter>
0048 list(Iter first, Iter last, const allocator_type& a);
0049 template<container-compatible-range<T> R>
0050 list(from_range_t, R&& rg, const Allocator& = Allocator()); // C++23
0051 list(const list& x);
0052 list(const list&, const allocator_type& a);
0053 list(list&& x)
0054 noexcept(is_nothrow_move_constructible<allocator_type>::value);
0055 list(list&&, const allocator_type& a);
0056 list(initializer_list<value_type>);
0057 list(initializer_list<value_type>, const allocator_type& a);
0058
0059 ~list();
0060
0061 list& operator=(const list& x);
0062 list& operator=(list&& x)
0063 noexcept(
0064 allocator_type::propagate_on_container_move_assignment::value &&
0065 is_nothrow_move_assignable<allocator_type>::value);
0066 list& operator=(initializer_list<value_type>);
0067 template <class Iter>
0068 void assign(Iter first, Iter last);
0069 template<container-compatible-range<T> R>
0070 void assign_range(R&& rg); // C++23
0071 void assign(size_type n, const value_type& t);
0072 void assign(initializer_list<value_type>);
0073
0074 allocator_type get_allocator() const noexcept;
0075
0076 iterator begin() noexcept;
0077 const_iterator begin() const noexcept;
0078 iterator end() noexcept;
0079 const_iterator end() const noexcept;
0080 reverse_iterator rbegin() noexcept;
0081 const_reverse_iterator rbegin() const noexcept;
0082 reverse_iterator rend() noexcept;
0083 const_reverse_iterator rend() const noexcept;
0084 const_iterator cbegin() const noexcept;
0085 const_iterator cend() const noexcept;
0086 const_reverse_iterator crbegin() const noexcept;
0087 const_reverse_iterator crend() const noexcept;
0088
0089 reference front();
0090 const_reference front() const;
0091 reference back();
0092 const_reference back() const;
0093
0094 bool empty() const noexcept;
0095 size_type size() const noexcept;
0096 size_type max_size() const noexcept;
0097
0098 template <class... Args>
0099 reference emplace_front(Args&&... args); // reference in C++17
0100 void pop_front();
0101 template <class... Args>
0102 reference emplace_back(Args&&... args); // reference in C++17
0103 void pop_back();
0104 void push_front(const value_type& x);
0105 void push_front(value_type&& x);
0106 template<container-compatible-range<T> R>
0107 void prepend_range(R&& rg); // C++23
0108 void push_back(const value_type& x);
0109 void push_back(value_type&& x);
0110 template<container-compatible-range<T> R>
0111 void append_range(R&& rg); // C++23
0112 template <class... Args>
0113 iterator emplace(const_iterator position, Args&&... args);
0114 iterator insert(const_iterator position, const value_type& x);
0115 iterator insert(const_iterator position, value_type&& x);
0116 iterator insert(const_iterator position, size_type n, const value_type& x);
0117 template <class Iter>
0118 iterator insert(const_iterator position, Iter first, Iter last);
0119 template<container-compatible-range<T> R>
0120 iterator insert_range(const_iterator position, R&& rg); // C++23
0121 iterator insert(const_iterator position, initializer_list<value_type> il);
0122
0123 iterator erase(const_iterator position);
0124 iterator erase(const_iterator position, const_iterator last);
0125
0126 void resize(size_type sz);
0127 void resize(size_type sz, const value_type& c);
0128
0129 void swap(list&)
0130 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
0131 void clear() noexcept;
0132
0133 void splice(const_iterator position, list& x);
0134 void splice(const_iterator position, list&& x);
0135 void splice(const_iterator position, list& x, const_iterator i);
0136 void splice(const_iterator position, list&& x, const_iterator i);
0137 void splice(const_iterator position, list& x, const_iterator first,
0138 const_iterator last);
0139 void splice(const_iterator position, list&& x, const_iterator first,
0140 const_iterator last);
0141
0142 size_type remove(const value_type& value); // void before C++20
0143 template <class Pred>
0144 size_type remove_if(Pred pred); // void before C++20
0145 size_type unique(); // void before C++20
0146 template <class BinaryPredicate>
0147 size_type unique(BinaryPredicate binary_pred); // void before C++20
0148 void merge(list& x);
0149 void merge(list&& x);
0150 template <class Compare>
0151 void merge(list& x, Compare comp);
0152 template <class Compare>
0153 void merge(list&& x, Compare comp);
0154 void sort();
0155 template <class Compare>
0156 void sort(Compare comp);
0157 void reverse() noexcept;
0158 };
0159
0160
0161 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
0162 list(InputIterator, InputIterator, Allocator = Allocator())
0163 -> list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
0164
0165 template<ranges::input_range R, class Allocator = allocator<ranges::range_value_t<R>>>
0166 list(from_range_t, R&&, Allocator = Allocator())
0167 -> list<ranges::range_value_t<R>, Allocator>; // C++23
0168
0169 template <class T, class Alloc>
0170 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
0171 template <class T, class Alloc>
0172 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
0173 template <class T, class Alloc>
0174 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
0175 template <class T, class Alloc>
0176 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
0177 template <class T, class Alloc>
0178 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
0179 template <class T, class Alloc>
0180 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); // removed in C++20
0181 template<class T, class Allocator>
0182 synth-three-way-result<T> operator<=>(const list<T, Allocator>& x,
0183 const list<T, Allocator>& y); // since C++20
0184
0185 template <class T, class Alloc>
0186 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
0187 noexcept(noexcept(x.swap(y)));
0188
0189 template <class T, class Allocator, class U>
0190 typename list<T, Allocator>::size_type
0191 erase(list<T, Allocator>& c, const U& value); // since C++20
0192 template <class T, class Allocator, class Predicate>
0193 typename list<T, Allocator>::size_type
0194 erase_if(list<T, Allocator>& c, Predicate pred); // since C++20
0195
0196 } // std
0197
0198 */
0199
0200 #if __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
0201 # include <__cxx03/list>
0202 #else
0203 # include <__algorithm/comp.h>
0204 # include <__algorithm/equal.h>
0205 # include <__algorithm/lexicographical_compare.h>
0206 # include <__algorithm/lexicographical_compare_three_way.h>
0207 # include <__algorithm/min.h>
0208 # include <__assert>
0209 # include <__config>
0210 # include <__format/enable_insertable.h>
0211 # include <__iterator/distance.h>
0212 # include <__iterator/iterator_traits.h>
0213 # include <__iterator/move_iterator.h>
0214 # include <__iterator/next.h>
0215 # include <__iterator/prev.h>
0216 # include <__iterator/reverse_iterator.h>
0217 # include <__memory/addressof.h>
0218 # include <__memory/allocation_guard.h>
0219 # include <__memory/allocator.h>
0220 # include <__memory/allocator_traits.h>
0221 # include <__memory/compressed_pair.h>
0222 # include <__memory/construct_at.h>
0223 # include <__memory/pointer_traits.h>
0224 # include <__memory/swap_allocator.h>
0225 # include <__memory_resource/polymorphic_allocator.h>
0226 # include <__new/launder.h>
0227 # include <__ranges/access.h>
0228 # include <__ranges/concepts.h>
0229 # include <__ranges/container_compatible_range.h>
0230 # include <__ranges/from_range.h>
0231 # include <__type_traits/conditional.h>
0232 # include <__type_traits/container_traits.h>
0233 # include <__type_traits/enable_if.h>
0234 # include <__type_traits/is_allocator.h>
0235 # include <__type_traits/is_nothrow_assignable.h>
0236 # include <__type_traits/is_nothrow_constructible.h>
0237 # include <__type_traits/is_pointer.h>
0238 # include <__type_traits/is_same.h>
0239 # include <__type_traits/type_identity.h>
0240 # include <__utility/forward.h>
0241 # include <__utility/move.h>
0242 # include <__utility/swap.h>
0243 # include <cstring>
0244 # include <limits>
0245 # include <version>
0246
0247 // standard-mandated includes
0248
0249 // [iterator.range]
0250 # include <__iterator/access.h>
0251 # include <__iterator/data.h>
0252 # include <__iterator/empty.h>
0253 # include <__iterator/reverse_access.h>
0254 # include <__iterator/size.h>
0255
0256 // [list.syn]
0257 # include <compare>
0258 # include <initializer_list>
0259
0260 # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0261 # pragma GCC system_header
0262 # endif
0263
0264 _LIBCPP_PUSH_MACROS
0265 # include <__undef_macros>
0266
0267 _LIBCPP_BEGIN_NAMESPACE_STD
0268
0269 template <class _Tp, class _VoidPtr>
0270 struct __list_node;
0271 template <class _Tp, class _VoidPtr>
0272 struct __list_node_base;
0273
0274 template <class _Tp, class _VoidPtr>
0275 struct __list_node_pointer_traits {
0276 typedef __rebind_pointer_t<_VoidPtr, __list_node<_Tp, _VoidPtr> > __node_pointer;
0277 typedef __rebind_pointer_t<_VoidPtr, __list_node_base<_Tp, _VoidPtr> > __base_pointer;
0278
0279 // TODO(LLVM 22): Remove this check
0280 # ifndef _LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB
0281 static_assert(sizeof(__node_pointer) == sizeof(__node_pointer) && _LIBCPP_ALIGNOF(__base_pointer) ==
0282 _LIBCPP_ALIGNOF(__node_pointer),
0283 "It looks like you are using std::list with a fancy pointer type that thas a different representation "
0284 "depending on whether it points to a list base pointer or a list node pointer (both of which are "
0285 "implementation details of the standard library). This means that your ABI is being broken between "
0286 "LLVM 19 and LLVM 20. If you don't care about your ABI being broken, define the "
0287 "_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB macro to silence this diagnostic.");
0288 # endif
0289
0290 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__base_pointer __p) { return __p; }
0291
0292 static _LIBCPP_HIDE_FROM_ABI __base_pointer __unsafe_link_pointer_cast(__node_pointer __p) {
0293 return static_cast<__base_pointer>(static_cast<_VoidPtr>(__p));
0294 }
0295 };
0296
0297 template <class _Tp, class _VoidPtr>
0298 struct __list_node_base {
0299 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
0300 typedef typename _NodeTraits::__node_pointer __node_pointer;
0301 typedef typename _NodeTraits::__base_pointer __base_pointer;
0302
0303 __base_pointer __prev_;
0304 __base_pointer __next_;
0305
0306 _LIBCPP_HIDE_FROM_ABI __list_node_base() : __prev_(__self()), __next_(__self()) {}
0307
0308 _LIBCPP_HIDE_FROM_ABI explicit __list_node_base(__base_pointer __prev, __base_pointer __next)
0309 : __prev_(__prev), __next_(__next) {}
0310
0311 _LIBCPP_HIDE_FROM_ABI __base_pointer __self() { return pointer_traits<__base_pointer>::pointer_to(*this); }
0312
0313 _LIBCPP_HIDE_FROM_ABI __node_pointer __as_node() { return static_cast<__node_pointer>(__self()); }
0314 };
0315
0316 template <class _Tp, class _VoidPtr>
0317 struct __list_node : public __list_node_base<_Tp, _VoidPtr> {
0318 // We allow starting the lifetime of nodes without initializing the value held by the node,
0319 // since that is handled by the list itself in order to be allocator-aware.
0320 # ifndef _LIBCPP_CXX03_LANG
0321
0322 private:
0323 union {
0324 _Tp __value_;
0325 };
0326
0327 public:
0328 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return __value_; }
0329 # else
0330
0331 private:
0332 _ALIGNAS_TYPE(_Tp) char __buffer_[sizeof(_Tp)];
0333
0334 public:
0335 _LIBCPP_HIDE_FROM_ABI _Tp& __get_value() { return *std::__launder(reinterpret_cast<_Tp*>(&__buffer_)); }
0336 # endif
0337
0338 typedef __list_node_base<_Tp, _VoidPtr> __base;
0339 typedef typename __base::__base_pointer __base_pointer;
0340
0341 _LIBCPP_HIDE_FROM_ABI explicit __list_node(__base_pointer __prev, __base_pointer __next) : __base(__prev, __next) {}
0342 _LIBCPP_HIDE_FROM_ABI ~__list_node() {}
0343
0344 _LIBCPP_HIDE_FROM_ABI __base_pointer __as_link() { return __base::__self(); }
0345 };
0346
0347 template <class _Tp, class _Alloc = allocator<_Tp> >
0348 class _LIBCPP_TEMPLATE_VIS list;
0349 template <class _Tp, class _Alloc>
0350 class __list_imp;
0351 template <class _Tp, class _VoidPtr>
0352 class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
0353
0354 template <class _Tp, class _VoidPtr>
0355 class _LIBCPP_TEMPLATE_VIS __list_iterator {
0356 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
0357 typedef typename _NodeTraits::__base_pointer __base_pointer;
0358
0359 __base_pointer __ptr_;
0360
0361 _LIBCPP_HIDE_FROM_ABI explicit __list_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
0362
0363 template <class, class>
0364 friend class list;
0365 template <class, class>
0366 friend class __list_imp;
0367 template <class, class>
0368 friend class __list_const_iterator;
0369
0370 public:
0371 typedef bidirectional_iterator_tag iterator_category;
0372 typedef _Tp value_type;
0373 typedef value_type& reference;
0374 typedef __rebind_pointer_t<_VoidPtr, value_type> pointer;
0375 typedef typename pointer_traits<pointer>::difference_type difference_type;
0376
0377 _LIBCPP_HIDE_FROM_ABI __list_iterator() _NOEXCEPT : __ptr_(nullptr) {}
0378
0379 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __ptr_->__as_node()->__get_value(); }
0380 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
0381 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
0382 }
0383
0384 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator++() {
0385 __ptr_ = __ptr_->__next_;
0386 return *this;
0387 }
0388 _LIBCPP_HIDE_FROM_ABI __list_iterator operator++(int) {
0389 __list_iterator __t(*this);
0390 ++(*this);
0391 return __t;
0392 }
0393
0394 _LIBCPP_HIDE_FROM_ABI __list_iterator& operator--() {
0395 __ptr_ = __ptr_->__prev_;
0396 return *this;
0397 }
0398 _LIBCPP_HIDE_FROM_ABI __list_iterator operator--(int) {
0399 __list_iterator __t(*this);
0400 --(*this);
0401 return __t;
0402 }
0403
0404 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __list_iterator& __x, const __list_iterator& __y) {
0405 return __x.__ptr_ == __y.__ptr_;
0406 }
0407 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __list_iterator& __x, const __list_iterator& __y) {
0408 return !(__x == __y);
0409 }
0410 };
0411
0412 template <class _Tp, class _VoidPtr>
0413 class _LIBCPP_TEMPLATE_VIS __list_const_iterator {
0414 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
0415 typedef typename _NodeTraits::__base_pointer __base_pointer;
0416
0417 __base_pointer __ptr_;
0418
0419 _LIBCPP_HIDE_FROM_ABI explicit __list_const_iterator(__base_pointer __p) _NOEXCEPT : __ptr_(__p) {}
0420
0421 template <class, class>
0422 friend class list;
0423 template <class, class>
0424 friend class __list_imp;
0425
0426 public:
0427 typedef bidirectional_iterator_tag iterator_category;
0428 typedef _Tp value_type;
0429 typedef const value_type& reference;
0430 typedef __rebind_pointer_t<_VoidPtr, const value_type> pointer;
0431 typedef typename pointer_traits<pointer>::difference_type difference_type;
0432
0433 _LIBCPP_HIDE_FROM_ABI __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) {}
0434 _LIBCPP_HIDE_FROM_ABI __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
0435 : __ptr_(__p.__ptr_) {}
0436
0437 _LIBCPP_HIDE_FROM_ABI reference operator*() const { return __ptr_->__as_node()->__get_value(); }
0438 _LIBCPP_HIDE_FROM_ABI pointer operator->() const {
0439 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__get_value());
0440 }
0441
0442 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator++() {
0443 __ptr_ = __ptr_->__next_;
0444 return *this;
0445 }
0446 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator++(int) {
0447 __list_const_iterator __t(*this);
0448 ++(*this);
0449 return __t;
0450 }
0451
0452 _LIBCPP_HIDE_FROM_ABI __list_const_iterator& operator--() {
0453 __ptr_ = __ptr_->__prev_;
0454 return *this;
0455 }
0456 _LIBCPP_HIDE_FROM_ABI __list_const_iterator operator--(int) {
0457 __list_const_iterator __t(*this);
0458 --(*this);
0459 return __t;
0460 }
0461
0462 friend _LIBCPP_HIDE_FROM_ABI bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) {
0463 return __x.__ptr_ == __y.__ptr_;
0464 }
0465 friend _LIBCPP_HIDE_FROM_ABI bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) {
0466 return !(__x == __y);
0467 }
0468 };
0469
0470 template <class _Tp, class _Alloc>
0471 class __list_imp {
0472 public:
0473 __list_imp(const __list_imp&) = delete;
0474 __list_imp& operator=(const __list_imp&) = delete;
0475
0476 typedef _Alloc allocator_type;
0477 typedef allocator_traits<allocator_type> __alloc_traits;
0478 typedef typename __alloc_traits::size_type size_type;
0479
0480 protected:
0481 typedef _Tp value_type;
0482 typedef typename __alloc_traits::void_pointer __void_pointer;
0483 typedef __list_iterator<value_type, __void_pointer> iterator;
0484 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
0485 typedef __list_node_base<value_type, __void_pointer> __node_base;
0486 typedef __list_node<value_type, __void_pointer> __node_type;
0487 typedef __rebind_alloc<__alloc_traits, __node_type> __node_allocator;
0488 typedef allocator_traits<__node_allocator> __node_alloc_traits;
0489 typedef typename __node_alloc_traits::pointer __node_pointer;
0490 typedef typename __node_alloc_traits::pointer __node_const_pointer;
0491 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
0492 typedef typename __node_pointer_traits::__base_pointer __base_pointer;
0493 typedef __base_pointer __link_const_pointer;
0494 typedef typename __alloc_traits::pointer pointer;
0495 typedef typename __alloc_traits::const_pointer const_pointer;
0496 typedef typename __alloc_traits::difference_type difference_type;
0497
0498 typedef __rebind_alloc<__alloc_traits, __node_base> __node_base_allocator;
0499 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
0500 static_assert(!is_same<allocator_type, __node_allocator>::value,
0501 "internal allocator type must differ from user-specified type; otherwise overload resolution breaks");
0502
0503 __node_base __end_;
0504 _LIBCPP_COMPRESSED_PAIR(size_type, __size_, __node_allocator, __node_alloc_);
0505
0506 _LIBCPP_HIDE_FROM_ABI __base_pointer __end_as_link() const _NOEXCEPT {
0507 return __node_pointer_traits::__unsafe_link_pointer_cast(const_cast<__node_base&>(__end_).__self());
0508 }
0509
0510 _LIBCPP_HIDE_FROM_ABI size_type __node_alloc_max_size() const _NOEXCEPT {
0511 return __node_alloc_traits::max_size(__node_alloc_);
0512 }
0513 _LIBCPP_HIDE_FROM_ABI static void __unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT;
0514
0515 _LIBCPP_HIDE_FROM_ABI __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
0516 _LIBCPP_HIDE_FROM_ABI __list_imp(const allocator_type& __a);
0517 _LIBCPP_HIDE_FROM_ABI __list_imp(const __node_allocator& __a);
0518 # ifndef _LIBCPP_CXX03_LANG
0519 _LIBCPP_HIDE_FROM_ABI __list_imp(__node_allocator&& __a) _NOEXCEPT;
0520 # endif
0521 _LIBCPP_HIDE_FROM_ABI ~__list_imp();
0522 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT;
0523 _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __size_ == 0; }
0524
0525 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return iterator(__end_.__next_); }
0526 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return const_iterator(__end_.__next_); }
0527 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return iterator(__end_as_link()); }
0528 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return const_iterator(__end_as_link()); }
0529
0530 _LIBCPP_HIDE_FROM_ABI void swap(__list_imp& __c)
0531 # if _LIBCPP_STD_VER >= 14
0532 _NOEXCEPT;
0533 # else
0534 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>);
0535 # endif
0536
0537 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c) {
0538 __copy_assign_alloc(
0539 __c, integral_constant<bool, __node_alloc_traits::propagate_on_container_copy_assignment::value>());
0540 }
0541
0542 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c)
0543 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_move_assignment::value ||
0544 is_nothrow_move_assignable<__node_allocator>::value) {
0545 __move_assign_alloc(
0546 __c, integral_constant<bool, __node_alloc_traits::propagate_on_container_move_assignment::value>());
0547 }
0548
0549 template <class... _Args>
0550 _LIBCPP_HIDE_FROM_ABI __node_pointer __create_node(__base_pointer __prev, __base_pointer __next, _Args&&... __args) {
0551 __allocation_guard<__node_allocator> __guard(__node_alloc_, 1);
0552 // Begin the lifetime of the node itself. Note that this doesn't begin the lifetime of the value
0553 // held inside the node, since we need to use the allocator's construct() method for that.
0554 //
0555 // We don't use the allocator's construct() method to construct the node itself since the
0556 // Cpp17FooInsertable named requirements don't require the allocator's construct() method
0557 // to work on anything other than the value_type.
0558 std::__construct_at(std::addressof(*__guard.__get()), __prev, __next);
0559
0560 // Now construct the value_type using the allocator's construct() method.
0561 __node_alloc_traits::construct(
0562 __node_alloc_, std::addressof(__guard.__get()->__get_value()), std::forward<_Args>(__args)...);
0563 return __guard.__release_ptr();
0564 }
0565
0566 _LIBCPP_HIDE_FROM_ABI void __delete_node(__node_pointer __node) {
0567 // For the same reason as above, we use the allocator's destroy() method for the value_type,
0568 // but not for the node itself.
0569 __node_alloc_traits::destroy(__node_alloc_, std::addressof(__node->__get_value()));
0570 std::__destroy_at(std::addressof(*__node));
0571 __node_alloc_traits::deallocate(__node_alloc_, __node, 1);
0572 }
0573
0574 private:
0575 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp& __c, true_type) {
0576 if (__node_alloc_ != __c.__node_alloc_)
0577 clear();
0578 __node_alloc_ = __c.__node_alloc_;
0579 }
0580
0581 _LIBCPP_HIDE_FROM_ABI void __copy_assign_alloc(const __list_imp&, false_type) {}
0582
0583 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp& __c, true_type)
0584 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) {
0585 __node_alloc_ = std::move(__c.__node_alloc_);
0586 }
0587
0588 _LIBCPP_HIDE_FROM_ABI void __move_assign_alloc(__list_imp&, false_type) _NOEXCEPT {}
0589 };
0590
0591 // Unlink nodes [__f, __l]
0592 template <class _Tp, class _Alloc>
0593 inline void __list_imp<_Tp, _Alloc>::__unlink_nodes(__base_pointer __f, __base_pointer __l) _NOEXCEPT {
0594 __f->__prev_->__next_ = __l->__next_;
0595 __l->__next_->__prev_ = __f->__prev_;
0596 }
0597
0598 template <class _Tp, class _Alloc>
0599 inline __list_imp<_Tp, _Alloc>::__list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
0600 : __size_(0) {}
0601
0602 template <class _Tp, class _Alloc>
0603 inline __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
0604 : __size_(0), __node_alloc_(__node_allocator(__a)) {}
0605
0606 template <class _Tp, class _Alloc>
0607 inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a) : __size_(0), __node_alloc_(__a) {}
0608
0609 # ifndef _LIBCPP_CXX03_LANG
0610 template <class _Tp, class _Alloc>
0611 inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
0612 : __size_(0),
0613 __node_alloc_(std::move(__a)) {}
0614 # endif
0615
0616 template <class _Tp, class _Alloc>
0617 __list_imp<_Tp, _Alloc>::~__list_imp() {
0618 clear();
0619 }
0620
0621 template <class _Tp, class _Alloc>
0622 void __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT {
0623 if (!empty()) {
0624 __base_pointer __f = __end_.__next_;
0625 __base_pointer __l = __end_as_link();
0626 __unlink_nodes(__f, __l->__prev_);
0627 __size_ = 0;
0628 while (__f != __l) {
0629 __node_pointer __np = __f->__as_node();
0630 __f = __f->__next_;
0631 __delete_node(__np);
0632 }
0633 }
0634 }
0635
0636 template <class _Tp, class _Alloc>
0637 void __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
0638 # if _LIBCPP_STD_VER >= 14
0639 _NOEXCEPT
0640 # else
0641 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<allocator_type>)
0642 # endif
0643 {
0644 _LIBCPP_ASSERT_COMPATIBLE_ALLOCATOR(
0645 __alloc_traits::propagate_on_container_swap::value || this->__node_alloc_ == __c.__node_alloc_,
0646 "list::swap: Either propagate_on_container_swap must be true"
0647 " or the allocators must compare equal");
0648 using std::swap;
0649 std::__swap_allocator(__node_alloc_, __c.__node_alloc_);
0650 swap(__size_, __c.__size_);
0651 swap(__end_, __c.__end_);
0652 if (__size_ == 0)
0653 __end_.__next_ = __end_.__prev_ = __end_as_link();
0654 else
0655 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
0656 if (__c.__size_ == 0)
0657 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
0658 else
0659 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
0660 }
0661
0662 template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
0663 class _LIBCPP_TEMPLATE_VIS list : private __list_imp<_Tp, _Alloc> {
0664 typedef __list_imp<_Tp, _Alloc> __base;
0665 typedef typename __base::__node_type __node_type;
0666 typedef typename __base::__node_allocator __node_allocator;
0667 typedef typename __base::__node_pointer __node_pointer;
0668 typedef typename __base::__node_alloc_traits __node_alloc_traits;
0669 typedef typename __base::__node_base __node_base;
0670 typedef typename __base::__node_base_pointer __node_base_pointer;
0671 typedef typename __base::__base_pointer __base_pointer;
0672
0673 public:
0674 typedef _Tp value_type;
0675 typedef _Alloc allocator_type;
0676 static_assert(__check_valid_allocator<allocator_type>::value);
0677 static_assert(is_same<value_type, typename allocator_type::value_type>::value,
0678 "Allocator::value_type must be same type as value_type");
0679 typedef value_type& reference;
0680 typedef const value_type& const_reference;
0681 typedef typename __base::pointer pointer;
0682 typedef typename __base::const_pointer const_pointer;
0683 typedef typename __base::size_type size_type;
0684 typedef typename __base::difference_type difference_type;
0685 typedef typename __base::iterator iterator;
0686 typedef typename __base::const_iterator const_iterator;
0687 typedef std::reverse_iterator<iterator> reverse_iterator;
0688 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
0689 # if _LIBCPP_STD_VER >= 20
0690 typedef size_type __remove_return_type;
0691 # else
0692 typedef void __remove_return_type;
0693 # endif
0694
0695 _LIBCPP_HIDE_FROM_ABI list() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) {}
0696 _LIBCPP_HIDE_FROM_ABI explicit list(const allocator_type& __a) : __base(__a) {}
0697 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n);
0698 # if _LIBCPP_STD_VER >= 14
0699 _LIBCPP_HIDE_FROM_ABI explicit list(size_type __n, const allocator_type& __a);
0700 # endif
0701 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x);
0702 template <__enable_if_t<__is_allocator<_Alloc>::value, int> = 0>
0703 _LIBCPP_HIDE_FROM_ABI list(size_type __n, const value_type& __x, const allocator_type& __a) : __base(__a) {
0704 for (; __n > 0; --__n)
0705 push_back(__x);
0706 }
0707
0708 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
0709 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l);
0710
0711 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
0712 _LIBCPP_HIDE_FROM_ABI list(_InpIter __f, _InpIter __l, const allocator_type& __a);
0713
0714 # if _LIBCPP_STD_VER >= 23
0715 template <_ContainerCompatibleRange<_Tp> _Range>
0716 _LIBCPP_HIDE_FROM_ABI list(from_range_t, _Range&& __range, const allocator_type& __a = allocator_type())
0717 : __base(__a) {
0718 prepend_range(std::forward<_Range>(__range));
0719 }
0720 # endif
0721
0722 _LIBCPP_HIDE_FROM_ABI list(const list& __c);
0723 _LIBCPP_HIDE_FROM_ABI list(const list& __c, const __type_identity_t<allocator_type>& __a);
0724 _LIBCPP_HIDE_FROM_ABI list& operator=(const list& __c);
0725 # ifndef _LIBCPP_CXX03_LANG
0726 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il);
0727 _LIBCPP_HIDE_FROM_ABI list(initializer_list<value_type> __il, const allocator_type& __a);
0728
0729 _LIBCPP_HIDE_FROM_ABI list(list&& __c) _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
0730 _LIBCPP_HIDE_FROM_ABI list(list&& __c, const __type_identity_t<allocator_type>& __a);
0731 _LIBCPP_HIDE_FROM_ABI list& operator=(list&& __c)
0732 _NOEXCEPT_(__node_alloc_traits::propagate_on_container_move_assignment::value&&
0733 is_nothrow_move_assignable<__node_allocator>::value);
0734
0735 _LIBCPP_HIDE_FROM_ABI list& operator=(initializer_list<value_type> __il) {
0736 assign(__il.begin(), __il.end());
0737 return *this;
0738 }
0739
0740 _LIBCPP_HIDE_FROM_ABI void assign(initializer_list<value_type> __il) { assign(__il.begin(), __il.end()); }
0741 # endif // _LIBCPP_CXX03_LANG
0742
0743 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
0744 _LIBCPP_HIDE_FROM_ABI void assign(_InpIter __f, _InpIter __l);
0745
0746 # if _LIBCPP_STD_VER >= 23
0747 template <_ContainerCompatibleRange<_Tp> _Range>
0748 _LIBCPP_HIDE_FROM_ABI void assign_range(_Range&& __range) {
0749 __assign_with_sentinel(ranges::begin(__range), ranges::end(__range));
0750 }
0751 # endif
0752
0753 _LIBCPP_HIDE_FROM_ABI void assign(size_type __n, const value_type& __x);
0754
0755 _LIBCPP_HIDE_FROM_ABI allocator_type get_allocator() const _NOEXCEPT;
0756
0757 _LIBCPP_HIDE_FROM_ABI size_type size() const _NOEXCEPT { return this->__size_; }
0758 [[__nodiscard__]] _LIBCPP_HIDE_FROM_ABI bool empty() const _NOEXCEPT { return __base::empty(); }
0759 _LIBCPP_HIDE_FROM_ABI size_type max_size() const _NOEXCEPT {
0760 return std::min<size_type>(this->__node_alloc_max_size(), numeric_limits<difference_type >::max());
0761 }
0762
0763 _LIBCPP_HIDE_FROM_ABI iterator begin() _NOEXCEPT { return __base::begin(); }
0764 _LIBCPP_HIDE_FROM_ABI const_iterator begin() const _NOEXCEPT { return __base::begin(); }
0765 _LIBCPP_HIDE_FROM_ABI iterator end() _NOEXCEPT { return __base::end(); }
0766 _LIBCPP_HIDE_FROM_ABI const_iterator end() const _NOEXCEPT { return __base::end(); }
0767 _LIBCPP_HIDE_FROM_ABI const_iterator cbegin() const _NOEXCEPT { return __base::begin(); }
0768 _LIBCPP_HIDE_FROM_ABI const_iterator cend() const _NOEXCEPT { return __base::end(); }
0769
0770 _LIBCPP_HIDE_FROM_ABI reverse_iterator rbegin() _NOEXCEPT { return reverse_iterator(end()); }
0771 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
0772 _LIBCPP_HIDE_FROM_ABI reverse_iterator rend() _NOEXCEPT { return reverse_iterator(begin()); }
0773 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator rend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
0774 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crbegin() const _NOEXCEPT { return const_reverse_iterator(end()); }
0775 _LIBCPP_HIDE_FROM_ABI const_reverse_iterator crend() const _NOEXCEPT { return const_reverse_iterator(begin()); }
0776
0777 _LIBCPP_HIDE_FROM_ABI reference front() {
0778 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
0779 return __base::__end_.__next_->__as_node()->__get_value();
0780 }
0781 _LIBCPP_HIDE_FROM_ABI const_reference front() const {
0782 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::front called on empty list");
0783 return __base::__end_.__next_->__as_node()->__get_value();
0784 }
0785 _LIBCPP_HIDE_FROM_ABI reference back() {
0786 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
0787 return __base::__end_.__prev_->__as_node()->__get_value();
0788 }
0789 _LIBCPP_HIDE_FROM_ABI const_reference back() const {
0790 _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS(!empty(), "list::back called on empty list");
0791 return __base::__end_.__prev_->__as_node()->__get_value();
0792 }
0793
0794 # ifndef _LIBCPP_CXX03_LANG
0795 _LIBCPP_HIDE_FROM_ABI void push_front(value_type&& __x);
0796 _LIBCPP_HIDE_FROM_ABI void push_back(value_type&& __x);
0797
0798 # if _LIBCPP_STD_VER >= 23
0799 template <_ContainerCompatibleRange<_Tp> _Range>
0800 _LIBCPP_HIDE_FROM_ABI void prepend_range(_Range&& __range) {
0801 insert_range(begin(), std::forward<_Range>(__range));
0802 }
0803
0804 template <_ContainerCompatibleRange<_Tp> _Range>
0805 _LIBCPP_HIDE_FROM_ABI void append_range(_Range&& __range) {
0806 insert_range(end(), std::forward<_Range>(__range));
0807 }
0808 # endif
0809
0810 template <class... _Args>
0811 # if _LIBCPP_STD_VER >= 17
0812 _LIBCPP_HIDE_FROM_ABI reference emplace_front(_Args&&... __args);
0813 # else
0814 _LIBCPP_HIDE_FROM_ABI void emplace_front(_Args&&... __args);
0815 # endif
0816 template <class... _Args>
0817 # if _LIBCPP_STD_VER >= 17
0818 _LIBCPP_HIDE_FROM_ABI reference emplace_back(_Args&&... __args);
0819 # else
0820 _LIBCPP_HIDE_FROM_ABI void emplace_back(_Args&&... __args);
0821 # endif
0822 template <class... _Args>
0823 _LIBCPP_HIDE_FROM_ABI iterator emplace(const_iterator __p, _Args&&... __args);
0824
0825 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, value_type&& __x);
0826
0827 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, initializer_list<value_type> __il) {
0828 return insert(__p, __il.begin(), __il.end());
0829 }
0830 # endif // _LIBCPP_CXX03_LANG
0831
0832 _LIBCPP_HIDE_FROM_ABI void push_front(const value_type& __x);
0833 _LIBCPP_HIDE_FROM_ABI void push_back(const value_type& __x);
0834
0835 # ifndef _LIBCPP_CXX03_LANG
0836 template <class _Arg>
0837 _LIBCPP_HIDE_FROM_ABI void __emplace_back(_Arg&& __arg) {
0838 emplace_back(std::forward<_Arg>(__arg));
0839 }
0840 # else
0841 _LIBCPP_HIDE_FROM_ABI void __emplace_back(value_type const& __arg) { push_back(__arg); }
0842 # endif
0843
0844 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, const value_type& __x);
0845 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, size_type __n, const value_type& __x);
0846
0847 template <class _InpIter, __enable_if_t<__has_input_iterator_category<_InpIter>::value, int> = 0>
0848 _LIBCPP_HIDE_FROM_ABI iterator insert(const_iterator __p, _InpIter __f, _InpIter __l);
0849
0850 # if _LIBCPP_STD_VER >= 23
0851 template <_ContainerCompatibleRange<_Tp> _Range>
0852 _LIBCPP_HIDE_FROM_ABI iterator insert_range(const_iterator __position, _Range&& __range) {
0853 return __insert_with_sentinel(__position, ranges::begin(__range), ranges::end(__range));
0854 }
0855 # endif
0856
0857 _LIBCPP_HIDE_FROM_ABI void swap(list& __c)
0858 # if _LIBCPP_STD_VER >= 14
0859 _NOEXCEPT
0860 # else
0861 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || __is_nothrow_swappable_v<__node_allocator>)
0862 # endif
0863 {
0864 __base::swap(__c);
0865 }
0866 _LIBCPP_HIDE_FROM_ABI void clear() _NOEXCEPT { __base::clear(); }
0867
0868 _LIBCPP_HIDE_FROM_ABI void pop_front();
0869 _LIBCPP_HIDE_FROM_ABI void pop_back();
0870
0871 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __p);
0872 _LIBCPP_HIDE_FROM_ABI iterator erase(const_iterator __f, const_iterator __l);
0873
0874 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n);
0875 _LIBCPP_HIDE_FROM_ABI void resize(size_type __n, const value_type& __x);
0876
0877 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c);
0878 # ifndef _LIBCPP_CXX03_LANG
0879 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c) { splice(__p, __c); }
0880 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __i) { splice(__p, __c, __i); }
0881 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) {
0882 splice(__p, __c, __f, __l);
0883 }
0884 # endif
0885 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __i);
0886 _LIBCPP_HIDE_FROM_ABI void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
0887
0888 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove(const value_type& __x);
0889 template <class _Pred>
0890 _LIBCPP_HIDE_FROM_ABI __remove_return_type remove_if(_Pred __pred);
0891 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique() { return unique(__equal_to()); }
0892 template <class _BinaryPred>
0893 _LIBCPP_HIDE_FROM_ABI __remove_return_type unique(_BinaryPred __binary_pred);
0894 _LIBCPP_HIDE_FROM_ABI void merge(list& __c);
0895 # ifndef _LIBCPP_CXX03_LANG
0896 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c) { merge(__c); }
0897
0898 template <class _Comp>
0899 _LIBCPP_HIDE_FROM_ABI void merge(list&& __c, _Comp __comp) {
0900 merge(__c, __comp);
0901 }
0902 # endif
0903 template <class _Comp>
0904 _LIBCPP_HIDE_FROM_ABI void merge(list& __c, _Comp __comp);
0905
0906 _LIBCPP_HIDE_FROM_ABI void sort();
0907 template <class _Comp>
0908 _LIBCPP_HIDE_FROM_ABI void sort(_Comp __comp);
0909
0910 _LIBCPP_HIDE_FROM_ABI void reverse() _NOEXCEPT;
0911
0912 _LIBCPP_HIDE_FROM_ABI bool __invariants() const;
0913
0914 private:
0915 template <class _Iterator, class _Sentinel>
0916 _LIBCPP_HIDE_FROM_ABI void __assign_with_sentinel(_Iterator __f, _Sentinel __l);
0917
0918 template <class _Iterator, class _Sentinel>
0919 _LIBCPP_HIDE_FROM_ABI iterator __insert_with_sentinel(const_iterator __p, _Iterator __f, _Sentinel __l);
0920
0921 _LIBCPP_HIDE_FROM_ABI static void __link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l);
0922 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_front(__base_pointer __f, __base_pointer __l);
0923 _LIBCPP_HIDE_FROM_ABI void __link_nodes_at_back(__base_pointer __f, __base_pointer __l);
0924 _LIBCPP_HIDE_FROM_ABI iterator __iterator(size_type __n);
0925 // TODO: Make this _LIBCPP_HIDE_FROM_ABI
0926 template <class _Comp>
0927 _LIBCPP_HIDDEN static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
0928
0929 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, true_type)
0930 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
0931 _LIBCPP_HIDE_FROM_ABI void __move_assign(list& __c, false_type);
0932 };
0933
0934 # if _LIBCPP_STD_VER >= 17
0935 template <class _InputIterator,
0936 class _Alloc = allocator<__iter_value_type<_InputIterator>>,
0937 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
0938 class = enable_if_t<__is_allocator<_Alloc>::value> >
0939 list(_InputIterator, _InputIterator) -> list<__iter_value_type<_InputIterator>, _Alloc>;
0940
0941 template <class _InputIterator,
0942 class _Alloc,
0943 class = enable_if_t<__has_input_iterator_category<_InputIterator>::value>,
0944 class = enable_if_t<__is_allocator<_Alloc>::value> >
0945 list(_InputIterator, _InputIterator, _Alloc) -> list<__iter_value_type<_InputIterator>, _Alloc>;
0946 # endif
0947
0948 # if _LIBCPP_STD_VER >= 23
0949 template <ranges::input_range _Range,
0950 class _Alloc = allocator<ranges::range_value_t<_Range>>,
0951 class = enable_if_t<__is_allocator<_Alloc>::value> >
0952 list(from_range_t, _Range&&, _Alloc = _Alloc()) -> list<ranges::range_value_t<_Range>, _Alloc>;
0953 # endif
0954
0955 // Link in nodes [__f, __l] just prior to __p
0956 template <class _Tp, class _Alloc>
0957 inline void list<_Tp, _Alloc>::__link_nodes(__base_pointer __p, __base_pointer __f, __base_pointer __l) {
0958 __p->__prev_->__next_ = __f;
0959 __f->__prev_ = __p->__prev_;
0960 __p->__prev_ = __l;
0961 __l->__next_ = __p;
0962 }
0963
0964 // Link in nodes [__f, __l] at the front of the list
0965 template <class _Tp, class _Alloc>
0966 inline void list<_Tp, _Alloc>::__link_nodes_at_front(__base_pointer __f, __base_pointer __l) {
0967 __f->__prev_ = __base::__end_as_link();
0968 __l->__next_ = __base::__end_.__next_;
0969 __l->__next_->__prev_ = __l;
0970 __base::__end_.__next_ = __f;
0971 }
0972
0973 // Link in nodes [__f, __l] at the back of the list
0974 template <class _Tp, class _Alloc>
0975 inline void list<_Tp, _Alloc>::__link_nodes_at_back(__base_pointer __f, __base_pointer __l) {
0976 __l->__next_ = __base::__end_as_link();
0977 __f->__prev_ = __base::__end_.__prev_;
0978 __f->__prev_->__next_ = __f;
0979 __base::__end_.__prev_ = __l;
0980 }
0981
0982 template <class _Tp, class _Alloc>
0983 inline typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::__iterator(size_type __n) {
0984 return __n <= this->__size_ / 2 ? std::next(begin(), __n) : std::prev(end(), this->__size_ - __n);
0985 }
0986
0987 template <class _Tp, class _Alloc>
0988 list<_Tp, _Alloc>::list(size_type __n) {
0989 for (; __n > 0; --__n)
0990 # ifndef _LIBCPP_CXX03_LANG
0991 emplace_back();
0992 # else
0993 push_back(value_type());
0994 # endif
0995 }
0996
0997 # if _LIBCPP_STD_VER >= 14
0998 template <class _Tp, class _Alloc>
0999 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : __base(__a) {
1000 for (; __n > 0; --__n)
1001 emplace_back();
1002 }
1003 # endif
1004
1005 template <class _Tp, class _Alloc>
1006 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) {
1007 for (; __n > 0; --__n)
1008 push_back(__x);
1009 }
1010
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);
1016 }
1017
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);
1023 }
1024
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)
1029 push_back(*__i);
1030 }
1031
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)
1035 push_back(*__i);
1036 }
1037
1038 # ifndef _LIBCPP_CXX03_LANG
1039
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)
1043 push_back(*__i);
1044 }
1045
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)
1049 push_back(*__i);
1050 }
1051
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_)) {
1055 splice(end(), __c);
1056 }
1057
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())
1061 splice(end(), __c);
1062 else {
1063 typedef move_iterator<iterator> _Ip;
1064 assign(_Ip(__c.begin()), _Ip(__c.end()));
1065 }
1066 }
1067
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>());
1073 return *this;
1074 }
1075
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()));
1081 } else
1082 __move_assign(__c, true_type());
1083 }
1084
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) {
1088 clear();
1089 __base::__move_assign_alloc(__c);
1090 splice(end(), __c);
1091 }
1092
1093 # endif // _LIBCPP_CXX03_LANG
1094
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());
1100 }
1101 return *this;
1102 }
1103
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);
1108 }
1109
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)
1116 *__i = *__f;
1117 if (__i == __e)
1118 __insert_with_sentinel(__e, std::move(__f), std::move(__l));
1119 else
1120 erase(__i, __e);
1121 }
1122
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)
1128 *__i = __x;
1129 if (__i == __e)
1130 insert(__e, __n, __x);
1131 else
1132 erase(__i, __e);
1133 }
1134
1135 template <class _Tp, class _Alloc>
1136 inline _Alloc list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT {
1137 return allocator_type(this->__node_alloc_);
1138 }
1139
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());
1144 ++this->__size_;
1145 return iterator(__node->__as_link());
1146 }
1147
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_);
1152 if (__n > 0) {
1153 size_type __ds = 0;
1154 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1155 ++__ds;
1156 __r = iterator(__node->__as_link());
1157 iterator __e = __r;
1158 # if _LIBCPP_HAS_EXCEPTIONS
1159 try {
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();
1163 }
1164 # if _LIBCPP_HAS_EXCEPTIONS
1165 } catch (...) {
1166 while (true) {
1167 __base_pointer __prev = __e.__ptr_->__prev_;
1168 __node_pointer __current = __e.__ptr_->__as_node();
1169 this->__delete_node(__current);
1170 if (__prev == 0)
1171 break;
1172 __e = iterator(__prev);
1173 }
1174 throw;
1175 }
1176 # endif // _LIBCPP_HAS_EXCEPTIONS
1177 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1178 this->__size_ += __ds;
1179 }
1180 return __r;
1181 }
1182
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);
1187 }
1188
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_);
1194 if (__f != __l) {
1195 size_type __ds = 0;
1196 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, *__f);
1197 ++__ds;
1198 __r = iterator(__node->__as_link());
1199 iterator __e = __r;
1200 # if _LIBCPP_HAS_EXCEPTIONS
1201 try {
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();
1205 }
1206 # if _LIBCPP_HAS_EXCEPTIONS
1207 } catch (...) {
1208 while (true) {
1209 __base_pointer __prev = __e.__ptr_->__prev_;
1210 __node_pointer __current = __e.__ptr_->__as_node();
1211 this->__delete_node(__current);
1212 if (__prev == 0)
1213 break;
1214 __e = iterator(__prev);
1215 }
1216 throw;
1217 }
1218 # endif // _LIBCPP_HAS_EXCEPTIONS
1219 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1220 this->__size_ += __ds;
1221 }
1222 return __r;
1223 }
1224
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);
1230 ++this->__size_;
1231 }
1232
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);
1238 ++this->__size_;
1239 }
1240
1241 # ifndef _LIBCPP_CXX03_LANG
1242
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);
1248 ++this->__size_;
1249 }
1250
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);
1256 ++this->__size_;
1257 }
1258
1259 template <class _Tp, class _Alloc>
1260 template <class... _Args>
1261 # if _LIBCPP_STD_VER >= 17
1262 typename list<_Tp, _Alloc>::reference
1263 # else
1264 void
1265 # endif
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);
1271 ++this->__size_;
1272 # if _LIBCPP_STD_VER >= 17
1273 return __node->__get_value();
1274 # endif
1275 }
1276
1277 template <class _Tp, class _Alloc>
1278 template <class... _Args>
1279 # if _LIBCPP_STD_VER >= 17
1280 typename list<_Tp, _Alloc>::reference
1281 # else
1282 void
1283 # endif
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);
1289 ++this->__size_;
1290 # if _LIBCPP_STD_VER >= 17
1291 return __node->__get_value();
1292 # endif
1293 }
1294
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);
1302 ++this->__size_;
1303 return iterator(__nl);
1304 }
1305
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);
1311 ++this->__size_;
1312 return iterator(__nl);
1313 }
1314
1315 # endif // _LIBCPP_CXX03_LANG
1316
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);
1322 --this->__size_;
1323 this->__delete_node(__n->__as_node());
1324 }
1325
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);
1331 --this->__size_;
1332 this->__delete_node(__n->__as_node());
1333 }
1334
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);
1341 --this->__size_;
1342 this->__delete_node(__n->__as_node());
1343 return iterator(__r);
1344 }
1345
1346 template <class _Tp, class _Alloc>
1347 typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) {
1348 if (__f != __l) {
1349 __base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1350 while (__f != __l) {
1351 __base_pointer __n = __f.__ptr_;
1352 ++__f;
1353 --this->__size_;
1354 this->__delete_node(__n->__as_node());
1355 }
1356 }
1357 return iterator(__l.__ptr_);
1358 }
1359
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_;
1366 size_type __ds = 0;
1367 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr);
1368 ++__ds;
1369 iterator __r = iterator(__node->__as_link());
1370 iterator __e = __r;
1371 # if _LIBCPP_HAS_EXCEPTIONS
1372 try {
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();
1376 }
1377 # if _LIBCPP_HAS_EXCEPTIONS
1378 } catch (...) {
1379 while (true) {
1380 __base_pointer __prev = __e.__ptr_->__prev_;
1381 __node_pointer __current = __e.__ptr_->__as_node();
1382 this->__delete_node(__current);
1383 if (__prev == 0)
1384 break;
1385 __e = iterator(__prev);
1386 }
1387 throw;
1388 }
1389 # endif // _LIBCPP_HAS_EXCEPTIONS
1390 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1391 this->__size_ += __ds;
1392 }
1393 }
1394
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_;
1401 size_type __ds = 0;
1402 __node_pointer __node = this->__create_node(/* prev = */ nullptr, /* next = */ nullptr, __x);
1403 ++__ds;
1404 __base_pointer __nl = __node->__as_link();
1405 iterator __r = iterator(__nl);
1406 iterator __e = __r;
1407 # if _LIBCPP_HAS_EXCEPTIONS
1408 try {
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();
1412 }
1413 # if _LIBCPP_HAS_EXCEPTIONS
1414 } catch (...) {
1415 while (true) {
1416 __base_pointer __prev = __e.__ptr_->__prev_;
1417 __node_pointer __current = __e.__ptr_->__as_node();
1418 this->__delete_node(__current);
1419 if (__prev == 0)
1420 break;
1421 __e = iterator(__prev);
1422 }
1423 throw;
1424 }
1425 # endif // _LIBCPP_HAS_EXCEPTIONS
1426 __link_nodes(__base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1427 this->__size_ += __ds;
1428 }
1429 }
1430
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");
1435 if (!__c.empty()) {
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_;
1441 __c.__size_ = 0;
1442 }
1443 }
1444
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);
1451 --__c.__size_;
1452 ++this->__size_;
1453 }
1454 }
1455
1456 template <class _Tp, class _Alloc>
1457 void list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) {
1458 if (__f != __l) {
1459 __base_pointer __first = __f.__ptr_;
1460 --__l;
1461 __base_pointer __last = __l.__ptr_;
1462 if (this != std::addressof(__c)) {
1463 size_type __s = std::distance(__f, __l) + 1;
1464 __c.__size_ -= __s;
1465 this->__size_ += __s;
1466 }
1467 __base::__unlink_nodes(__first, __last);
1468 __link_nodes(__p.__ptr_, __first, __last);
1469 }
1470 }
1471
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;) {
1476 if (*__i == __x) {
1477 const_iterator __j = std::next(__i);
1478 for (; __j != __e && *__j == __x; ++__j)
1479 ;
1480 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
1481 __i = __j;
1482 if (__i != __e)
1483 ++__i;
1484 } else
1485 ++__i;
1486 }
1487
1488 return (__remove_return_type)__deleted_nodes.size();
1489 }
1490
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;) {
1496 if (__pred(*__i)) {
1497 iterator __j = std::next(__i);
1498 for (; __j != __e && __pred(*__j); ++__j)
1499 ;
1500 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
1501 __i = __j;
1502 if (__i != __e)
1503 ++__i;
1504 } else
1505 ++__i;
1506 }
1507
1508 return (__remove_return_type)__deleted_nodes.size();
1509 }
1510
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)
1518 ;
1519 if (++__i != __j) {
1520 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
1521 __i = __j;
1522 }
1523 }
1524
1525 return (__remove_return_type)__deleted_nodes.size();
1526 }
1527
1528 template <class _Tp, class _Alloc>
1529 inline void list<_Tp, _Alloc>::merge(list& __c) {
1530 merge(__c, __less<>());
1531 }
1532
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)) {
1543 size_type __ds = 1;
1544 iterator __m2 = std::next(__f2);
1545 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, (void)++__ds)
1546 ;
1547 this->__size_ += __ds;
1548 __c.__size_ -= __ds;
1549 __base_pointer __f = __f2.__ptr_;
1550 __base_pointer __l = __m2.__ptr_->__prev_;
1551 __f2 = __m2;
1552 __base::__unlink_nodes(__f, __l);
1553 __m2 = std::next(__f1);
1554 __link_nodes(__f1.__ptr_, __f, __l);
1555 __f1 = __m2;
1556 } else
1557 ++__f1;
1558 }
1559 splice(__e1, __c);
1560 }
1561 }
1562
1563 template <class _Tp, class _Alloc>
1564 inline void list<_Tp, _Alloc>::sort() {
1565 sort(__less<>());
1566 }
1567
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);
1572 }
1573
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) {
1578 switch (__n) {
1579 case 0:
1580 case 1:
1581 return __f1;
1582 case 2:
1583 if (__comp(*--__e2, *__f1)) {
1584 __base_pointer __f = __e2.__ptr_;
1585 __base::__unlink_nodes(__f, __f);
1586 __link_nodes(__f1.__ptr_, __f, __f);
1587 return __e2;
1588 }
1589 return __f1;
1590 }
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)
1598 ;
1599 __base_pointer __f = __f2.__ptr_;
1600 __base_pointer __l = __m2.__ptr_->__prev_;
1601 __r = __f2;
1602 __e1 = __f2 = __m2;
1603 __base::__unlink_nodes(__f, __l);
1604 __m2 = std::next(__f1);
1605 __link_nodes(__f1.__ptr_, __f, __l);
1606 __f1 = __m2;
1607 } else
1608 ++__f1;
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)
1613 ;
1614 __base_pointer __f = __f2.__ptr_;
1615 __base_pointer __l = __m2.__ptr_->__prev_;
1616 if (__e1 == __f2)
1617 __e1 = __m2;
1618 __f2 = __m2;
1619 __base::__unlink_nodes(__f, __l);
1620 __m2 = std::next(__f1);
1621 __link_nodes(__f1.__ptr_, __f, __l);
1622 __f1 = __m2;
1623 } else
1624 ++__f1;
1625 }
1626 return __r;
1627 }
1628
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_;
1636 }
1637 std::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
1638 }
1639 }
1640
1641 template <class _Tp, class _Alloc>
1642 bool list<_Tp, _Alloc>::__invariants() const {
1643 return size() == std::distance(begin(), end());
1644 }
1645
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());
1649 }
1650
1651 # if _LIBCPP_STD_VER <= 17
1652
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());
1656 }
1657
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);
1661 }
1662
1663 template <class _Tp, class _Alloc>
1664 inline _LIBCPP_HIDE_FROM_ABI bool operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) {
1665 return __y < __x;
1666 }
1667
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);
1671 }
1672
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);
1676 }
1677
1678 # else // _LIBCPP_STD_VER <= 17
1679
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);
1684 }
1685
1686 # endif // _LIBCPP_STD_VER <= 17
1687
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))) {
1691 __x.swap(__y);
1692 }
1693
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);
1699 }
1700
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; });
1705 }
1706
1707 template <>
1708 inline constexpr bool __format::__enable_insertable<std::list<char>> = true;
1709 # if _LIBCPP_HAS_WIDE_CHARACTERS
1710 template <>
1711 inline constexpr bool __format::__enable_insertable<std::list<wchar_t>> = true;
1712 # endif
1713
1714 # endif // _LIBCPP_STD_VER >= 20
1715
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;
1725 };
1726
1727 _LIBCPP_END_NAMESPACE_STD
1728
1729 # if _LIBCPP_STD_VER >= 17
1730 _LIBCPP_BEGIN_NAMESPACE_STD
1731 namespace pmr {
1732 template <class _ValueT>
1733 using list _LIBCPP_AVAILABILITY_PMR = std::list<_ValueT, polymorphic_allocator<_ValueT>>;
1734 } // namespace pmr
1735 _LIBCPP_END_NAMESPACE_STD
1736 # endif
1737
1738 _LIBCPP_POP_MACROS
1739
1740 # if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
1741 # include <algorithm>
1742 # include <atomic>
1743 # include <concepts>
1744 # include <cstdint>
1745 # include <cstdlib>
1746 # include <functional>
1747 # include <iosfwd>
1748 # include <iterator>
1749 # include <stdexcept>
1750 # include <type_traits>
1751 # include <typeinfo>
1752 # endif
1753 #endif // __cplusplus < 201103L && defined(_LIBCPP_USE_FROZEN_CXX03_HEADERS)
1754
1755 #endif // _LIBCPP_LIST