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 void emplace_front(Args&&... args);
98 template <class... Args>
99 void emplace_back(Args&&... args);
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_type::propagate_on_container_swap::value ||
122 __is_nothrow_swappable<allocator_type>::value);
123 void clear() noexcept;
125 void splice(const_iterator position, list& x);
126 void splice(const_iterator position, list&& x);
127 void splice(const_iterator position, list& x, const_iterator i);
128 void splice(const_iterator position, list&& x, const_iterator i);
129 void splice(const_iterator position, list& x, const_iterator first,
130 const_iterator last);
131 void splice(const_iterator position, list&& x, const_iterator first,
132 const_iterator last);
134 void remove(const value_type& value);
135 template <class Pred> void remove_if(Pred pred);
137 template <class BinaryPredicate>
138 void unique(BinaryPredicate binary_pred);
140 void merge(list&& x);
141 template <class Compare>
142 void merge(list& x, Compare comp);
143 template <class Compare>
144 void merge(list&& x, Compare comp);
146 template <class Compare>
147 void sort(Compare comp);
148 void reverse() noexcept;
151 template <class T, class Alloc>
152 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
153 template <class T, class Alloc>
154 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
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);
164 template <class T, class Alloc>
165 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
166 noexcept(noexcept(x.swap(y)));
176 #include <initializer_list>
180 #include <__undef_min_max>
184 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
185 #pragma GCC system_header
188 _LIBCPP_BEGIN_NAMESPACE_STD
190 template <class _Tp, class _VoidPtr> struct __list_node;
192 template <class _Tp, class _VoidPtr>
193 struct __list_node_base
195 typedef typename pointer_traits<_VoidPtr>::template
196 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
197 rebind<__list_node<_Tp, _VoidPtr> > pointer;
199 rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
202 typedef typename pointer_traits<_VoidPtr>::template
203 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
204 rebind<__list_node_base> __base_pointer;
206 rebind<__list_node_base>::other __base_pointer;
212 _LIBCPP_INLINE_VISIBILITY
213 __list_node_base() : __prev_(__self()), __next_(__self()) {}
215 _LIBCPP_INLINE_VISIBILITY
218 return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
222 template <class _Tp, class _VoidPtr>
224 : public __list_node_base<_Tp, _VoidPtr>
229 template <class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS_ONLY list;
230 template <class _Tp, class _Alloc> class __list_imp;
231 template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
233 template <class _Tp, class _VoidPtr>
234 class _LIBCPP_TYPE_VIS_ONLY __list_iterator
236 typedef typename pointer_traits<_VoidPtr>::template
237 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
238 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
240 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
243 __node_pointer __ptr_;
245 #if _LIBCPP_DEBUG_LEVEL >= 2
246 _LIBCPP_INLINE_VISIBILITY
247 explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
250 __get_db()->__insert_ic(this, __c);
253 _LIBCPP_INLINE_VISIBILITY
254 explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
259 template<class, class> friend class list;
260 template<class, class> friend class __list_imp;
261 template<class, class> friend class __list_const_iterator;
263 typedef bidirectional_iterator_tag iterator_category;
264 typedef _Tp value_type;
265 typedef value_type& reference;
266 typedef typename pointer_traits<_VoidPtr>::template
267 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
270 rebind<value_type>::other
273 typedef typename pointer_traits<pointer>::difference_type difference_type;
275 _LIBCPP_INLINE_VISIBILITY
276 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
278 #if _LIBCPP_DEBUG_LEVEL >= 2
279 __get_db()->__insert_i(this);
283 #if _LIBCPP_DEBUG_LEVEL >= 2
285 _LIBCPP_INLINE_VISIBILITY
286 __list_iterator(const __list_iterator& __p)
289 __get_db()->__iterator_copy(this, &__p);
292 _LIBCPP_INLINE_VISIBILITY
295 __get_db()->__erase_i(this);
298 _LIBCPP_INLINE_VISIBILITY
299 __list_iterator& operator=(const __list_iterator& __p)
303 __get_db()->__iterator_copy(this, &__p);
309 #endif // _LIBCPP_DEBUG_LEVEL >= 2
311 _LIBCPP_INLINE_VISIBILITY
312 reference operator*() const
314 #if _LIBCPP_DEBUG_LEVEL >= 2
315 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
316 "Attempted to dereference a non-dereferenceable list::iterator");
318 return __ptr_->__value_;
320 _LIBCPP_INLINE_VISIBILITY
321 pointer operator->() const
323 #if _LIBCPP_DEBUG_LEVEL >= 2
324 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
325 "Attempted to dereference a non-dereferenceable list::iterator");
327 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
330 _LIBCPP_INLINE_VISIBILITY
331 __list_iterator& operator++()
333 #if _LIBCPP_DEBUG_LEVEL >= 2
334 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
335 "Attempted to increment non-incrementable list::iterator");
337 __ptr_ = __ptr_->__next_;
340 _LIBCPP_INLINE_VISIBILITY
341 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
343 _LIBCPP_INLINE_VISIBILITY
344 __list_iterator& operator--()
346 #if _LIBCPP_DEBUG_LEVEL >= 2
347 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
348 "Attempted to decrement non-decrementable list::iterator");
350 __ptr_ = __ptr_->__prev_;
353 _LIBCPP_INLINE_VISIBILITY
354 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
356 friend _LIBCPP_INLINE_VISIBILITY
357 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
359 return __x.__ptr_ == __y.__ptr_;
361 friend _LIBCPP_INLINE_VISIBILITY
362 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
363 {return !(__x == __y);}
366 template <class _Tp, class _VoidPtr>
367 class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
369 typedef typename pointer_traits<_VoidPtr>::template
370 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
371 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
373 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
376 __node_pointer __ptr_;
378 #if _LIBCPP_DEBUG_LEVEL >= 2
379 _LIBCPP_INLINE_VISIBILITY
380 explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
383 __get_db()->__insert_ic(this, __c);
386 _LIBCPP_INLINE_VISIBILITY
387 explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
390 template<class, class> friend class list;
391 template<class, class> friend class __list_imp;
393 typedef bidirectional_iterator_tag iterator_category;
394 typedef _Tp value_type;
395 typedef const value_type& reference;
396 typedef typename pointer_traits<_VoidPtr>::template
397 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
398 rebind<const value_type>
400 rebind<const value_type>::other
403 typedef typename pointer_traits<pointer>::difference_type difference_type;
405 _LIBCPP_INLINE_VISIBILITY
406 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
408 #if _LIBCPP_DEBUG_LEVEL >= 2
409 __get_db()->__insert_i(this);
412 _LIBCPP_INLINE_VISIBILITY
413 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
416 #if _LIBCPP_DEBUG_LEVEL >= 2
417 __get_db()->__iterator_copy(this, &__p);
421 #if _LIBCPP_DEBUG_LEVEL >= 2
423 _LIBCPP_INLINE_VISIBILITY
424 __list_const_iterator(const __list_const_iterator& __p)
427 __get_db()->__iterator_copy(this, &__p);
430 _LIBCPP_INLINE_VISIBILITY
431 ~__list_const_iterator()
433 __get_db()->__erase_i(this);
436 _LIBCPP_INLINE_VISIBILITY
437 __list_const_iterator& operator=(const __list_const_iterator& __p)
441 __get_db()->__iterator_copy(this, &__p);
447 #endif // _LIBCPP_DEBUG_LEVEL >= 2
448 _LIBCPP_INLINE_VISIBILITY
449 reference operator*() const
451 #if _LIBCPP_DEBUG_LEVEL >= 2
452 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
453 "Attempted to dereference a non-dereferenceable list::const_iterator");
455 return __ptr_->__value_;
457 _LIBCPP_INLINE_VISIBILITY
458 pointer operator->() const
460 #if _LIBCPP_DEBUG_LEVEL >= 2
461 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
462 "Attempted to dereference a non-dereferenceable list::iterator");
464 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
467 _LIBCPP_INLINE_VISIBILITY
468 __list_const_iterator& operator++()
470 #if _LIBCPP_DEBUG_LEVEL >= 2
471 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
472 "Attempted to increment non-incrementable list::const_iterator");
474 __ptr_ = __ptr_->__next_;
477 _LIBCPP_INLINE_VISIBILITY
478 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
480 _LIBCPP_INLINE_VISIBILITY
481 __list_const_iterator& operator--()
483 #if _LIBCPP_DEBUG_LEVEL >= 2
484 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
485 "Attempted to decrement non-decrementable list::const_iterator");
487 __ptr_ = __ptr_->__prev_;
490 _LIBCPP_INLINE_VISIBILITY
491 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
493 friend _LIBCPP_INLINE_VISIBILITY
494 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
496 return __x.__ptr_ == __y.__ptr_;
498 friend _LIBCPP_INLINE_VISIBILITY
499 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
500 {return !(__x == __y);}
503 template <class _Tp, class _Alloc>
506 __list_imp(const __list_imp&);
507 __list_imp& operator=(const __list_imp&);
509 typedef _Tp value_type;
510 typedef _Alloc allocator_type;
511 typedef allocator_traits<allocator_type> __alloc_traits;
512 typedef typename __alloc_traits::size_type size_type;
513 typedef typename __alloc_traits::void_pointer __void_pointer;
514 typedef __list_iterator<value_type, __void_pointer> iterator;
515 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
516 typedef __list_node_base<value_type, __void_pointer> __node_base;
517 typedef __list_node<value_type, __void_pointer> __node;
518 typedef typename __alloc_traits::template
519 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
522 rebind_alloc<__node>::other
525 typedef allocator_traits<__node_allocator> __node_alloc_traits;
526 typedef typename __node_alloc_traits::pointer __node_pointer;
527 typedef typename __node_alloc_traits::pointer __node_const_pointer;
528 typedef typename __alloc_traits::pointer pointer;
529 typedef typename __alloc_traits::const_pointer const_pointer;
530 typedef typename __alloc_traits::difference_type difference_type;
532 typedef typename __alloc_traits::template
533 #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
534 rebind_alloc<__node_base>
536 rebind_alloc<__node_base>::other
538 __node_base_allocator;
539 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
542 __compressed_pair<size_type, __node_allocator> __size_alloc_;
544 _LIBCPP_INLINE_VISIBILITY
545 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
546 _LIBCPP_INLINE_VISIBILITY
547 const size_type& __sz() const _NOEXCEPT
548 {return __size_alloc_.first();}
549 _LIBCPP_INLINE_VISIBILITY
550 __node_allocator& __node_alloc() _NOEXCEPT
551 {return __size_alloc_.second();}
552 _LIBCPP_INLINE_VISIBILITY
553 const __node_allocator& __node_alloc() const _NOEXCEPT
554 {return __size_alloc_.second();}
556 static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
559 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
560 __list_imp(const allocator_type& __a);
562 void clear() _NOEXCEPT;
563 _LIBCPP_INLINE_VISIBILITY
564 bool empty() const _NOEXCEPT {return __sz() == 0;}
566 _LIBCPP_INLINE_VISIBILITY
567 iterator begin() _NOEXCEPT
569 #if _LIBCPP_DEBUG_LEVEL >= 2
570 return iterator(__end_.__next_, this);
572 return iterator(__end_.__next_);
575 _LIBCPP_INLINE_VISIBILITY
576 const_iterator begin() const _NOEXCEPT
578 #if _LIBCPP_DEBUG_LEVEL >= 2
579 return const_iterator(__end_.__next_, this);
581 return const_iterator(__end_.__next_);
584 _LIBCPP_INLINE_VISIBILITY
585 iterator end() _NOEXCEPT
587 #if _LIBCPP_DEBUG_LEVEL >= 2
588 return iterator(static_cast<__node_pointer>(
589 pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
591 return iterator(static_cast<__node_pointer>(
592 pointer_traits<__node_base_pointer>::pointer_to(__end_)));
595 _LIBCPP_INLINE_VISIBILITY
596 const_iterator end() const _NOEXCEPT
598 #if _LIBCPP_DEBUG_LEVEL >= 2
599 return const_iterator(static_cast<__node_const_pointer>(
600 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
602 return const_iterator(static_cast<__node_const_pointer>(
603 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
607 void swap(__list_imp& __c)
608 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
609 __is_nothrow_swappable<__node_allocator>::value);
611 _LIBCPP_INLINE_VISIBILITY
612 void __copy_assign_alloc(const __list_imp& __c)
613 {__copy_assign_alloc(__c, integral_constant<bool,
614 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
616 _LIBCPP_INLINE_VISIBILITY
617 void __move_assign_alloc(__list_imp& __c)
619 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
620 is_nothrow_move_assignable<__node_allocator>::value)
621 {__move_assign_alloc(__c, integral_constant<bool,
622 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
625 _LIBCPP_INLINE_VISIBILITY
626 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
627 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
628 __is_nothrow_swappable<__node_allocator>::value)
629 {__swap_alloc(__x, __y, integral_constant<bool,
630 __node_alloc_traits::propagate_on_container_swap::value>());}
631 _LIBCPP_INLINE_VISIBILITY
632 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
633 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
638 _LIBCPP_INLINE_VISIBILITY
639 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
643 _LIBCPP_INLINE_VISIBILITY
644 void __copy_assign_alloc(const __list_imp& __c, true_type)
646 if (__node_alloc() != __c.__node_alloc())
648 __node_alloc() = __c.__node_alloc();
651 _LIBCPP_INLINE_VISIBILITY
652 void __copy_assign_alloc(const __list_imp& __c, false_type)
655 _LIBCPP_INLINE_VISIBILITY
656 void __move_assign_alloc(__list_imp& __c, true_type)
657 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
659 __node_alloc() = _VSTD::move(__c.__node_alloc());
662 _LIBCPP_INLINE_VISIBILITY
663 void __move_assign_alloc(__list_imp& __c, false_type)
668 // Unlink nodes [__f, __l]
669 template <class _Tp, class _Alloc>
670 inline _LIBCPP_INLINE_VISIBILITY
672 __list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
675 __f->__prev_->__next_ = __l->__next_;
676 __l->__next_->__prev_ = __f->__prev_;
679 template <class _Tp, class _Alloc>
680 inline _LIBCPP_INLINE_VISIBILITY
681 __list_imp<_Tp, _Alloc>::__list_imp()
682 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
687 template <class _Tp, class _Alloc>
688 inline _LIBCPP_INLINE_VISIBILITY
689 __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
690 : __size_alloc_(0, __node_allocator(__a))
694 template <class _Tp, class _Alloc>
695 __list_imp<_Tp, _Alloc>::~__list_imp()
698 #if _LIBCPP_DEBUG_LEVEL >= 2
699 __get_db()->__erase_c(this);
703 template <class _Tp, class _Alloc>
705 __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
709 __node_allocator& __na = __node_alloc();
710 __node_pointer __f = __end_.__next_;
711 __node_pointer __l = static_cast<__node_pointer>(
712 pointer_traits<__node_base_pointer>::pointer_to(__end_));
713 __unlink_nodes(__f, __l->__prev_);
717 __node_pointer __n = __f;
719 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
720 __node_alloc_traits::deallocate(__na, __n, 1);
722 #if _LIBCPP_DEBUG_LEVEL >= 2
723 __c_node* __c = __get_db()->__find_c_and_lock(this);
724 for (__i_node** __p = __c->end_; __p != __c->beg_; )
727 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
728 if (__i->__ptr_ != __l)
730 (*__p)->__c_ = nullptr;
731 if (--__c->end_ != __p)
732 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
735 __get_db()->unlock();
740 template <class _Tp, class _Alloc>
742 __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
743 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
744 __is_nothrow_swappable<__node_allocator>::value)
746 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
747 this->__node_alloc() == __c.__node_alloc(),
748 "list::swap: Either propagate_on_container_swap must be true"
749 " or the allocators must compare equal");
751 __swap_alloc(__node_alloc(), __c.__node_alloc());
752 swap(__sz(), __c.__sz());
753 swap(__end_, __c.__end_);
755 __end_.__next_ = __end_.__prev_ = __end_.__self();
757 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
759 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
761 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
763 #if _LIBCPP_DEBUG_LEVEL >= 2
764 __libcpp_db* __db = __get_db();
765 __c_node* __cn1 = __db->__find_c_and_lock(this);
766 __c_node* __cn2 = __db->__find_c(&__c);
767 std::swap(__cn1->beg_, __cn2->beg_);
768 std::swap(__cn1->end_, __cn2->end_);
769 std::swap(__cn1->cap_, __cn2->cap_);
770 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
773 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
774 if (__i->__ptr_ == static_cast<__node_pointer>(
775 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
778 if (--__cn1->end_ != __p)
779 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
782 (*__p)->__c_ = __cn1;
784 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
787 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
788 if (__i->__ptr_ == static_cast<__node_pointer>(
789 pointer_traits<__node_base_pointer>::pointer_to(__end_)))
792 if (--__cn2->end_ != __p)
793 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
796 (*__p)->__c_ = __cn2;
802 template <class _Tp, class _Alloc = allocator<_Tp> >
803 class _LIBCPP_TYPE_VIS_ONLY list
804 : private __list_imp<_Tp, _Alloc>
806 typedef __list_imp<_Tp, _Alloc> base;
807 typedef typename base::__node __node;
808 typedef typename base::__node_allocator __node_allocator;
809 typedef typename base::__node_pointer __node_pointer;
810 typedef typename base::__node_alloc_traits __node_alloc_traits;
811 typedef typename base::__node_base __node_base;
812 typedef typename base::__node_base_pointer __node_base_pointer;
815 typedef _Tp value_type;
816 typedef _Alloc allocator_type;
817 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
818 "Invalid allocator::value_type");
819 typedef value_type& reference;
820 typedef const value_type& const_reference;
821 typedef typename base::pointer pointer;
822 typedef typename base::const_pointer const_pointer;
823 typedef typename base::size_type size_type;
824 typedef typename base::difference_type difference_type;
825 typedef typename base::iterator iterator;
826 typedef typename base::const_iterator const_iterator;
827 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
828 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
830 _LIBCPP_INLINE_VISIBILITY
832 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
834 #if _LIBCPP_DEBUG_LEVEL >= 2
835 __get_db()->__insert_c(this);
838 _LIBCPP_INLINE_VISIBILITY
839 explicit list(const allocator_type& __a) : base(__a)
841 #if _LIBCPP_DEBUG_LEVEL >= 2
842 __get_db()->__insert_c(this);
845 explicit list(size_type __n);
846 #if _LIBCPP_STD_VER > 11
847 explicit list(size_type __n, const allocator_type& __a);
849 list(size_type __n, const value_type& __x);
850 list(size_type __n, const value_type& __x, const allocator_type& __a);
851 template <class _InpIter>
852 list(_InpIter __f, _InpIter __l,
853 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
854 template <class _InpIter>
855 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
856 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
858 list(const list& __c);
859 list(const list& __c, const allocator_type& __a);
860 list& operator=(const list& __c);
861 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
862 list(initializer_list<value_type> __il);
863 list(initializer_list<value_type> __il, const allocator_type& __a);
864 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
865 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
867 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
868 list(list&& __c, const allocator_type& __a);
869 list& operator=(list&& __c)
871 __node_alloc_traits::propagate_on_container_move_assignment::value &&
872 is_nothrow_move_assignable<__node_allocator>::value);
873 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
874 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
875 _LIBCPP_INLINE_VISIBILITY
876 list& operator=(initializer_list<value_type> __il)
877 {assign(__il.begin(), __il.end()); return *this;}
878 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
880 template <class _InpIter>
881 void assign(_InpIter __f, _InpIter __l,
882 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
883 void assign(size_type __n, const value_type& __x);
884 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
885 _LIBCPP_INLINE_VISIBILITY
886 void assign(initializer_list<value_type> __il)
887 {assign(__il.begin(), __il.end());}
888 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
890 allocator_type get_allocator() const _NOEXCEPT;
892 _LIBCPP_INLINE_VISIBILITY
893 size_type size() const _NOEXCEPT {return base::__sz();}
894 _LIBCPP_INLINE_VISIBILITY
895 bool empty() const _NOEXCEPT {return base::empty();}
896 _LIBCPP_INLINE_VISIBILITY
897 size_type max_size() const _NOEXCEPT
898 {return numeric_limits<difference_type>::max();}
900 _LIBCPP_INLINE_VISIBILITY
901 iterator begin() _NOEXCEPT {return base::begin();}
902 _LIBCPP_INLINE_VISIBILITY
903 const_iterator begin() const _NOEXCEPT {return base::begin();}
904 _LIBCPP_INLINE_VISIBILITY
905 iterator end() _NOEXCEPT {return base::end();}
906 _LIBCPP_INLINE_VISIBILITY
907 const_iterator end() const _NOEXCEPT {return base::end();}
908 _LIBCPP_INLINE_VISIBILITY
909 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
910 _LIBCPP_INLINE_VISIBILITY
911 const_iterator cend() const _NOEXCEPT {return base::end();}
913 _LIBCPP_INLINE_VISIBILITY
914 reverse_iterator rbegin() _NOEXCEPT
915 {return reverse_iterator(end());}
916 _LIBCPP_INLINE_VISIBILITY
917 const_reverse_iterator rbegin() const _NOEXCEPT
918 {return const_reverse_iterator(end());}
919 _LIBCPP_INLINE_VISIBILITY
920 reverse_iterator rend() _NOEXCEPT
921 {return reverse_iterator(begin());}
922 _LIBCPP_INLINE_VISIBILITY
923 const_reverse_iterator rend() const _NOEXCEPT
924 {return const_reverse_iterator(begin());}
925 _LIBCPP_INLINE_VISIBILITY
926 const_reverse_iterator crbegin() const _NOEXCEPT
927 {return const_reverse_iterator(end());}
928 _LIBCPP_INLINE_VISIBILITY
929 const_reverse_iterator crend() const _NOEXCEPT
930 {return const_reverse_iterator(begin());}
932 _LIBCPP_INLINE_VISIBILITY
935 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
936 return base::__end_.__next_->__value_;
938 _LIBCPP_INLINE_VISIBILITY
939 const_reference front() const
941 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
942 return base::__end_.__next_->__value_;
944 _LIBCPP_INLINE_VISIBILITY
947 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
948 return base::__end_.__prev_->__value_;
950 _LIBCPP_INLINE_VISIBILITY
951 const_reference back() const
953 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
954 return base::__end_.__prev_->__value_;
957 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
958 void push_front(value_type&& __x);
959 void push_back(value_type&& __x);
960 #ifndef _LIBCPP_HAS_NO_VARIADICS
961 template <class... _Args>
962 void emplace_front(_Args&&... __args);
963 template <class... _Args>
964 void emplace_back(_Args&&... __args);
965 template <class... _Args>
966 iterator emplace(const_iterator __p, _Args&&... __args);
967 #endif // _LIBCPP_HAS_NO_VARIADICS
968 iterator insert(const_iterator __p, value_type&& __x);
969 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
971 void push_front(const value_type& __x);
972 void push_back(const value_type& __x);
974 iterator insert(const_iterator __p, const value_type& __x);
975 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
976 template <class _InpIter>
977 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
978 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
979 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
980 _LIBCPP_INLINE_VISIBILITY
981 iterator insert(const_iterator __p, initializer_list<value_type> __il)
982 {return insert(__p, __il.begin(), __il.end());}
983 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
985 _LIBCPP_INLINE_VISIBILITY
987 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
988 __is_nothrow_swappable<__node_allocator>::value)
990 _LIBCPP_INLINE_VISIBILITY
991 void clear() _NOEXCEPT {base::clear();}
996 iterator erase(const_iterator __p);
997 iterator erase(const_iterator __f, const_iterator __l);
999 void resize(size_type __n);
1000 void resize(size_type __n, const value_type& __x);
1002 void splice(const_iterator __p, list& __c);
1003 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1004 _LIBCPP_INLINE_VISIBILITY
1005 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1007 void splice(const_iterator __p, list& __c, const_iterator __i);
1008 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1009 _LIBCPP_INLINE_VISIBILITY
1010 void splice(const_iterator __p, list&& __c, const_iterator __i)
1011 {splice(__p, __c, __i);}
1012 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1013 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
1014 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1015 _LIBCPP_INLINE_VISIBILITY
1016 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1017 {splice(__p, __c, __f, __l);}
1018 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1020 void remove(const value_type& __x);
1021 template <class _Pred> void remove_if(_Pred __pred);
1023 template <class _BinaryPred>
1024 void unique(_BinaryPred __binary_pred);
1025 void merge(list& __c);
1026 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1027 _LIBCPP_INLINE_VISIBILITY
1028 void merge(list&& __c) {merge(__c);}
1030 template <class _Comp>
1031 void merge(list& __c, _Comp __comp);
1032 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1033 template <class _Comp>
1034 _LIBCPP_INLINE_VISIBILITY
1035 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
1036 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1038 template <class _Comp>
1039 void sort(_Comp __comp);
1041 void reverse() _NOEXCEPT;
1043 bool __invariants() const;
1045 #if _LIBCPP_DEBUG_LEVEL >= 2
1047 bool __dereferenceable(const const_iterator* __i) const;
1048 bool __decrementable(const const_iterator* __i) const;
1049 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1050 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1052 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1055 static void __link_nodes (__node_pointer __p, __node_pointer __f, __node_pointer __l);
1056 void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
1057 void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
1058 iterator __iterator(size_type __n);
1059 template <class _Comp>
1060 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1062 void __move_assign(list& __c, true_type)
1063 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
1064 void __move_assign(list& __c, false_type);
1067 // Link in nodes [__f, __l] just prior to __p
1068 template <class _Tp, class _Alloc>
1069 inline _LIBCPP_INLINE_VISIBILITY
1071 list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
1073 __p->__prev_->__next_ = __f;
1074 __f->__prev_ = __p->__prev_;
1079 // Link in nodes [__f, __l] at the front of the list
1080 template <class _Tp, class _Alloc>
1081 inline _LIBCPP_INLINE_VISIBILITY
1083 list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
1085 __f->__prev_ = base::__end_.__self();
1086 __l->__next_ = base::__end_.__next_;
1087 __l->__next_->__prev_ = __l;
1088 base::__end_.__next_ = __f;
1091 // Link in nodes [__f, __l] at the front of the list
1092 template <class _Tp, class _Alloc>
1093 inline _LIBCPP_INLINE_VISIBILITY
1095 list<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
1097 __l->__next_ = base::__end_.__self();
1098 __f->__prev_ = base::__end_.__prev_;
1099 __f->__prev_->__next_ = __f;
1100 base::__end_.__prev_ = __l;
1104 template <class _Tp, class _Alloc>
1105 inline _LIBCPP_INLINE_VISIBILITY
1106 typename list<_Tp, _Alloc>::iterator
1107 list<_Tp, _Alloc>::__iterator(size_type __n)
1109 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1110 : _VSTD::prev(end(), base::__sz() - __n);
1113 template <class _Tp, class _Alloc>
1114 list<_Tp, _Alloc>::list(size_type __n)
1116 #if _LIBCPP_DEBUG_LEVEL >= 2
1117 __get_db()->__insert_c(this);
1119 for (; __n > 0; --__n)
1120 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1123 push_back(value_type());
1127 #if _LIBCPP_STD_VER > 11
1128 template <class _Tp, class _Alloc>
1129 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1131 #if _LIBCPP_DEBUG_LEVEL >= 2
1132 __get_db()->__insert_c(this);
1134 for (; __n > 0; --__n)
1135 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1138 push_back(value_type());
1143 template <class _Tp, class _Alloc>
1144 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1146 #if _LIBCPP_DEBUG_LEVEL >= 2
1147 __get_db()->__insert_c(this);
1149 for (; __n > 0; --__n)
1153 template <class _Tp, class _Alloc>
1154 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1157 #if _LIBCPP_DEBUG_LEVEL >= 2
1158 __get_db()->__insert_c(this);
1160 for (; __n > 0; --__n)
1164 template <class _Tp, class _Alloc>
1165 template <class _InpIter>
1166 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1167 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1169 #if _LIBCPP_DEBUG_LEVEL >= 2
1170 __get_db()->__insert_c(this);
1172 for (; __f != __l; ++__f)
1176 template <class _Tp, class _Alloc>
1177 template <class _InpIter>
1178 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1179 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1182 #if _LIBCPP_DEBUG_LEVEL >= 2
1183 __get_db()->__insert_c(this);
1185 for (; __f != __l; ++__f)
1189 template <class _Tp, class _Alloc>
1190 list<_Tp, _Alloc>::list(const list& __c)
1191 : base(allocator_type(
1192 __node_alloc_traits::select_on_container_copy_construction(
1193 __c.__node_alloc())))
1195 #if _LIBCPP_DEBUG_LEVEL >= 2
1196 __get_db()->__insert_c(this);
1198 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1202 template <class _Tp, class _Alloc>
1203 list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1206 #if _LIBCPP_DEBUG_LEVEL >= 2
1207 __get_db()->__insert_c(this);
1209 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1213 #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1215 template <class _Tp, class _Alloc>
1216 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1219 #if _LIBCPP_DEBUG_LEVEL >= 2
1220 __get_db()->__insert_c(this);
1222 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1223 __e = __il.end(); __i != __e; ++__i)
1227 template <class _Tp, class _Alloc>
1228 list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1230 #if _LIBCPP_DEBUG_LEVEL >= 2
1231 __get_db()->__insert_c(this);
1233 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1234 __e = __il.end(); __i != __e; ++__i)
1238 #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1240 template <class _Tp, class _Alloc>
1241 inline _LIBCPP_INLINE_VISIBILITY
1243 list<_Tp, _Alloc>::operator=(const list& __c)
1247 base::__copy_assign_alloc(__c);
1248 assign(__c.begin(), __c.end());
1253 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1255 template <class _Tp, class _Alloc>
1256 inline _LIBCPP_INLINE_VISIBILITY
1257 list<_Tp, _Alloc>::list(list&& __c)
1258 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
1259 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
1261 #if _LIBCPP_DEBUG_LEVEL >= 2
1262 __get_db()->__insert_c(this);
1267 template <class _Tp, class _Alloc>
1268 inline _LIBCPP_INLINE_VISIBILITY
1269 list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1272 #if _LIBCPP_DEBUG_LEVEL >= 2
1273 __get_db()->__insert_c(this);
1275 if (__a == __c.get_allocator())
1279 typedef move_iterator<iterator> _Ip;
1280 assign(_Ip(__c.begin()), _Ip(__c.end()));
1284 template <class _Tp, class _Alloc>
1285 inline _LIBCPP_INLINE_VISIBILITY
1287 list<_Tp, _Alloc>::operator=(list&& __c)
1289 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1290 is_nothrow_move_assignable<__node_allocator>::value)
1292 __move_assign(__c, integral_constant<bool,
1293 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1297 template <class _Tp, class _Alloc>
1299 list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1301 if (base::__node_alloc() != __c.__node_alloc())
1303 typedef move_iterator<iterator> _Ip;
1304 assign(_Ip(__c.begin()), _Ip(__c.end()));
1307 __move_assign(__c, true_type());
1310 template <class _Tp, class _Alloc>
1312 list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
1313 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
1316 base::__move_assign_alloc(__c);
1320 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1322 template <class _Tp, class _Alloc>
1323 template <class _InpIter>
1325 list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1326 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1328 iterator __i = begin();
1329 iterator __e = end();
1330 for (; __f != __l && __i != __e; ++__f, ++__i)
1333 insert(__e, __f, __l);
1338 template <class _Tp, class _Alloc>
1340 list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1342 iterator __i = begin();
1343 iterator __e = end();
1344 for (; __n > 0 && __i != __e; --__n, ++__i)
1347 insert(__e, __n, __x);
1352 template <class _Tp, class _Alloc>
1353 inline _LIBCPP_INLINE_VISIBILITY
1355 list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
1357 return allocator_type(base::__node_alloc());
1360 template <class _Tp, class _Alloc>
1361 typename list<_Tp, _Alloc>::iterator
1362 list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1364 #if _LIBCPP_DEBUG_LEVEL >= 2
1365 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1366 "list::insert(iterator, x) called with an iterator not"
1367 " referring to this list");
1369 __node_allocator& __na = base::__node_alloc();
1370 typedef __allocator_destructor<__node_allocator> _Dp;
1371 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1372 __hold->__prev_ = 0;
1373 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1374 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
1376 #if _LIBCPP_DEBUG_LEVEL >= 2
1377 return iterator(__hold.release(), this);
1379 return iterator(__hold.release());
1383 template <class _Tp, class _Alloc>
1384 typename list<_Tp, _Alloc>::iterator
1385 list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1387 #if _LIBCPP_DEBUG_LEVEL >= 2
1388 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1389 "list::insert(iterator, n, x) called with an iterator not"
1390 " referring to this list");
1391 iterator __r(__p.__ptr_, this);
1393 iterator __r(__p.__ptr_);
1398 __node_allocator& __na = base::__node_alloc();
1399 typedef __allocator_destructor<__node_allocator> _Dp;
1400 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1401 __hold->__prev_ = 0;
1402 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1404 #if _LIBCPP_DEBUG_LEVEL >= 2
1405 __r = iterator(__hold.get(), this);
1407 __r = iterator(__hold.get());
1411 #ifndef _LIBCPP_NO_EXCEPTIONS
1414 #endif // _LIBCPP_NO_EXCEPTIONS
1415 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1417 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1418 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1419 __e.__ptr_->__next_ = __hold.get();
1420 __hold->__prev_ = __e.__ptr_;
1423 #ifndef _LIBCPP_NO_EXCEPTIONS
1429 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1430 __node_pointer __prev = __e.__ptr_->__prev_;
1431 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1434 #if _LIBCPP_DEBUG_LEVEL >= 2
1435 __e = iterator(__prev, this);
1437 __e = iterator(__prev);
1442 #endif // _LIBCPP_NO_EXCEPTIONS
1443 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1444 base::__sz() += __ds;
1449 template <class _Tp, class _Alloc>
1450 template <class _InpIter>
1451 typename list<_Tp, _Alloc>::iterator
1452 list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1453 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1455 #if _LIBCPP_DEBUG_LEVEL >= 2
1456 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1457 "list::insert(iterator, range) called with an iterator not"
1458 " referring to this list");
1459 iterator __r(__p.__ptr_, this);
1461 iterator __r(__p.__ptr_);
1466 __node_allocator& __na = base::__node_alloc();
1467 typedef __allocator_destructor<__node_allocator> _Dp;
1468 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1469 __hold->__prev_ = 0;
1470 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1472 #if _LIBCPP_DEBUG_LEVEL >= 2
1473 __r = iterator(__hold.get(), this);
1475 __r = iterator(__hold.get());
1479 #ifndef _LIBCPP_NO_EXCEPTIONS
1482 #endif // _LIBCPP_NO_EXCEPTIONS
1483 for (++__f; __f != __l; ++__f, ++__e, ++__ds)
1485 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1486 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1487 __e.__ptr_->__next_ = __hold.get();
1488 __hold->__prev_ = __e.__ptr_;
1491 #ifndef _LIBCPP_NO_EXCEPTIONS
1497 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1498 __node_pointer __prev = __e.__ptr_->__prev_;
1499 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1502 #if _LIBCPP_DEBUG_LEVEL >= 2
1503 __e = iterator(__prev, this);
1505 __e = iterator(__prev);
1510 #endif // _LIBCPP_NO_EXCEPTIONS
1511 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1512 base::__sz() += __ds;
1517 template <class _Tp, class _Alloc>
1519 list<_Tp, _Alloc>::push_front(const value_type& __x)
1521 __node_allocator& __na = base::__node_alloc();
1522 typedef __allocator_destructor<__node_allocator> _Dp;
1523 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1524 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1525 __link_nodes_at_front(__hold.get(), __hold.get());
1530 template <class _Tp, class _Alloc>
1532 list<_Tp, _Alloc>::push_back(const value_type& __x)
1534 __node_allocator& __na = base::__node_alloc();
1535 typedef __allocator_destructor<__node_allocator> _Dp;
1536 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1537 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1538 __link_nodes_at_back(__hold.get(), __hold.get());
1543 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1545 template <class _Tp, class _Alloc>
1547 list<_Tp, _Alloc>::push_front(value_type&& __x)
1549 __node_allocator& __na = base::__node_alloc();
1550 typedef __allocator_destructor<__node_allocator> _Dp;
1551 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1552 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1553 __link_nodes_at_front(__hold.get(), __hold.get());
1558 template <class _Tp, class _Alloc>
1560 list<_Tp, _Alloc>::push_back(value_type&& __x)
1562 __node_allocator& __na = base::__node_alloc();
1563 typedef __allocator_destructor<__node_allocator> _Dp;
1564 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1565 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1566 __link_nodes_at_back(__hold.get(), __hold.get());
1571 #ifndef _LIBCPP_HAS_NO_VARIADICS
1573 template <class _Tp, class _Alloc>
1574 template <class... _Args>
1576 list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1578 __node_allocator& __na = base::__node_alloc();
1579 typedef __allocator_destructor<__node_allocator> _Dp;
1580 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1581 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1582 __link_nodes_at_front(__hold.get(), __hold.get());
1587 template <class _Tp, class _Alloc>
1588 template <class... _Args>
1590 list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1592 __node_allocator& __na = base::__node_alloc();
1593 typedef __allocator_destructor<__node_allocator> _Dp;
1594 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1595 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1596 __link_nodes_at_back(__hold.get(), __hold.get());
1601 template <class _Tp, class _Alloc>
1602 template <class... _Args>
1603 typename list<_Tp, _Alloc>::iterator
1604 list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1606 #if _LIBCPP_DEBUG_LEVEL >= 2
1607 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1608 "list::emplace(iterator, args...) called with an iterator not"
1609 " referring to this list");
1611 __node_allocator& __na = base::__node_alloc();
1612 typedef __allocator_destructor<__node_allocator> _Dp;
1613 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1614 __hold->__prev_ = 0;
1615 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1616 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
1618 #if _LIBCPP_DEBUG_LEVEL >= 2
1619 return iterator(__hold.release(), this);
1621 return iterator(__hold.release());
1625 #endif // _LIBCPP_HAS_NO_VARIADICS
1627 template <class _Tp, class _Alloc>
1628 typename list<_Tp, _Alloc>::iterator
1629 list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1631 #if _LIBCPP_DEBUG_LEVEL >= 2
1632 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1633 "list::insert(iterator, x) called with an iterator not"
1634 " referring to this list");
1636 __node_allocator& __na = base::__node_alloc();
1637 typedef __allocator_destructor<__node_allocator> _Dp;
1638 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1639 __hold->__prev_ = 0;
1640 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1641 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
1643 #if _LIBCPP_DEBUG_LEVEL >= 2
1644 return iterator(__hold.release(), this);
1646 return iterator(__hold.release());
1650 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
1652 template <class _Tp, class _Alloc>
1654 list<_Tp, _Alloc>::pop_front()
1656 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
1657 __node_allocator& __na = base::__node_alloc();
1658 __node_pointer __n = base::__end_.__next_;
1659 base::__unlink_nodes(__n, __n);
1661 #if _LIBCPP_DEBUG_LEVEL >= 2
1662 __c_node* __c = __get_db()->__find_c_and_lock(this);
1663 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1666 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1667 if (__i->__ptr_ == __n)
1669 (*__p)->__c_ = nullptr;
1670 if (--__c->end_ != __p)
1671 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1674 __get_db()->unlock();
1676 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1677 __node_alloc_traits::deallocate(__na, __n, 1);
1680 template <class _Tp, class _Alloc>
1682 list<_Tp, _Alloc>::pop_back()
1684 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
1685 __node_allocator& __na = base::__node_alloc();
1686 __node_pointer __n = base::__end_.__prev_;
1687 base::__unlink_nodes(__n, __n);
1689 #if _LIBCPP_DEBUG_LEVEL >= 2
1690 __c_node* __c = __get_db()->__find_c_and_lock(this);
1691 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1694 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1695 if (__i->__ptr_ == __n)
1697 (*__p)->__c_ = nullptr;
1698 if (--__c->end_ != __p)
1699 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1702 __get_db()->unlock();
1704 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1705 __node_alloc_traits::deallocate(__na, __n, 1);
1708 template <class _Tp, class _Alloc>
1709 typename list<_Tp, _Alloc>::iterator
1710 list<_Tp, _Alloc>::erase(const_iterator __p)
1712 #if _LIBCPP_DEBUG_LEVEL >= 2
1713 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1714 "list::erase(iterator) called with an iterator not"
1715 " referring to this list");
1717 _LIBCPP_ASSERT(__p != end(),
1718 "list::erase(iterator) called with a non-dereferenceable iterator");
1719 __node_allocator& __na = base::__node_alloc();
1720 __node_pointer __n = __p.__ptr_;
1721 __node_pointer __r = __n->__next_;
1722 base::__unlink_nodes(__n, __n);
1724 #if _LIBCPP_DEBUG_LEVEL >= 2
1725 __c_node* __c = __get_db()->__find_c_and_lock(this);
1726 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1729 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1730 if (__i->__ptr_ == __n)
1732 (*__p)->__c_ = nullptr;
1733 if (--__c->end_ != __p)
1734 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1737 __get_db()->unlock();
1739 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1740 __node_alloc_traits::deallocate(__na, __n, 1);
1741 #if _LIBCPP_DEBUG_LEVEL >= 2
1742 return iterator(__r, this);
1744 return iterator(__r);
1748 template <class _Tp, class _Alloc>
1749 typename list<_Tp, _Alloc>::iterator
1750 list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1752 #if _LIBCPP_DEBUG_LEVEL >= 2
1753 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1754 "list::erase(iterator, iterator) called with an iterator not"
1755 " referring to this list");
1759 __node_allocator& __na = base::__node_alloc();
1760 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1763 __node_pointer __n = __f.__ptr_;
1766 #if _LIBCPP_DEBUG_LEVEL >= 2
1767 __c_node* __c = __get_db()->__find_c_and_lock(this);
1768 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1771 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1772 if (__i->__ptr_ == __n)
1774 (*__p)->__c_ = nullptr;
1775 if (--__c->end_ != __p)
1776 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1779 __get_db()->unlock();
1781 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1782 __node_alloc_traits::deallocate(__na, __n, 1);
1785 #if _LIBCPP_DEBUG_LEVEL >= 2
1786 return iterator(__l.__ptr_, this);
1788 return iterator(__l.__ptr_);
1792 template <class _Tp, class _Alloc>
1794 list<_Tp, _Alloc>::resize(size_type __n)
1796 if (__n < base::__sz())
1797 erase(__iterator(__n), end());
1798 else if (__n > base::__sz())
1800 __n -= base::__sz();
1802 __node_allocator& __na = base::__node_alloc();
1803 typedef __allocator_destructor<__node_allocator> _Dp;
1804 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1805 __hold->__prev_ = 0;
1806 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1808 #if _LIBCPP_DEBUG_LEVEL >= 2
1809 iterator __r = iterator(__hold.release(), this);
1811 iterator __r = iterator(__hold.release());
1814 #ifndef _LIBCPP_NO_EXCEPTIONS
1817 #endif // _LIBCPP_NO_EXCEPTIONS
1818 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1820 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1821 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1822 __e.__ptr_->__next_ = __hold.get();
1823 __hold->__prev_ = __e.__ptr_;
1826 #ifndef _LIBCPP_NO_EXCEPTIONS
1832 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1833 __node_pointer __prev = __e.__ptr_->__prev_;
1834 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1837 #if _LIBCPP_DEBUG_LEVEL >= 2
1838 __e = iterator(__prev, this);
1840 __e = iterator(__prev);
1845 #endif // _LIBCPP_NO_EXCEPTIONS
1846 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1847 base::__sz() += __ds;
1851 template <class _Tp, class _Alloc>
1853 list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1855 if (__n < base::__sz())
1856 erase(__iterator(__n), end());
1857 else if (__n > base::__sz())
1859 __n -= base::__sz();
1861 __node_allocator& __na = base::__node_alloc();
1862 typedef __allocator_destructor<__node_allocator> _Dp;
1863 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1864 __hold->__prev_ = 0;
1865 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1867 #if _LIBCPP_DEBUG_LEVEL >= 2
1868 iterator __r = iterator(__hold.release(), this);
1870 iterator __r = iterator(__hold.release());
1873 #ifndef _LIBCPP_NO_EXCEPTIONS
1876 #endif // _LIBCPP_NO_EXCEPTIONS
1877 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1879 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1880 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1881 __e.__ptr_->__next_ = __hold.get();
1882 __hold->__prev_ = __e.__ptr_;
1885 #ifndef _LIBCPP_NO_EXCEPTIONS
1891 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1892 __node_pointer __prev = __e.__ptr_->__prev_;
1893 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1896 #if _LIBCPP_DEBUG_LEVEL >= 2
1897 __e = iterator(__prev, this);
1899 __e = iterator(__prev);
1904 #endif // _LIBCPP_NO_EXCEPTIONS
1905 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
1906 pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
1907 base::__sz() += __ds;
1911 template <class _Tp, class _Alloc>
1913 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1915 _LIBCPP_ASSERT(this != &__c,
1916 "list::splice(iterator, list) called with this == &list");
1917 #if _LIBCPP_DEBUG_LEVEL >= 2
1918 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1919 "list::splice(iterator, list) called with an iterator not"
1920 " referring to this list");
1924 __node_pointer __f = __c.__end_.__next_;
1925 __node_pointer __l = __c.__end_.__prev_;
1926 base::__unlink_nodes(__f, __l);
1927 __link_nodes(__p.__ptr_, __f, __l);
1928 base::__sz() += __c.__sz();
1930 #if _LIBCPP_DEBUG_LEVEL >= 2
1931 __libcpp_db* __db = __get_db();
1932 __c_node* __cn1 = __db->__find_c_and_lock(this);
1933 __c_node* __cn2 = __db->__find_c(&__c);
1934 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1937 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1938 if (__i->__ptr_ != static_cast<__node_pointer>(
1939 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
1942 (*__p)->__c_ = __cn1;
1943 if (--__cn2->end_ != __p)
1944 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1952 template <class _Tp, class _Alloc>
1954 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1956 #if _LIBCPP_DEBUG_LEVEL >= 2
1957 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1958 "list::splice(iterator, list, iterator) called with first iterator not"
1959 " referring to this list");
1960 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1961 "list::splice(iterator, list, iterator) called with second iterator not"
1962 " referring to list argument");
1963 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
1964 "list::splice(iterator, list, iterator) called with second iterator not"
1967 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
1969 __node_pointer __f = __i.__ptr_;
1970 base::__unlink_nodes(__f, __f);
1971 __link_nodes(__p.__ptr_, __f, __f);
1974 #if _LIBCPP_DEBUG_LEVEL >= 2
1975 __libcpp_db* __db = __get_db();
1976 __c_node* __cn1 = __db->__find_c_and_lock(this);
1977 __c_node* __cn2 = __db->__find_c(&__c);
1978 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1981 iterator* __j = static_cast<iterator*>((*__p)->__i_);
1982 if (__j->__ptr_ == __f)
1985 (*__p)->__c_ = __cn1;
1986 if (--__cn2->end_ != __p)
1987 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1995 template <class _Tp, class _Alloc>
1997 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
1999 #if _LIBCPP_DEBUG_LEVEL >= 2
2000 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2001 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2002 " referring to this list");
2003 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2004 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2005 " referring to list argument");
2008 for (const_iterator __i = __f; __i != __l; ++__i)
2009 _LIBCPP_ASSERT(__i != __p,
2010 "list::splice(iterator, list, iterator, iterator)"
2011 " called with the first iterator within the range"
2012 " of the second and third iterators");
2019 size_type __s = _VSTD::distance(__f, __l);
2021 base::__sz() += __s;
2023 __node_pointer __first = __f.__ptr_;
2025 __node_pointer __last = __l.__ptr_;
2026 base::__unlink_nodes(__first, __last);
2027 __link_nodes(__p.__ptr_, __first, __last);
2028 #if _LIBCPP_DEBUG_LEVEL >= 2
2029 __libcpp_db* __db = __get_db();
2030 __c_node* __cn1 = __db->__find_c_and_lock(this);
2031 __c_node* __cn2 = __db->__find_c(&__c);
2032 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2035 iterator* __j = static_cast<iterator*>((*__p)->__i_);
2036 for (__node_pointer __k = __f.__ptr_;
2037 __k != __l.__ptr_; __k = __k->__next_)
2039 if (__j->__ptr_ == __k)
2042 (*__p)->__c_ = __cn1;
2043 if (--__cn2->end_ != __p)
2044 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2053 template <class _Tp, class _Alloc>
2055 list<_Tp, _Alloc>::remove(const value_type& __x)
2057 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2058 for (const_iterator __i = begin(), __e = end(); __i != __e;)
2062 const_iterator __j = _VSTD::next(__i);
2063 for (; __j != __e && *__j == __x; ++__j)
2065 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2075 template <class _Tp, class _Alloc>
2076 template <class _Pred>
2078 list<_Tp, _Alloc>::remove_if(_Pred __pred)
2080 for (iterator __i = begin(), __e = end(); __i != __e;)
2084 iterator __j = _VSTD::next(__i);
2085 for (; __j != __e && __pred(*__j); ++__j)
2087 __i = erase(__i, __j);
2096 template <class _Tp, class _Alloc>
2097 inline _LIBCPP_INLINE_VISIBILITY
2099 list<_Tp, _Alloc>::unique()
2101 unique(__equal_to<value_type>());
2104 template <class _Tp, class _Alloc>
2105 template <class _BinaryPred>
2107 list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2109 for (iterator __i = begin(), __e = end(); __i != __e;)
2111 iterator __j = _VSTD::next(__i);
2112 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2115 __i = erase(__i, __j);
2119 template <class _Tp, class _Alloc>
2120 inline _LIBCPP_INLINE_VISIBILITY
2122 list<_Tp, _Alloc>::merge(list& __c)
2124 merge(__c, __less<value_type>());
2127 template <class _Tp, class _Alloc>
2128 template <class _Comp>
2130 list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2134 iterator __f1 = begin();
2135 iterator __e1 = end();
2136 iterator __f2 = __c.begin();
2137 iterator __e2 = __c.end();
2138 while (__f1 != __e1 && __f2 != __e2)
2140 if (__comp(*__f2, *__f1))
2143 iterator __m2 = _VSTD::next(__f2);
2144 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2146 base::__sz() += __ds;
2148 __node_pointer __f = __f2.__ptr_;
2149 __node_pointer __l = __m2.__ptr_->__prev_;
2151 base::__unlink_nodes(__f, __l);
2152 __m2 = _VSTD::next(__f1);
2153 __link_nodes(__f1.__ptr_, __f, __l);
2160 #if _LIBCPP_DEBUG_LEVEL >= 2
2161 __libcpp_db* __db = __get_db();
2162 __c_node* __cn1 = __db->__find_c_and_lock(this);
2163 __c_node* __cn2 = __db->__find_c(&__c);
2164 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2167 iterator* __i = static_cast<iterator*>((*__p)->__i_);
2168 if (__i->__ptr_ != static_cast<__node_pointer>(
2169 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
2172 (*__p)->__c_ = __cn1;
2173 if (--__cn2->end_ != __p)
2174 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2182 template <class _Tp, class _Alloc>
2183 inline _LIBCPP_INLINE_VISIBILITY
2185 list<_Tp, _Alloc>::sort()
2187 sort(__less<value_type>());
2190 template <class _Tp, class _Alloc>
2191 template <class _Comp>
2192 inline _LIBCPP_INLINE_VISIBILITY
2194 list<_Tp, _Alloc>::sort(_Comp __comp)
2196 __sort(begin(), end(), base::__sz(), __comp);
2199 template <class _Tp, class _Alloc>
2200 template <class _Comp>
2201 typename list<_Tp, _Alloc>::iterator
2202 list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2210 if (__comp(*--__e2, *__f1))
2212 __node_pointer __f = __e2.__ptr_;
2213 base::__unlink_nodes(__f, __f);
2214 __link_nodes(__f1.__ptr_, __f, __f);
2219 size_type __n2 = __n / 2;
2220 iterator __e1 = _VSTD::next(__f1, __n2);
2221 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2222 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2223 if (__comp(*__f2, *__f1))
2225 iterator __m2 = _VSTD::next(__f2);
2226 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2228 __node_pointer __f = __f2.__ptr_;
2229 __node_pointer __l = __m2.__ptr_->__prev_;
2232 base::__unlink_nodes(__f, __l);
2233 __m2 = _VSTD::next(__f1);
2234 __link_nodes(__f1.__ptr_, __f, __l);
2239 while (__f1 != __e1 && __f2 != __e2)
2241 if (__comp(*__f2, *__f1))
2243 iterator __m2 = _VSTD::next(__f2);
2244 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2246 __node_pointer __f = __f2.__ptr_;
2247 __node_pointer __l = __m2.__ptr_->__prev_;
2251 base::__unlink_nodes(__f, __l);
2252 __m2 = _VSTD::next(__f1);
2253 __link_nodes(__f1.__ptr_, __f, __l);
2262 template <class _Tp, class _Alloc>
2264 list<_Tp, _Alloc>::reverse() _NOEXCEPT
2266 if (base::__sz() > 1)
2268 iterator __e = end();
2269 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2271 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
2272 __i.__ptr_ = __i.__ptr_->__prev_;
2274 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
2278 template <class _Tp, class _Alloc>
2280 list<_Tp, _Alloc>::__invariants() const
2282 return size() == _VSTD::distance(begin(), end());
2285 #if _LIBCPP_DEBUG_LEVEL >= 2
2287 template <class _Tp, class _Alloc>
2289 list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2291 return __i->__ptr_ != static_cast<__node_pointer>(
2292 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
2295 template <class _Tp, class _Alloc>
2297 list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2299 return !empty() && __i->__ptr_ != base::__end_.__next_;
2302 template <class _Tp, class _Alloc>
2304 list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2309 template <class _Tp, class _Alloc>
2311 list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2316 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2318 template <class _Tp, class _Alloc>
2319 inline _LIBCPP_INLINE_VISIBILITY
2321 operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2323 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2326 template <class _Tp, class _Alloc>
2327 inline _LIBCPP_INLINE_VISIBILITY
2329 operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2331 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2334 template <class _Tp, class _Alloc>
2335 inline _LIBCPP_INLINE_VISIBILITY
2337 operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2339 return !(__x == __y);
2342 template <class _Tp, class _Alloc>
2343 inline _LIBCPP_INLINE_VISIBILITY
2345 operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2350 template <class _Tp, class _Alloc>
2351 inline _LIBCPP_INLINE_VISIBILITY
2353 operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2355 return !(__x < __y);
2358 template <class _Tp, class _Alloc>
2359 inline _LIBCPP_INLINE_VISIBILITY
2361 operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2363 return !(__y < __x);
2366 template <class _Tp, class _Alloc>
2367 inline _LIBCPP_INLINE_VISIBILITY
2369 swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
2370 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2375 _LIBCPP_END_NAMESPACE_STD
2377 #endif // _LIBCPP_LIST