2 //===---------------------------- list ------------------------------------===//
4 // The LLVM Compiler Infrastructure
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
9 //===----------------------------------------------------------------------===//
20 template <class T, class Alloc = allocator<T> >
27 typedef Alloc allocator_type;
28 typedef typename allocator_type::reference reference;
29 typedef typename allocator_type::const_reference const_reference;
30 typedef typename allocator_type::pointer pointer;
31 typedef typename allocator_type::const_pointer const_pointer;
32 typedef implementation-defined iterator;
33 typedef implementation-defined const_iterator;
34 typedef implementation-defined size_type;
35 typedef implementation-defined difference_type;
36 typedef reverse_iterator<iterator> reverse_iterator;
37 typedef reverse_iterator<const_iterator> const_reverse_iterator;
40 noexcept(is_nothrow_default_constructible<allocator_type>::value);
41 explicit list(const allocator_type& a);
42 explicit list(size_type n);
43 explicit list(size_type n, const allocator_type& a); // C++14
44 list(size_type n, const value_type& value);
45 list(size_type n, const value_type& value, const allocator_type& a);
47 list(Iter first, Iter last);
49 list(Iter first, Iter last, const allocator_type& a);
51 list(const list&, const allocator_type& a);
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
54 list(list&&, const allocator_type& a);
55 list(initializer_list<value_type>);
56 list(initializer_list<value_type>, const allocator_type& a);
60 list& operator=(const list& x);
61 list& operator=(list&& x)
63 allocator_type::propagate_on_container_move_assignment::value &&
64 is_nothrow_move_assignable<allocator_type>::value);
65 list& operator=(initializer_list<value_type>);
67 void assign(Iter first, Iter last);
68 void assign(size_type n, const value_type& t);
69 void assign(initializer_list<value_type>);
71 allocator_type get_allocator() const noexcept;
73 iterator begin() noexcept;
74 const_iterator begin() const noexcept;
75 iterator end() noexcept;
76 const_iterator end() const noexcept;
77 reverse_iterator rbegin() noexcept;
78 const_reverse_iterator rbegin() const noexcept;
79 reverse_iterator rend() noexcept;
80 const_reverse_iterator rend() const noexcept;
81 const_iterator cbegin() const noexcept;
82 const_iterator cend() const noexcept;
83 const_reverse_iterator crbegin() const noexcept;
84 const_reverse_iterator crend() const noexcept;
87 const_reference front() const;
89 const_reference back() const;
91 bool empty() const noexcept;
92 size_type size() const noexcept;
93 size_type max_size() const noexcept;
95 template <class... Args>
96 reference emplace_front(Args&&... args); // reference in C++17
98 template <class... Args>
99 reference emplace_back(Args&&... args); // reference in C++17
101 void push_front(const value_type& x);
102 void push_front(value_type&& x);
103 void push_back(const value_type& x);
104 void push_back(value_type&& x);
105 template <class... Args>
106 iterator emplace(const_iterator position, Args&&... args);
107 iterator insert(const_iterator position, const value_type& x);
108 iterator insert(const_iterator position, value_type&& x);
109 iterator insert(const_iterator position, size_type n, const value_type& x);
110 template <class Iter>
111 iterator insert(const_iterator position, Iter first, Iter last);
112 iterator insert(const_iterator position, initializer_list<value_type> il);
114 iterator erase(const_iterator position);
115 iterator erase(const_iterator position, const_iterator last);
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
121 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
122 void clear() noexcept;
124 void splice(const_iterator position, list& x);
125 void splice(const_iterator position, list&& x);
126 void splice(const_iterator position, list& x, const_iterator i);
127 void splice(const_iterator position, list&& x, const_iterator i);
128 void splice(const_iterator position, list& x, const_iterator first,
129 const_iterator last);
130 void splice(const_iterator position, list&& x, const_iterator first,
131 const_iterator last);
133 void remove(const value_type& value);
134 template <class Pred> void remove_if(Pred pred);
136 template <class BinaryPredicate>
137 void unique(BinaryPredicate binary_pred);
139 void merge(list&& x);
140 template <class Compare>
141 void merge(list& x, Compare comp);
142 template <class Compare>
143 void merge(list&& x, Compare comp);
145 template <class Compare>
146 void sort(Compare comp);
147 void reverse() noexcept;
151 template <class InputIterator, class Allocator = allocator<typename iterator_traits<InputIterator>::value_type>>
152 list(InputIterator, InputIterator, Allocator = Allocator())
153 -> list<typename iterator_traits<InputIterator>::value_type, Allocator>; // C++17
155 template <class T, class Alloc>
156 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
157 template <class T, class Alloc>
158 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
159 template <class T, class Alloc>
160 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
161 template <class T, class Alloc>
162 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
163 template <class T, class Alloc>
164 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
165 template <class T, class Alloc>
166 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
168 template <class T, class Alloc>
169 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
170 noexcept(noexcept(x.swap(y)));
172 template <class T, class Allocator, class U>
173 void erase(list<T, Allocator>& c, const U& value); // C++20
174 template <class T, class Allocator, class Predicate>
175 void erase_if(list<T, Allocator>& c, Predicate pred); // C++20
185 #include <initializer_list>
188 #include <type_traits>
193 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
194 #pragma GCC system_header
198 #include <__undef_macros>
201 _LIBCPP_BEGIN_NAMESPACE_STD
203 template <class _Tp, class _VoidPtr> struct __list_node;
204 template <class _Tp, class _VoidPtr> struct __list_node_base;
206 template <class _Tp, class _VoidPtr>
207 struct __list_node_pointer_traits {
208 typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
210 typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
213 #if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
214 typedef __base_pointer __link_pointer;
216 typedef typename conditional<
217 is_pointer<_VoidPtr>::value,
220 >::type __link_pointer;
223 typedef typename conditional<
224 is_same<__link_pointer, __node_pointer>::value,
227 >::type __non_link_pointer;
229 static _LIBCPP_INLINE_VISIBILITY
230 __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
234 static _LIBCPP_INLINE_VISIBILITY
235 __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
236 return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
241 template <class _Tp, class _VoidPtr>
242 struct __list_node_base
244 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
245 typedef typename _NodeTraits::__node_pointer __node_pointer;
246 typedef typename _NodeTraits::__base_pointer __base_pointer;
247 typedef typename _NodeTraits::__link_pointer __link_pointer;
249 __link_pointer __prev_;
250 __link_pointer __next_;
252 _LIBCPP_INLINE_VISIBILITY
253 __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
254 __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
256 _LIBCPP_INLINE_VISIBILITY
257 __base_pointer __self() {
258 return pointer_traits<__base_pointer>::pointer_to(*this);
261 _LIBCPP_INLINE_VISIBILITY
262 __node_pointer __as_node() {
263 return static_cast<__node_pointer>(__self());
267 template <class _Tp, class _VoidPtr>
269 : public __list_node_base<_Tp, _VoidPtr>
273 typedef __list_node_base<_Tp, _VoidPtr> __base;
274 typedef typename __base::__link_pointer __link_pointer;
276 _LIBCPP_INLINE_VISIBILITY
277 __link_pointer __as_link() {
278 return static_cast<__link_pointer>(__base::__self());
282 template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
283 template <class _Tp, class _Alloc> class __list_imp;
284 template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
286 template <class _Tp, class _VoidPtr>
287 class _LIBCPP_TEMPLATE_VIS __list_iterator
289 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
290 typedef typename _NodeTraits::__link_pointer __link_pointer;
292 __link_pointer __ptr_;
294 #if _LIBCPP_DEBUG_LEVEL >= 2
295 _LIBCPP_INLINE_VISIBILITY
296 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
299 __get_db()->__insert_ic(this, __c);
302 _LIBCPP_INLINE_VISIBILITY
303 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
308 template<class, class> friend class list;
309 template<class, class> friend class __list_imp;
310 template<class, class> friend class __list_const_iterator;
312 typedef bidirectional_iterator_tag iterator_category;
313 typedef _Tp value_type;
314 typedef value_type& reference;
315 typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
316 typedef typename pointer_traits<pointer>::difference_type difference_type;
318 _LIBCPP_INLINE_VISIBILITY
319 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
321 #if _LIBCPP_DEBUG_LEVEL >= 2
322 __get_db()->__insert_i(this);
326 #if _LIBCPP_DEBUG_LEVEL >= 2
328 _LIBCPP_INLINE_VISIBILITY
329 __list_iterator(const __list_iterator& __p)
332 __get_db()->__iterator_copy(this, &__p);
335 _LIBCPP_INLINE_VISIBILITY
338 __get_db()->__erase_i(this);
341 _LIBCPP_INLINE_VISIBILITY
342 __list_iterator& operator=(const __list_iterator& __p)
346 __get_db()->__iterator_copy(this, &__p);
352 #endif // _LIBCPP_DEBUG_LEVEL >= 2
354 _LIBCPP_INLINE_VISIBILITY
355 reference operator*() const
357 #if _LIBCPP_DEBUG_LEVEL >= 2
358 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
359 "Attempted to dereference a non-dereferenceable list::iterator");
361 return __ptr_->__as_node()->__value_;
363 _LIBCPP_INLINE_VISIBILITY
364 pointer operator->() const
366 #if _LIBCPP_DEBUG_LEVEL >= 2
367 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
368 "Attempted to dereference a non-dereferenceable list::iterator");
370 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
373 _LIBCPP_INLINE_VISIBILITY
374 __list_iterator& operator++()
376 #if _LIBCPP_DEBUG_LEVEL >= 2
377 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
378 "Attempted to increment non-incrementable list::iterator");
380 __ptr_ = __ptr_->__next_;
383 _LIBCPP_INLINE_VISIBILITY
384 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
386 _LIBCPP_INLINE_VISIBILITY
387 __list_iterator& operator--()
389 #if _LIBCPP_DEBUG_LEVEL >= 2
390 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
391 "Attempted to decrement non-decrementable list::iterator");
393 __ptr_ = __ptr_->__prev_;
396 _LIBCPP_INLINE_VISIBILITY
397 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
399 friend _LIBCPP_INLINE_VISIBILITY
400 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
402 return __x.__ptr_ == __y.__ptr_;
404 friend _LIBCPP_INLINE_VISIBILITY
405 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
406 {return !(__x == __y);}
409 template <class _Tp, class _VoidPtr>
410 class _LIBCPP_TEMPLATE_VIS __list_const_iterator
412 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
413 typedef typename _NodeTraits::__link_pointer __link_pointer;
415 __link_pointer __ptr_;
417 #if _LIBCPP_DEBUG_LEVEL >= 2
418 _LIBCPP_INLINE_VISIBILITY
419 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
422 __get_db()->__insert_ic(this, __c);
425 _LIBCPP_INLINE_VISIBILITY
426 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
429 template<class, class> friend class list;
430 template<class, class> friend class __list_imp;
432 typedef bidirectional_iterator_tag iterator_category;
433 typedef _Tp value_type;
434 typedef const value_type& reference;
435 typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
436 typedef typename pointer_traits<pointer>::difference_type difference_type;
438 _LIBCPP_INLINE_VISIBILITY
439 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
441 #if _LIBCPP_DEBUG_LEVEL >= 2
442 __get_db()->__insert_i(this);
445 _LIBCPP_INLINE_VISIBILITY
446 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
449 #if _LIBCPP_DEBUG_LEVEL >= 2
450 __get_db()->__iterator_copy(this, &__p);
454 #if _LIBCPP_DEBUG_LEVEL >= 2
456 _LIBCPP_INLINE_VISIBILITY
457 __list_const_iterator(const __list_const_iterator& __p)
460 __get_db()->__iterator_copy(this, &__p);
463 _LIBCPP_INLINE_VISIBILITY
464 ~__list_const_iterator()
466 __get_db()->__erase_i(this);
469 _LIBCPP_INLINE_VISIBILITY
470 __list_const_iterator& operator=(const __list_const_iterator& __p)
474 __get_db()->__iterator_copy(this, &__p);
480 #endif // _LIBCPP_DEBUG_LEVEL >= 2
481 _LIBCPP_INLINE_VISIBILITY
482 reference operator*() const
484 #if _LIBCPP_DEBUG_LEVEL >= 2
485 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
486 "Attempted to dereference a non-dereferenceable list::const_iterator");
488 return __ptr_->__as_node()->__value_;
490 _LIBCPP_INLINE_VISIBILITY
491 pointer operator->() const
493 #if _LIBCPP_DEBUG_LEVEL >= 2
494 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
495 "Attempted to dereference a non-dereferenceable list::const_iterator");
497 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
500 _LIBCPP_INLINE_VISIBILITY
501 __list_const_iterator& operator++()
503 #if _LIBCPP_DEBUG_LEVEL >= 2
504 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
505 "Attempted to increment non-incrementable list::const_iterator");
507 __ptr_ = __ptr_->__next_;
510 _LIBCPP_INLINE_VISIBILITY
511 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
513 _LIBCPP_INLINE_VISIBILITY
514 __list_const_iterator& operator--()
516 #if _LIBCPP_DEBUG_LEVEL >= 2
517 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
518 "Attempted to decrement non-decrementable list::const_iterator");
520 __ptr_ = __ptr_->__prev_;
523 _LIBCPP_INLINE_VISIBILITY
524 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
526 friend _LIBCPP_INLINE_VISIBILITY
527 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
529 return __x.__ptr_ == __y.__ptr_;
531 friend _LIBCPP_INLINE_VISIBILITY
532 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
533 {return !(__x == __y);}
536 template <class _Tp, class _Alloc>
539 __list_imp(const __list_imp&);
540 __list_imp& operator=(const __list_imp&);
542 typedef _Alloc allocator_type;
543 typedef allocator_traits<allocator_type> __alloc_traits;
544 typedef typename __alloc_traits::size_type size_type;
546 typedef _Tp value_type;
547 typedef typename __alloc_traits::void_pointer __void_pointer;
548 typedef __list_iterator<value_type, __void_pointer> iterator;
549 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
550 typedef __list_node_base<value_type, __void_pointer> __node_base;
551 typedef __list_node<value_type, __void_pointer> __node;
552 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
553 typedef allocator_traits<__node_allocator> __node_alloc_traits;
554 typedef typename __node_alloc_traits::pointer __node_pointer;
555 typedef typename __node_alloc_traits::pointer __node_const_pointer;
556 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
557 typedef typename __node_pointer_traits::__link_pointer __link_pointer;
558 typedef __link_pointer __link_const_pointer;
559 typedef typename __alloc_traits::pointer pointer;
560 typedef typename __alloc_traits::const_pointer const_pointer;
561 typedef typename __alloc_traits::difference_type difference_type;
563 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
564 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
565 static_assert((!is_same<allocator_type, __node_allocator>::value),
566 "internal allocator type must differ from user-specified "
567 "type; otherwise overload resolution breaks");
570 __compressed_pair<size_type, __node_allocator> __size_alloc_;
572 _LIBCPP_INLINE_VISIBILITY
573 __link_pointer __end_as_link() const _NOEXCEPT {
574 return __node_pointer_traits::__unsafe_link_pointer_cast(
575 const_cast<__node_base&>(__end_).__self());
578 _LIBCPP_INLINE_VISIBILITY
579 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
580 _LIBCPP_INLINE_VISIBILITY
581 const size_type& __sz() const _NOEXCEPT
582 {return __size_alloc_.first();}
583 _LIBCPP_INLINE_VISIBILITY
584 __node_allocator& __node_alloc() _NOEXCEPT
585 {return __size_alloc_.second();}
586 _LIBCPP_INLINE_VISIBILITY
587 const __node_allocator& __node_alloc() const _NOEXCEPT
588 {return __size_alloc_.second();}
590 _LIBCPP_INLINE_VISIBILITY
591 size_type __node_alloc_max_size() const _NOEXCEPT {
592 return __node_alloc_traits::max_size(__node_alloc());
594 _LIBCPP_INLINE_VISIBILITY
595 static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
597 _LIBCPP_INLINE_VISIBILITY
599 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
600 _LIBCPP_INLINE_VISIBILITY
601 __list_imp(const allocator_type& __a);
602 _LIBCPP_INLINE_VISIBILITY
603 __list_imp(const __node_allocator& __a);
604 #ifndef _LIBCPP_CXX03_LANG
605 __list_imp(__node_allocator&& __a) _NOEXCEPT;
608 void clear() _NOEXCEPT;
609 _LIBCPP_INLINE_VISIBILITY
610 bool empty() const _NOEXCEPT {return __sz() == 0;}
612 _LIBCPP_INLINE_VISIBILITY
613 iterator begin() _NOEXCEPT
615 #if _LIBCPP_DEBUG_LEVEL >= 2
616 return iterator(__end_.__next_, this);
618 return iterator(__end_.__next_);
621 _LIBCPP_INLINE_VISIBILITY
622 const_iterator begin() const _NOEXCEPT
624 #if _LIBCPP_DEBUG_LEVEL >= 2
625 return const_iterator(__end_.__next_, this);
627 return const_iterator(__end_.__next_);
630 _LIBCPP_INLINE_VISIBILITY
631 iterator end() _NOEXCEPT
633 #if _LIBCPP_DEBUG_LEVEL >= 2
634 return iterator(__end_as_link(), this);
636 return iterator(__end_as_link());
639 _LIBCPP_INLINE_VISIBILITY
640 const_iterator end() const _NOEXCEPT
642 #if _LIBCPP_DEBUG_LEVEL >= 2
643 return const_iterator(__end_as_link(), this);
645 return const_iterator(__end_as_link());
649 void swap(__list_imp& __c)
650 #if _LIBCPP_STD_VER >= 14
653 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
654 __is_nothrow_swappable<allocator_type>::value);
657 _LIBCPP_INLINE_VISIBILITY
658 void __copy_assign_alloc(const __list_imp& __c)
659 {__copy_assign_alloc(__c, integral_constant<bool,
660 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
662 _LIBCPP_INLINE_VISIBILITY
663 void __move_assign_alloc(__list_imp& __c)
665 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
666 is_nothrow_move_assignable<__node_allocator>::value)
667 {__move_assign_alloc(__c, integral_constant<bool,
668 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
671 _LIBCPP_INLINE_VISIBILITY
672 void __copy_assign_alloc(const __list_imp& __c, true_type)
674 if (__node_alloc() != __c.__node_alloc())
676 __node_alloc() = __c.__node_alloc();
679 _LIBCPP_INLINE_VISIBILITY
680 void __copy_assign_alloc(const __list_imp&, false_type)
683 _LIBCPP_INLINE_VISIBILITY
684 void __move_assign_alloc(__list_imp& __c, true_type)
685 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
687 __node_alloc() = _VSTD::move(__c.__node_alloc());
690 _LIBCPP_INLINE_VISIBILITY
691 void __move_assign_alloc(__list_imp&, false_type)
695 _LIBCPP_INLINE_VISIBILITY
696 void __invalidate_all_iterators() {
697 #if _LIBCPP_DEBUG_LEVEL >= 2
698 __get_db()->__invalidate_all(this);
703 // Unlink nodes [__f, __l]
704 template <class _Tp, class _Alloc>
707 __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
710 __f->__prev_->__next_ = __l->__next_;
711 __l->__next_->__prev_ = __f->__prev_;
714 template <class _Tp, class _Alloc>
716 __list_imp<_Tp, _Alloc>::__list_imp()
717 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
722 template <class _Tp, class _Alloc>
724 __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
725 : __size_alloc_(0, __node_allocator(__a))
729 template <class _Tp, class _Alloc>
730 inline __list_imp<_Tp, _Alloc>::__list_imp(const __node_allocator& __a)
731 : __size_alloc_(0, __a) {}
733 #ifndef _LIBCPP_CXX03_LANG
734 template <class _Tp, class _Alloc>
735 inline __list_imp<_Tp, _Alloc>::__list_imp(__node_allocator&& __a) _NOEXCEPT
736 : __size_alloc_(0, std::move(__a)) {}
739 template <class _Tp, class _Alloc>
740 __list_imp<_Tp, _Alloc>::~__list_imp() {
742 #if _LIBCPP_DEBUG_LEVEL >= 2
743 __get_db()->__erase_c(this);
747 template <class _Tp, class _Alloc>
749 __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
753 __node_allocator& __na = __node_alloc();
754 __link_pointer __f = __end_.__next_;
755 __link_pointer __l = __end_as_link();
756 __unlink_nodes(__f, __l->__prev_);
760 __node_pointer __np = __f->__as_node();
762 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
763 __node_alloc_traits::deallocate(__na, __np, 1);
765 __invalidate_all_iterators();
769 template <class _Tp, class _Alloc>
771 __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
772 #if _LIBCPP_STD_VER >= 14
775 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
776 __is_nothrow_swappable<allocator_type>::value)
779 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
780 this->__node_alloc() == __c.__node_alloc(),
781 "list::swap: Either propagate_on_container_swap must be true"
782 " or the allocators must compare equal");
784 __swap_allocator(__node_alloc(), __c.__node_alloc());
785 swap(__sz(), __c.__sz());
786 swap(__end_, __c.__end_);
788 __end_.__next_ = __end_.__prev_ = __end_as_link();
790 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
792 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
794 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
796 #if _LIBCPP_DEBUG_LEVEL >= 2
797 __libcpp_db* __db = __get_db();
798 __c_node* __cn1 = __db->__find_c_and_lock(this);
799 __c_node* __cn2 = __db->__find_c(&__c);
800 std::swap(__cn1->beg_, __cn2->beg_);
801 std::swap(__cn1->end_, __cn2->end_);
802 std::swap(__cn1->cap_, __cn2->cap_);
803 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
806 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
807 if (__i->__ptr_ == __c.__end_as_link())
810 if (--__cn1->end_ != __p)
811 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
814 (*__p)->__c_ = __cn1;
816 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
819 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
820 if (__i->__ptr_ == __end_as_link())
823 if (--__cn2->end_ != __p)
824 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
827 (*__p)->__c_ = __cn2;
833 template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
834 class _LIBCPP_TEMPLATE_VIS list
835 : private __list_imp<_Tp, _Alloc>
837 typedef __list_imp<_Tp, _Alloc> base;
838 typedef typename base::__node __node;
839 typedef typename base::__node_allocator __node_allocator;
840 typedef typename base::__node_pointer __node_pointer;
841 typedef typename base::__node_alloc_traits __node_alloc_traits;
842 typedef typename base::__node_base __node_base;
843 typedef typename base::__node_base_pointer __node_base_pointer;
844 typedef typename base::__link_pointer __link_pointer;
847 typedef _Tp value_type;
848 typedef _Alloc allocator_type;
849 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
850 "Invalid allocator::value_type");
851 typedef value_type& reference;
852 typedef const value_type& const_reference;
853 typedef typename base::pointer pointer;
854 typedef typename base::const_pointer const_pointer;
855 typedef typename base::size_type size_type;
856 typedef typename base::difference_type difference_type;
857 typedef typename base::iterator iterator;
858 typedef typename base::const_iterator const_iterator;
859 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
860 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
862 _LIBCPP_INLINE_VISIBILITY
864 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
866 #if _LIBCPP_DEBUG_LEVEL >= 2
867 __get_db()->__insert_c(this);
870 _LIBCPP_INLINE_VISIBILITY
871 explicit list(const allocator_type& __a) : base(__a)
873 #if _LIBCPP_DEBUG_LEVEL >= 2
874 __get_db()->__insert_c(this);
877 explicit list(size_type __n);
878 #if _LIBCPP_STD_VER > 11
879 explicit list(size_type __n, const allocator_type& __a);
881 list(size_type __n, const value_type& __x);
882 list(size_type __n, const value_type& __x, const allocator_type& __a);
883 template <class _InpIter>
884 list(_InpIter __f, _InpIter __l,
885 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
886 template <class _InpIter>
887 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
888 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
890 list(const list& __c);
891 list(const list& __c, const allocator_type& __a);
892 _LIBCPP_INLINE_VISIBILITY
893 list& operator=(const list& __c);
894 #ifndef _LIBCPP_CXX03_LANG
895 list(initializer_list<value_type> __il);
896 list(initializer_list<value_type> __il, const allocator_type& __a);
898 _LIBCPP_INLINE_VISIBILITY
900 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
901 _LIBCPP_INLINE_VISIBILITY
902 list(list&& __c, const allocator_type& __a);
903 _LIBCPP_INLINE_VISIBILITY
904 list& operator=(list&& __c)
906 __node_alloc_traits::propagate_on_container_move_assignment::value &&
907 is_nothrow_move_assignable<__node_allocator>::value);
909 _LIBCPP_INLINE_VISIBILITY
910 list& operator=(initializer_list<value_type> __il)
911 {assign(__il.begin(), __il.end()); return *this;}
913 _LIBCPP_INLINE_VISIBILITY
914 void assign(initializer_list<value_type> __il)
915 {assign(__il.begin(), __il.end());}
916 #endif // _LIBCPP_CXX03_LANG
918 template <class _InpIter>
919 void assign(_InpIter __f, _InpIter __l,
920 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
921 void assign(size_type __n, const value_type& __x);
923 _LIBCPP_INLINE_VISIBILITY
924 allocator_type get_allocator() const _NOEXCEPT;
926 _LIBCPP_INLINE_VISIBILITY
927 size_type size() const _NOEXCEPT {return base::__sz();}
928 _LIBCPP_NODISCARD_AFTER_CXX17 _LIBCPP_INLINE_VISIBILITY
929 bool empty() const _NOEXCEPT {return base::empty();}
930 _LIBCPP_INLINE_VISIBILITY
931 size_type max_size() const _NOEXCEPT
933 return std::min<size_type>(
934 base::__node_alloc_max_size(),
935 numeric_limits<difference_type >::max());
938 _LIBCPP_INLINE_VISIBILITY
939 iterator begin() _NOEXCEPT {return base::begin();}
940 _LIBCPP_INLINE_VISIBILITY
941 const_iterator begin() const _NOEXCEPT {return base::begin();}
942 _LIBCPP_INLINE_VISIBILITY
943 iterator end() _NOEXCEPT {return base::end();}
944 _LIBCPP_INLINE_VISIBILITY
945 const_iterator end() const _NOEXCEPT {return base::end();}
946 _LIBCPP_INLINE_VISIBILITY
947 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
948 _LIBCPP_INLINE_VISIBILITY
949 const_iterator cend() const _NOEXCEPT {return base::end();}
951 _LIBCPP_INLINE_VISIBILITY
952 reverse_iterator rbegin() _NOEXCEPT
953 {return reverse_iterator(end());}
954 _LIBCPP_INLINE_VISIBILITY
955 const_reverse_iterator rbegin() const _NOEXCEPT
956 {return const_reverse_iterator(end());}
957 _LIBCPP_INLINE_VISIBILITY
958 reverse_iterator rend() _NOEXCEPT
959 {return reverse_iterator(begin());}
960 _LIBCPP_INLINE_VISIBILITY
961 const_reverse_iterator rend() const _NOEXCEPT
962 {return const_reverse_iterator(begin());}
963 _LIBCPP_INLINE_VISIBILITY
964 const_reverse_iterator crbegin() const _NOEXCEPT
965 {return const_reverse_iterator(end());}
966 _LIBCPP_INLINE_VISIBILITY
967 const_reverse_iterator crend() const _NOEXCEPT
968 {return const_reverse_iterator(begin());}
970 _LIBCPP_INLINE_VISIBILITY
973 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
974 return base::__end_.__next_->__as_node()->__value_;
976 _LIBCPP_INLINE_VISIBILITY
977 const_reference front() const
979 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
980 return base::__end_.__next_->__as_node()->__value_;
982 _LIBCPP_INLINE_VISIBILITY
985 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
986 return base::__end_.__prev_->__as_node()->__value_;
988 _LIBCPP_INLINE_VISIBILITY
989 const_reference back() const
991 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
992 return base::__end_.__prev_->__as_node()->__value_;
995 #ifndef _LIBCPP_CXX03_LANG
996 void push_front(value_type&& __x);
997 void push_back(value_type&& __x);
999 template <class... _Args>
1000 #if _LIBCPP_STD_VER > 14
1001 reference emplace_front(_Args&&... __args);
1003 void emplace_front(_Args&&... __args);
1005 template <class... _Args>
1006 #if _LIBCPP_STD_VER > 14
1007 reference emplace_back(_Args&&... __args);
1009 void emplace_back(_Args&&... __args);
1011 template <class... _Args>
1012 iterator emplace(const_iterator __p, _Args&&... __args);
1014 iterator insert(const_iterator __p, value_type&& __x);
1016 _LIBCPP_INLINE_VISIBILITY
1017 iterator insert(const_iterator __p, initializer_list<value_type> __il)
1018 {return insert(__p, __il.begin(), __il.end());}
1019 #endif // _LIBCPP_CXX03_LANG
1021 void push_front(const value_type& __x);
1022 void push_back(const value_type& __x);
1024 #ifndef _LIBCPP_CXX03_LANG
1025 template <class _Arg>
1026 _LIBCPP_INLINE_VISIBILITY
1027 void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); }
1029 _LIBCPP_INLINE_VISIBILITY
1030 void __emplace_back(value_type const& __arg) { push_back(__arg); }
1033 iterator insert(const_iterator __p, const value_type& __x);
1034 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
1035 template <class _InpIter>
1036 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
1037 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
1039 _LIBCPP_INLINE_VISIBILITY
1040 void swap(list& __c)
1041 #if _LIBCPP_STD_VER >= 14
1044 _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value ||
1045 __is_nothrow_swappable<__node_allocator>::value)
1048 _LIBCPP_INLINE_VISIBILITY
1049 void clear() _NOEXCEPT {base::clear();}
1054 iterator erase(const_iterator __p);
1055 iterator erase(const_iterator __f, const_iterator __l);
1057 void resize(size_type __n);
1058 void resize(size_type __n, const value_type& __x);
1060 void splice(const_iterator __p, list& __c);
1061 #ifndef _LIBCPP_CXX03_LANG
1062 _LIBCPP_INLINE_VISIBILITY
1063 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1064 _LIBCPP_INLINE_VISIBILITY
1065 void splice(const_iterator __p, list&& __c, const_iterator __i)
1066 {splice(__p, __c, __i);}
1067 _LIBCPP_INLINE_VISIBILITY
1068 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1069 {splice(__p, __c, __f, __l);}
1071 void splice(const_iterator __p, list& __c, const_iterator __i);
1072 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
1074 void remove(const value_type& __x);
1075 template <class _Pred> void remove_if(_Pred __pred);
1076 _LIBCPP_INLINE_VISIBILITY
1078 template <class _BinaryPred>
1079 void unique(_BinaryPred __binary_pred);
1080 _LIBCPP_INLINE_VISIBILITY
1081 void merge(list& __c);
1082 #ifndef _LIBCPP_CXX03_LANG
1083 _LIBCPP_INLINE_VISIBILITY
1084 void merge(list&& __c) {merge(__c);}
1086 template <class _Comp>
1087 _LIBCPP_INLINE_VISIBILITY
1088 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
1090 template <class _Comp>
1091 void merge(list& __c, _Comp __comp);
1093 _LIBCPP_INLINE_VISIBILITY
1095 template <class _Comp>
1096 _LIBCPP_INLINE_VISIBILITY
1097 void sort(_Comp __comp);
1099 void reverse() _NOEXCEPT;
1101 bool __invariants() const;
1103 typedef __allocator_destructor<__node_allocator> __node_destructor;
1104 typedef unique_ptr<__node, __node_destructor> __hold_pointer;
1106 _LIBCPP_INLINE_VISIBILITY
1107 __hold_pointer __allocate_node(__node_allocator& __na) {
1108 __node_pointer __p = __node_alloc_traits::allocate(__na, 1);
1109 __p->__prev_ = nullptr;
1110 return __hold_pointer(__p, __node_destructor(__na, 1));
1113 #if _LIBCPP_DEBUG_LEVEL >= 2
1115 bool __dereferenceable(const const_iterator* __i) const;
1116 bool __decrementable(const const_iterator* __i) const;
1117 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1118 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1120 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1123 _LIBCPP_INLINE_VISIBILITY
1124 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
1125 _LIBCPP_INLINE_VISIBILITY
1126 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
1127 _LIBCPP_INLINE_VISIBILITY
1128 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
1129 iterator __iterator(size_type __n);
1130 template <class _Comp>
1131 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1133 void __move_assign(list& __c, true_type)
1134 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
1135 void __move_assign(list& __c, false_type);
1138 #ifndef _LIBCPP_HAS_NO_DEDUCTION_GUIDES
1139 template<class _InputIterator,
1140 class _Alloc = typename std::allocator<typename iterator_traits<_InputIterator>::value_type>,
1141 class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
1143 list(_InputIterator, _InputIterator)
1144 -> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
1146 template<class _InputIterator,
1148 class = typename enable_if<__is_allocator<_Alloc>::value, void>::type
1150 list(_InputIterator, _InputIterator, _Alloc)
1151 -> list<typename iterator_traits<_InputIterator>::value_type, _Alloc>;
1154 // Link in nodes [__f, __l] just prior to __p
1155 template <class _Tp, class _Alloc>
1158 list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
1160 __p->__prev_->__next_ = __f;
1161 __f->__prev_ = __p->__prev_;
1166 // Link in nodes [__f, __l] at the front of the list
1167 template <class _Tp, class _Alloc>
1170 list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
1172 __f->__prev_ = base::__end_as_link();
1173 __l->__next_ = base::__end_.__next_;
1174 __l->__next_->__prev_ = __l;
1175 base::__end_.__next_ = __f;
1178 // Link in nodes [__f, __l] at the back of the list
1179 template <class _Tp, class _Alloc>
1182 list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
1184 __l->__next_ = base::__end_as_link();
1185 __f->__prev_ = base::__end_.__prev_;
1186 __f->__prev_->__next_ = __f;
1187 base::__end_.__prev_ = __l;
1191 template <class _Tp, class _Alloc>
1193 typename list<_Tp, _Alloc>::iterator
1194 list<_Tp, _Alloc>::__iterator(size_type __n)
1196 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1197 : _VSTD::prev(end(), base::__sz() - __n);
1200 template <class _Tp, class _Alloc>
1201 list<_Tp, _Alloc>::list(size_type __n)
1203 #if _LIBCPP_DEBUG_LEVEL >= 2
1204 __get_db()->__insert_c(this);
1206 for (; __n > 0; --__n)
1207 #ifndef _LIBCPP_CXX03_LANG
1210 push_back(value_type());
1214 #if _LIBCPP_STD_VER > 11
1215 template <class _Tp, class _Alloc>
1216 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1218 #if _LIBCPP_DEBUG_LEVEL >= 2
1219 __get_db()->__insert_c(this);
1221 for (; __n > 0; --__n)
1226 template <class _Tp, class _Alloc>
1227 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1229 #if _LIBCPP_DEBUG_LEVEL >= 2
1230 __get_db()->__insert_c(this);
1232 for (; __n > 0; --__n)
1236 template <class _Tp, class _Alloc>
1237 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1240 #if _LIBCPP_DEBUG_LEVEL >= 2
1241 __get_db()->__insert_c(this);
1243 for (; __n > 0; --__n)
1247 template <class _Tp, class _Alloc>
1248 template <class _InpIter>
1249 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1250 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1252 #if _LIBCPP_DEBUG_LEVEL >= 2
1253 __get_db()->__insert_c(this);
1255 for (; __f != __l; ++__f)
1256 __emplace_back(*__f);
1259 template <class _Tp, class _Alloc>
1260 template <class _InpIter>
1261 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1262 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1265 #if _LIBCPP_DEBUG_LEVEL >= 2
1266 __get_db()->__insert_c(this);
1268 for (; __f != __l; ++__f)
1269 __emplace_back(*__f);
1272 template <class _Tp, class _Alloc>
1273 list<_Tp, _Alloc>::list(const list& __c)
1274 : base(__node_alloc_traits::select_on_container_copy_construction(
1275 __c.__node_alloc())) {
1276 #if _LIBCPP_DEBUG_LEVEL >= 2
1277 __get_db()->__insert_c(this);
1279 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1283 template <class _Tp, class _Alloc>
1284 list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1287 #if _LIBCPP_DEBUG_LEVEL >= 2
1288 __get_db()->__insert_c(this);
1290 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1294 #ifndef _LIBCPP_CXX03_LANG
1296 template <class _Tp, class _Alloc>
1297 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1300 #if _LIBCPP_DEBUG_LEVEL >= 2
1301 __get_db()->__insert_c(this);
1303 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1304 __e = __il.end(); __i != __e; ++__i)
1308 template <class _Tp, class _Alloc>
1309 list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1311 #if _LIBCPP_DEBUG_LEVEL >= 2
1312 __get_db()->__insert_c(this);
1314 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1315 __e = __il.end(); __i != __e; ++__i)
1319 template <class _Tp, class _Alloc>
1320 inline list<_Tp, _Alloc>::list(list&& __c)
1321 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
1322 : base(_VSTD::move(__c.__node_alloc())) {
1323 #if _LIBCPP_DEBUG_LEVEL >= 2
1324 __get_db()->__insert_c(this);
1329 template <class _Tp, class _Alloc>
1331 list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1334 #if _LIBCPP_DEBUG_LEVEL >= 2
1335 __get_db()->__insert_c(this);
1337 if (__a == __c.get_allocator())
1341 typedef move_iterator<iterator> _Ip;
1342 assign(_Ip(__c.begin()), _Ip(__c.end()));
1346 template <class _Tp, class _Alloc>
1349 list<_Tp, _Alloc>::operator=(list&& __c)
1351 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1352 is_nothrow_move_assignable<__node_allocator>::value)
1354 __move_assign(__c, integral_constant<bool,
1355 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1359 template <class _Tp, class _Alloc>
1361 list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1363 if (base::__node_alloc() != __c.__node_alloc())
1365 typedef move_iterator<iterator> _Ip;
1366 assign(_Ip(__c.begin()), _Ip(__c.end()));
1369 __move_assign(__c, true_type());
1372 template <class _Tp, class _Alloc>
1374 list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
1375 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
1378 base::__move_assign_alloc(__c);
1382 #endif // _LIBCPP_CXX03_LANG
1384 template <class _Tp, class _Alloc>
1387 list<_Tp, _Alloc>::operator=(const list& __c)
1391 base::__copy_assign_alloc(__c);
1392 assign(__c.begin(), __c.end());
1397 template <class _Tp, class _Alloc>
1398 template <class _InpIter>
1400 list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1401 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1403 iterator __i = begin();
1404 iterator __e = end();
1405 for (; __f != __l && __i != __e; ++__f, ++__i)
1408 insert(__e, __f, __l);
1411 #if _LIBCPP_DEBUG_LEVEL >= 2
1412 __get_db()->__invalidate_all(this);
1416 template <class _Tp, class _Alloc>
1418 list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1420 iterator __i = begin();
1421 iterator __e = end();
1422 for (; __n > 0 && __i != __e; --__n, ++__i)
1425 insert(__e, __n, __x);
1428 #if _LIBCPP_DEBUG_LEVEL >= 2
1429 __get_db()->__invalidate_all(this);
1433 template <class _Tp, class _Alloc>
1436 list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
1438 return allocator_type(base::__node_alloc());
1441 template <class _Tp, class _Alloc>
1442 typename list<_Tp, _Alloc>::iterator
1443 list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1445 #if _LIBCPP_DEBUG_LEVEL >= 2
1446 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1447 "list::insert(iterator, x) called with an iterator not"
1448 " referring to this list");
1450 __node_allocator& __na = base::__node_alloc();
1451 __hold_pointer __hold = __allocate_node(__na);
1452 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1453 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
1455 #if _LIBCPP_DEBUG_LEVEL >= 2
1456 return iterator(__hold.release()->__as_link(), this);
1458 return iterator(__hold.release()->__as_link());
1462 template <class _Tp, class _Alloc>
1463 typename list<_Tp, _Alloc>::iterator
1464 list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1466 #if _LIBCPP_DEBUG_LEVEL >= 2
1467 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1468 "list::insert(iterator, n, x) called with an iterator not"
1469 " referring to this list");
1470 iterator __r(__p.__ptr_, this);
1472 iterator __r(__p.__ptr_);
1477 __node_allocator& __na = base::__node_alloc();
1478 __hold_pointer __hold = __allocate_node(__na);
1479 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1481 #if _LIBCPP_DEBUG_LEVEL >= 2
1482 __r = iterator(__hold->__as_link(), this);
1484 __r = iterator(__hold->__as_link());
1488 #ifndef _LIBCPP_NO_EXCEPTIONS
1491 #endif // _LIBCPP_NO_EXCEPTIONS
1492 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1494 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1495 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1496 __e.__ptr_->__next_ = __hold->__as_link();
1497 __hold->__prev_ = __e.__ptr_;
1500 #ifndef _LIBCPP_NO_EXCEPTIONS
1506 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1507 __link_pointer __prev = __e.__ptr_->__prev_;
1508 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1511 #if _LIBCPP_DEBUG_LEVEL >= 2
1512 __e = iterator(__prev, this);
1514 __e = iterator(__prev);
1519 #endif // _LIBCPP_NO_EXCEPTIONS
1520 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1521 base::__sz() += __ds;
1526 template <class _Tp, class _Alloc>
1527 template <class _InpIter>
1528 typename list<_Tp, _Alloc>::iterator
1529 list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1530 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1532 #if _LIBCPP_DEBUG_LEVEL >= 2
1533 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1534 "list::insert(iterator, range) called with an iterator not"
1535 " referring to this list");
1536 iterator __r(__p.__ptr_, this);
1538 iterator __r(__p.__ptr_);
1543 __node_allocator& __na = base::__node_alloc();
1544 __hold_pointer __hold = __allocate_node(__na);
1545 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1547 #if _LIBCPP_DEBUG_LEVEL >= 2
1548 __r = iterator(__hold.get()->__as_link(), this);
1550 __r = iterator(__hold.get()->__as_link());
1554 #ifndef _LIBCPP_NO_EXCEPTIONS
1557 #endif // _LIBCPP_NO_EXCEPTIONS
1558 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
1560 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1561 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1562 __e.__ptr_->__next_ = __hold.get()->__as_link();
1563 __hold->__prev_ = __e.__ptr_;
1566 #ifndef _LIBCPP_NO_EXCEPTIONS
1572 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1573 __link_pointer __prev = __e.__ptr_->__prev_;
1574 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1577 #if _LIBCPP_DEBUG_LEVEL >= 2
1578 __e = iterator(__prev, this);
1580 __e = iterator(__prev);
1585 #endif // _LIBCPP_NO_EXCEPTIONS
1586 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1587 base::__sz() += __ds;
1592 template <class _Tp, class _Alloc>
1594 list<_Tp, _Alloc>::push_front(const value_type& __x)
1596 __node_allocator& __na = base::__node_alloc();
1597 __hold_pointer __hold = __allocate_node(__na);
1598 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1599 __link_pointer __nl = __hold->__as_link();
1600 __link_nodes_at_front(__nl, __nl);
1605 template <class _Tp, class _Alloc>
1607 list<_Tp, _Alloc>::push_back(const value_type& __x)
1609 __node_allocator& __na = base::__node_alloc();
1610 __hold_pointer __hold = __allocate_node(__na);
1611 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1612 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
1617 #ifndef _LIBCPP_CXX03_LANG
1619 template <class _Tp, class _Alloc>
1621 list<_Tp, _Alloc>::push_front(value_type&& __x)
1623 __node_allocator& __na = base::__node_alloc();
1624 __hold_pointer __hold = __allocate_node(__na);
1625 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1626 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
1631 template <class _Tp, class _Alloc>
1633 list<_Tp, _Alloc>::push_back(value_type&& __x)
1635 __node_allocator& __na = base::__node_alloc();
1636 __hold_pointer __hold = __allocate_node(__na);
1637 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1638 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
1643 template <class _Tp, class _Alloc>
1644 template <class... _Args>
1645 #if _LIBCPP_STD_VER > 14
1646 typename list<_Tp, _Alloc>::reference
1650 list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1652 __node_allocator& __na = base::__node_alloc();
1653 __hold_pointer __hold = __allocate_node(__na);
1654 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1655 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
1657 #if _LIBCPP_STD_VER > 14
1658 return __hold.release()->__value_;
1664 template <class _Tp, class _Alloc>
1665 template <class... _Args>
1666 #if _LIBCPP_STD_VER > 14
1667 typename list<_Tp, _Alloc>::reference
1671 list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1673 __node_allocator& __na = base::__node_alloc();
1674 __hold_pointer __hold = __allocate_node(__na);
1675 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1676 __link_pointer __nl = __hold->__as_link();
1677 __link_nodes_at_back(__nl, __nl);
1679 #if _LIBCPP_STD_VER > 14
1680 return __hold.release()->__value_;
1686 template <class _Tp, class _Alloc>
1687 template <class... _Args>
1688 typename list<_Tp, _Alloc>::iterator
1689 list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1691 #if _LIBCPP_DEBUG_LEVEL >= 2
1692 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1693 "list::emplace(iterator, args...) called with an iterator not"
1694 " referring to this list");
1696 __node_allocator& __na = base::__node_alloc();
1697 __hold_pointer __hold = __allocate_node(__na);
1698 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1699 __link_pointer __nl = __hold.get()->__as_link();
1700 __link_nodes(__p.__ptr_, __nl, __nl);
1703 #if _LIBCPP_DEBUG_LEVEL >= 2
1704 return iterator(__nl, this);
1706 return iterator(__nl);
1710 template <class _Tp, class _Alloc>
1711 typename list<_Tp, _Alloc>::iterator
1712 list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1714 #if _LIBCPP_DEBUG_LEVEL >= 2
1715 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1716 "list::insert(iterator, x) called with an iterator not"
1717 " referring to this list");
1719 __node_allocator& __na = base::__node_alloc();
1720 __hold_pointer __hold = __allocate_node(__na);
1721 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1722 __link_pointer __nl = __hold->__as_link();
1723 __link_nodes(__p.__ptr_, __nl, __nl);
1726 #if _LIBCPP_DEBUG_LEVEL >= 2
1727 return iterator(__nl, this);
1729 return iterator(__nl);
1733 #endif // _LIBCPP_CXX03_LANG
1735 template <class _Tp, class _Alloc>
1737 list<_Tp, _Alloc>::pop_front()
1739 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
1740 __node_allocator& __na = base::__node_alloc();
1741 __link_pointer __n = base::__end_.__next_;
1742 base::__unlink_nodes(__n, __n);
1744 #if _LIBCPP_DEBUG_LEVEL >= 2
1745 __c_node* __c = __get_db()->__find_c_and_lock(this);
1746 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1749 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1750 if (__i->__ptr_ == __n)
1752 (*__p)->__c_ = nullptr;
1753 if (--__c->end_ != __p)
1754 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1757 __get_db()->unlock();
1759 __node_pointer __np = __n->__as_node();
1760 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1761 __node_alloc_traits::deallocate(__na, __np, 1);
1764 template <class _Tp, class _Alloc>
1766 list<_Tp, _Alloc>::pop_back()
1768 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
1769 __node_allocator& __na = base::__node_alloc();
1770 __link_pointer __n = base::__end_.__prev_;
1771 base::__unlink_nodes(__n, __n);
1773 #if _LIBCPP_DEBUG_LEVEL >= 2
1774 __c_node* __c = __get_db()->__find_c_and_lock(this);
1775 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1778 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1779 if (__i->__ptr_ == __n)
1781 (*__p)->__c_ = nullptr;
1782 if (--__c->end_ != __p)
1783 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1786 __get_db()->unlock();
1788 __node_pointer __np = __n->__as_node();
1789 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1790 __node_alloc_traits::deallocate(__na, __np, 1);
1793 template <class _Tp, class _Alloc>
1794 typename list<_Tp, _Alloc>::iterator
1795 list<_Tp, _Alloc>::erase(const_iterator __p)
1797 #if _LIBCPP_DEBUG_LEVEL >= 2
1798 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1799 "list::erase(iterator) called with an iterator not"
1800 " referring to this list");
1802 _LIBCPP_ASSERT(__p != end(),
1803 "list::erase(iterator) called with a non-dereferenceable iterator");
1804 __node_allocator& __na = base::__node_alloc();
1805 __link_pointer __n = __p.__ptr_;
1806 __link_pointer __r = __n->__next_;
1807 base::__unlink_nodes(__n, __n);
1809 #if _LIBCPP_DEBUG_LEVEL >= 2
1810 __c_node* __c = __get_db()->__find_c_and_lock(this);
1811 for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
1814 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
1815 if (__i->__ptr_ == __n)
1817 (*__ip)->__c_ = nullptr;
1818 if (--__c->end_ != __ip)
1819 memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
1822 __get_db()->unlock();
1824 __node_pointer __np = __n->__as_node();
1825 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1826 __node_alloc_traits::deallocate(__na, __np, 1);
1827 #if _LIBCPP_DEBUG_LEVEL >= 2
1828 return iterator(__r, this);
1830 return iterator(__r);
1834 template <class _Tp, class _Alloc>
1835 typename list<_Tp, _Alloc>::iterator
1836 list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1838 #if _LIBCPP_DEBUG_LEVEL >= 2
1839 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1840 "list::erase(iterator, iterator) called with an iterator not"
1841 " referring to this list");
1842 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
1843 "list::erase(iterator, iterator) called with an iterator not"
1844 " referring to this list");
1848 __node_allocator& __na = base::__node_alloc();
1849 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1852 __link_pointer __n = __f.__ptr_;
1855 #if _LIBCPP_DEBUG_LEVEL >= 2
1856 __c_node* __c = __get_db()->__find_c_and_lock(this);
1857 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1860 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1861 if (__i->__ptr_ == __n)
1863 (*__p)->__c_ = nullptr;
1864 if (--__c->end_ != __p)
1865 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1868 __get_db()->unlock();
1870 __node_pointer __np = __n->__as_node();
1871 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1872 __node_alloc_traits::deallocate(__na, __np, 1);
1875 #if _LIBCPP_DEBUG_LEVEL >= 2
1876 return iterator(__l.__ptr_, this);
1878 return iterator(__l.__ptr_);
1882 template <class _Tp, class _Alloc>
1884 list<_Tp, _Alloc>::resize(size_type __n)
1886 if (__n < base::__sz())
1887 erase(__iterator(__n), end());
1888 else if (__n > base::__sz())
1890 __n -= base::__sz();
1892 __node_allocator& __na = base::__node_alloc();
1893 __hold_pointer __hold = __allocate_node(__na);
1894 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1896 #if _LIBCPP_DEBUG_LEVEL >= 2
1897 iterator __r = iterator(__hold.release()->__as_link(), this);
1899 iterator __r = iterator(__hold.release()->__as_link());
1902 #ifndef _LIBCPP_NO_EXCEPTIONS
1905 #endif // _LIBCPP_NO_EXCEPTIONS
1906 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1908 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1909 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1910 __e.__ptr_->__next_ = __hold.get()->__as_link();
1911 __hold->__prev_ = __e.__ptr_;
1914 #ifndef _LIBCPP_NO_EXCEPTIONS
1920 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1921 __link_pointer __prev = __e.__ptr_->__prev_;
1922 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1925 #if _LIBCPP_DEBUG_LEVEL >= 2
1926 __e = iterator(__prev, this);
1928 __e = iterator(__prev);
1933 #endif // _LIBCPP_NO_EXCEPTIONS
1934 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1935 base::__sz() += __ds;
1939 template <class _Tp, class _Alloc>
1941 list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1943 if (__n < base::__sz())
1944 erase(__iterator(__n), end());
1945 else if (__n > base::__sz())
1947 __n -= base::__sz();
1949 __node_allocator& __na = base::__node_alloc();
1950 __hold_pointer __hold = __allocate_node(__na);
1951 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1953 __link_pointer __nl = __hold.release()->__as_link();
1954 #if _LIBCPP_DEBUG_LEVEL >= 2
1955 iterator __r = iterator(__nl, this);
1957 iterator __r = iterator(__nl);
1960 #ifndef _LIBCPP_NO_EXCEPTIONS
1963 #endif // _LIBCPP_NO_EXCEPTIONS
1964 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1966 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1967 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1968 __e.__ptr_->__next_ = __hold.get()->__as_link();
1969 __hold->__prev_ = __e.__ptr_;
1972 #ifndef _LIBCPP_NO_EXCEPTIONS
1978 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1979 __link_pointer __prev = __e.__ptr_->__prev_;
1980 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1983 #if _LIBCPP_DEBUG_LEVEL >= 2
1984 __e = iterator(__prev, this);
1986 __e = iterator(__prev);
1991 #endif // _LIBCPP_NO_EXCEPTIONS
1992 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1993 base::__sz() += __ds;
1997 template <class _Tp, class _Alloc>
1999 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
2001 _LIBCPP_ASSERT(this != &__c,
2002 "list::splice(iterator, list) called with this == &list");
2003 #if _LIBCPP_DEBUG_LEVEL >= 2
2004 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2005 "list::splice(iterator, list) called with an iterator not"
2006 " referring to this list");
2010 __link_pointer __f = __c.__end_.__next_;
2011 __link_pointer __l = __c.__end_.__prev_;
2012 base::__unlink_nodes(__f, __l);
2013 __link_nodes(__p.__ptr_, __f, __l);
2014 base::__sz() += __c.__sz();
2016 #if _LIBCPP_DEBUG_LEVEL >= 2
2017 __libcpp_db* __db = __get_db();
2018 __c_node* __cn1 = __db->__find_c_and_lock(this);
2019 __c_node* __cn2 = __db->__find_c(&__c);
2020 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
2023 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
2024 if (__i->__ptr_ != __c.__end_as_link())
2026 __cn1->__add(*__ip);
2027 (*__ip)->__c_ = __cn1;
2028 if (--__cn2->end_ != __ip)
2029 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2037 template <class _Tp, class _Alloc>
2039 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
2041 #if _LIBCPP_DEBUG_LEVEL >= 2
2042 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2043 "list::splice(iterator, list, iterator) called with first iterator not"
2044 " referring to this list");
2045 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
2046 "list::splice(iterator, list, iterator) called with second iterator not"
2047 " referring to list argument");
2048 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
2049 "list::splice(iterator, list, iterator) called with second iterator not"
2052 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
2054 __link_pointer __f = __i.__ptr_;
2055 base::__unlink_nodes(__f, __f);
2056 __link_nodes(__p.__ptr_, __f, __f);
2059 #if _LIBCPP_DEBUG_LEVEL >= 2
2060 __libcpp_db* __db = __get_db();
2061 __c_node* __cn1 = __db->__find_c_and_lock(this);
2062 __c_node* __cn2 = __db->__find_c(&__c);
2063 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
2066 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
2067 if (__j->__ptr_ == __f)
2069 __cn1->__add(*__ip);
2070 (*__ip)->__c_ = __cn1;
2071 if (--__cn2->end_ != __ip)
2072 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2080 template <class _Tp, class _Alloc>
2082 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
2084 #if _LIBCPP_DEBUG_LEVEL >= 2
2085 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2086 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2087 " referring to this list");
2088 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2089 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2090 " referring to list argument");
2093 for (const_iterator __i = __f; __i != __l; ++__i)
2094 _LIBCPP_ASSERT(__i != __p,
2095 "list::splice(iterator, list, iterator, iterator)"
2096 " called with the first iterator within the range"
2097 " of the second and third iterators");
2102 __link_pointer __first = __f.__ptr_;
2104 __link_pointer __last = __l.__ptr_;
2107 size_type __s = _VSTD::distance(__f, __l) + 1;
2109 base::__sz() += __s;
2111 base::__unlink_nodes(__first, __last);
2112 __link_nodes(__p.__ptr_, __first, __last);
2113 #if _LIBCPP_DEBUG_LEVEL >= 2
2114 __libcpp_db* __db = __get_db();
2115 __c_node* __cn1 = __db->__find_c_and_lock(this);
2116 __c_node* __cn2 = __db->__find_c(&__c);
2117 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
2120 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
2121 for (__link_pointer __k = __f.__ptr_;
2122 __k != __l.__ptr_; __k = __k->__next_)
2124 if (__j->__ptr_ == __k)
2126 __cn1->__add(*__ip);
2127 (*__ip)->__c_ = __cn1;
2128 if (--__cn2->end_ != __ip)
2129 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2138 template <class _Tp, class _Alloc>
2140 list<_Tp, _Alloc>::remove(const value_type& __x)
2142 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
2143 for (const_iterator __i = begin(), __e = end(); __i != __e;)
2147 const_iterator __j = _VSTD::next(__i);
2148 for (; __j != __e && *__j == __x; ++__j)
2150 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2160 template <class _Tp, class _Alloc>
2161 template <class _Pred>
2163 list<_Tp, _Alloc>::remove_if(_Pred __pred)
2165 for (iterator __i = begin(), __e = end(); __i != __e;)
2169 iterator __j = _VSTD::next(__i);
2170 for (; __j != __e && __pred(*__j); ++__j)
2172 __i = erase(__i, __j);
2181 template <class _Tp, class _Alloc>
2184 list<_Tp, _Alloc>::unique()
2186 unique(__equal_to<value_type>());
2189 template <class _Tp, class _Alloc>
2190 template <class _BinaryPred>
2192 list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2194 for (iterator __i = begin(), __e = end(); __i != __e;)
2196 iterator __j = _VSTD::next(__i);
2197 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2200 __i = erase(__i, __j);
2204 template <class _Tp, class _Alloc>
2207 list<_Tp, _Alloc>::merge(list& __c)
2209 merge(__c, __less<value_type>());
2212 template <class _Tp, class _Alloc>
2213 template <class _Comp>
2215 list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2217 if (this != _VSTD::addressof(__c))
2219 iterator __f1 = begin();
2220 iterator __e1 = end();
2221 iterator __f2 = __c.begin();
2222 iterator __e2 = __c.end();
2223 while (__f1 != __e1 && __f2 != __e2)
2225 if (__comp(*__f2, *__f1))
2228 iterator __m2 = _VSTD::next(__f2);
2229 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2231 base::__sz() += __ds;
2233 __link_pointer __f = __f2.__ptr_;
2234 __link_pointer __l = __m2.__ptr_->__prev_;
2236 base::__unlink_nodes(__f, __l);
2237 __m2 = _VSTD::next(__f1);
2238 __link_nodes(__f1.__ptr_, __f, __l);
2245 #if _LIBCPP_DEBUG_LEVEL >= 2
2246 __libcpp_db* __db = __get_db();
2247 __c_node* __cn1 = __db->__find_c_and_lock(this);
2248 __c_node* __cn2 = __db->__find_c(&__c);
2249 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2252 iterator* __i = static_cast<iterator*>((*__p)->__i_);
2253 if (__i->__ptr_ != __c.__end_as_link())
2256 (*__p)->__c_ = __cn1;
2257 if (--__cn2->end_ != __p)
2258 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2266 template <class _Tp, class _Alloc>
2269 list<_Tp, _Alloc>::sort()
2271 sort(__less<value_type>());
2274 template <class _Tp, class _Alloc>
2275 template <class _Comp>
2278 list<_Tp, _Alloc>::sort(_Comp __comp)
2280 __sort(begin(), end(), base::__sz(), __comp);
2283 template <class _Tp, class _Alloc>
2284 template <class _Comp>
2285 typename list<_Tp, _Alloc>::iterator
2286 list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2294 if (__comp(*--__e2, *__f1))
2296 __link_pointer __f = __e2.__ptr_;
2297 base::__unlink_nodes(__f, __f);
2298 __link_nodes(__f1.__ptr_, __f, __f);
2303 size_type __n2 = __n / 2;
2304 iterator __e1 = _VSTD::next(__f1, __n2);
2305 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2306 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2307 if (__comp(*__f2, *__f1))
2309 iterator __m2 = _VSTD::next(__f2);
2310 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2312 __link_pointer __f = __f2.__ptr_;
2313 __link_pointer __l = __m2.__ptr_->__prev_;
2316 base::__unlink_nodes(__f, __l);
2317 __m2 = _VSTD::next(__f1);
2318 __link_nodes(__f1.__ptr_, __f, __l);
2323 while (__f1 != __e1 && __f2 != __e2)
2325 if (__comp(*__f2, *__f1))
2327 iterator __m2 = _VSTD::next(__f2);
2328 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2330 __link_pointer __f = __f2.__ptr_;
2331 __link_pointer __l = __m2.__ptr_->__prev_;
2335 base::__unlink_nodes(__f, __l);
2336 __m2 = _VSTD::next(__f1);
2337 __link_nodes(__f1.__ptr_, __f, __l);
2346 template <class _Tp, class _Alloc>
2348 list<_Tp, _Alloc>::reverse() _NOEXCEPT
2350 if (base::__sz() > 1)
2352 iterator __e = end();
2353 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2355 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
2356 __i.__ptr_ = __i.__ptr_->__prev_;
2358 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
2362 template <class _Tp, class _Alloc>
2364 list<_Tp, _Alloc>::__invariants() const
2366 return size() == _VSTD::distance(begin(), end());
2369 #if _LIBCPP_DEBUG_LEVEL >= 2
2371 template <class _Tp, class _Alloc>
2373 list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2375 return __i->__ptr_ != this->__end_as_link();
2378 template <class _Tp, class _Alloc>
2380 list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2382 return !empty() && __i->__ptr_ != base::__end_.__next_;
2385 template <class _Tp, class _Alloc>
2387 list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2392 template <class _Tp, class _Alloc>
2394 list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2399 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2401 template <class _Tp, class _Alloc>
2402 inline _LIBCPP_INLINE_VISIBILITY
2404 operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2406 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2409 template <class _Tp, class _Alloc>
2410 inline _LIBCPP_INLINE_VISIBILITY
2412 operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2414 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2417 template <class _Tp, class _Alloc>
2418 inline _LIBCPP_INLINE_VISIBILITY
2420 operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2422 return !(__x == __y);
2425 template <class _Tp, class _Alloc>
2426 inline _LIBCPP_INLINE_VISIBILITY
2428 operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2433 template <class _Tp, class _Alloc>
2434 inline _LIBCPP_INLINE_VISIBILITY
2436 operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2438 return !(__x < __y);
2441 template <class _Tp, class _Alloc>
2442 inline _LIBCPP_INLINE_VISIBILITY
2444 operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2446 return !(__y < __x);
2449 template <class _Tp, class _Alloc>
2450 inline _LIBCPP_INLINE_VISIBILITY
2452 swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
2453 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2458 #if _LIBCPP_STD_VER > 17
2459 template <class _Tp, class _Allocator, class _Predicate>
2460 inline _LIBCPP_INLINE_VISIBILITY
2461 void erase_if(list<_Tp, _Allocator>& __c, _Predicate __pred)
2462 { __c.remove_if(__pred); }
2464 template <class _Tp, class _Allocator, class _Up>
2465 inline _LIBCPP_INLINE_VISIBILITY
2466 void erase(list<_Tp, _Allocator>& __c, const _Up& __v)
2467 { _VSTD::erase_if(__c, [&](auto& __elem) { return __elem == __v; }); }
2470 _LIBCPP_END_NAMESPACE_STD
2474 #endif // _LIBCPP_LIST