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;
150 template <class T, class Alloc>
151 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
152 template <class T, class Alloc>
153 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
154 template <class T, class Alloc>
155 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
156 template <class T, class Alloc>
157 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
158 template <class T, class Alloc>
159 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
160 template <class T, class Alloc>
161 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
163 template <class T, class Alloc>
164 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
165 noexcept(noexcept(x.swap(y)));
175 #include <initializer_list>
178 #include <type_traits>
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;
191 template <class _Tp, class _VoidPtr> struct __list_node_base;
193 template <class _Tp, class _VoidPtr>
194 struct __list_node_pointer_traits {
195 typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
197 typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
200 #if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
201 typedef __base_pointer __link_pointer;
203 typedef typename conditional<
204 is_pointer<_VoidPtr>::value,
207 >::type __link_pointer;
210 typedef typename conditional<
211 is_same<__link_pointer, __node_pointer>::value,
214 >::type __non_link_pointer;
216 static _LIBCPP_INLINE_VISIBILITY
217 __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
221 static _LIBCPP_INLINE_VISIBILITY
222 __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
223 return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
228 template <class _Tp, class _VoidPtr>
229 struct __list_node_base
231 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
232 typedef typename _NodeTraits::__node_pointer __node_pointer;
233 typedef typename _NodeTraits::__base_pointer __base_pointer;
234 typedef typename _NodeTraits::__link_pointer __link_pointer;
236 __link_pointer __prev_;
237 __link_pointer __next_;
239 _LIBCPP_INLINE_VISIBILITY
240 __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
241 __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
243 _LIBCPP_INLINE_VISIBILITY
244 __base_pointer __self() {
245 return pointer_traits<__base_pointer>::pointer_to(*this);
248 _LIBCPP_INLINE_VISIBILITY
249 __node_pointer __as_node() {
250 return static_cast<__node_pointer>(__self());
254 template <class _Tp, class _VoidPtr>
256 : public __list_node_base<_Tp, _VoidPtr>
260 typedef __list_node_base<_Tp, _VoidPtr> __base;
261 typedef typename __base::__link_pointer __link_pointer;
263 _LIBCPP_INLINE_VISIBILITY
264 __link_pointer __as_link() {
265 return static_cast<__link_pointer>(__base::__self());
269 template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
270 template <class _Tp, class _Alloc> class __list_imp;
271 template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
273 template <class _Tp, class _VoidPtr>
274 class _LIBCPP_TEMPLATE_VIS __list_iterator
276 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
277 typedef typename _NodeTraits::__link_pointer __link_pointer;
279 __link_pointer __ptr_;
281 #if _LIBCPP_DEBUG_LEVEL >= 2
282 _LIBCPP_INLINE_VISIBILITY
283 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
286 __get_db()->__insert_ic(this, __c);
289 _LIBCPP_INLINE_VISIBILITY
290 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
295 template<class, class> friend class list;
296 template<class, class> friend class __list_imp;
297 template<class, class> friend class __list_const_iterator;
299 typedef bidirectional_iterator_tag iterator_category;
300 typedef _Tp value_type;
301 typedef value_type& reference;
302 typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
303 typedef typename pointer_traits<pointer>::difference_type difference_type;
305 _LIBCPP_INLINE_VISIBILITY
306 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
308 #if _LIBCPP_DEBUG_LEVEL >= 2
309 __get_db()->__insert_i(this);
313 #if _LIBCPP_DEBUG_LEVEL >= 2
315 _LIBCPP_INLINE_VISIBILITY
316 __list_iterator(const __list_iterator& __p)
319 __get_db()->__iterator_copy(this, &__p);
322 _LIBCPP_INLINE_VISIBILITY
325 __get_db()->__erase_i(this);
328 _LIBCPP_INLINE_VISIBILITY
329 __list_iterator& operator=(const __list_iterator& __p)
333 __get_db()->__iterator_copy(this, &__p);
339 #endif // _LIBCPP_DEBUG_LEVEL >= 2
341 _LIBCPP_INLINE_VISIBILITY
342 reference operator*() const
344 #if _LIBCPP_DEBUG_LEVEL >= 2
345 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
346 "Attempted to dereference a non-dereferenceable list::iterator");
348 return __ptr_->__as_node()->__value_;
350 _LIBCPP_INLINE_VISIBILITY
351 pointer operator->() const
353 #if _LIBCPP_DEBUG_LEVEL >= 2
354 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
355 "Attempted to dereference a non-dereferenceable list::iterator");
357 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
360 _LIBCPP_INLINE_VISIBILITY
361 __list_iterator& operator++()
363 #if _LIBCPP_DEBUG_LEVEL >= 2
364 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
365 "Attempted to increment non-incrementable list::iterator");
367 __ptr_ = __ptr_->__next_;
370 _LIBCPP_INLINE_VISIBILITY
371 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
373 _LIBCPP_INLINE_VISIBILITY
374 __list_iterator& operator--()
376 #if _LIBCPP_DEBUG_LEVEL >= 2
377 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
378 "Attempted to decrement non-decrementable list::iterator");
380 __ptr_ = __ptr_->__prev_;
383 _LIBCPP_INLINE_VISIBILITY
384 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
386 friend _LIBCPP_INLINE_VISIBILITY
387 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
389 return __x.__ptr_ == __y.__ptr_;
391 friend _LIBCPP_INLINE_VISIBILITY
392 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
393 {return !(__x == __y);}
396 template <class _Tp, class _VoidPtr>
397 class _LIBCPP_TEMPLATE_VIS __list_const_iterator
399 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
400 typedef typename _NodeTraits::__link_pointer __link_pointer;
402 __link_pointer __ptr_;
404 #if _LIBCPP_DEBUG_LEVEL >= 2
405 _LIBCPP_INLINE_VISIBILITY
406 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
409 __get_db()->__insert_ic(this, __c);
412 _LIBCPP_INLINE_VISIBILITY
413 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
416 template<class, class> friend class list;
417 template<class, class> friend class __list_imp;
419 typedef bidirectional_iterator_tag iterator_category;
420 typedef _Tp value_type;
421 typedef const value_type& reference;
422 typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
423 typedef typename pointer_traits<pointer>::difference_type difference_type;
425 _LIBCPP_INLINE_VISIBILITY
426 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
428 #if _LIBCPP_DEBUG_LEVEL >= 2
429 __get_db()->__insert_i(this);
432 _LIBCPP_INLINE_VISIBILITY
433 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
436 #if _LIBCPP_DEBUG_LEVEL >= 2
437 __get_db()->__iterator_copy(this, &__p);
441 #if _LIBCPP_DEBUG_LEVEL >= 2
443 _LIBCPP_INLINE_VISIBILITY
444 __list_const_iterator(const __list_const_iterator& __p)
447 __get_db()->__iterator_copy(this, &__p);
450 _LIBCPP_INLINE_VISIBILITY
451 ~__list_const_iterator()
453 __get_db()->__erase_i(this);
456 _LIBCPP_INLINE_VISIBILITY
457 __list_const_iterator& operator=(const __list_const_iterator& __p)
461 __get_db()->__iterator_copy(this, &__p);
467 #endif // _LIBCPP_DEBUG_LEVEL >= 2
468 _LIBCPP_INLINE_VISIBILITY
469 reference operator*() const
471 #if _LIBCPP_DEBUG_LEVEL >= 2
472 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
473 "Attempted to dereference a non-dereferenceable list::const_iterator");
475 return __ptr_->__as_node()->__value_;
477 _LIBCPP_INLINE_VISIBILITY
478 pointer operator->() const
480 #if _LIBCPP_DEBUG_LEVEL >= 2
481 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
482 "Attempted to dereference a non-dereferenceable list::iterator");
484 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
487 _LIBCPP_INLINE_VISIBILITY
488 __list_const_iterator& operator++()
490 #if _LIBCPP_DEBUG_LEVEL >= 2
491 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
492 "Attempted to increment non-incrementable list::const_iterator");
494 __ptr_ = __ptr_->__next_;
497 _LIBCPP_INLINE_VISIBILITY
498 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
500 _LIBCPP_INLINE_VISIBILITY
501 __list_const_iterator& operator--()
503 #if _LIBCPP_DEBUG_LEVEL >= 2
504 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
505 "Attempted to decrement non-decrementable list::const_iterator");
507 __ptr_ = __ptr_->__prev_;
510 _LIBCPP_INLINE_VISIBILITY
511 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
513 friend _LIBCPP_INLINE_VISIBILITY
514 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
516 return __x.__ptr_ == __y.__ptr_;
518 friend _LIBCPP_INLINE_VISIBILITY
519 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
520 {return !(__x == __y);}
523 template <class _Tp, class _Alloc>
526 __list_imp(const __list_imp&);
527 __list_imp& operator=(const __list_imp&);
529 typedef _Tp value_type;
530 typedef _Alloc allocator_type;
531 typedef allocator_traits<allocator_type> __alloc_traits;
532 typedef typename __alloc_traits::size_type size_type;
533 typedef typename __alloc_traits::void_pointer __void_pointer;
534 typedef __list_iterator<value_type, __void_pointer> iterator;
535 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
536 typedef __list_node_base<value_type, __void_pointer> __node_base;
537 typedef __list_node<value_type, __void_pointer> __node;
538 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
539 typedef allocator_traits<__node_allocator> __node_alloc_traits;
540 typedef typename __node_alloc_traits::pointer __node_pointer;
541 typedef typename __node_alloc_traits::pointer __node_const_pointer;
542 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
543 typedef typename __node_pointer_traits::__link_pointer __link_pointer;
544 typedef __link_pointer __link_const_pointer;
545 typedef typename __alloc_traits::pointer pointer;
546 typedef typename __alloc_traits::const_pointer const_pointer;
547 typedef typename __alloc_traits::difference_type difference_type;
549 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
550 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
553 __compressed_pair<size_type, __node_allocator> __size_alloc_;
555 _LIBCPP_INLINE_VISIBILITY
556 __link_pointer __end_as_link() const _NOEXCEPT {
557 return __node_pointer_traits::__unsafe_link_pointer_cast(
558 const_cast<__node_base&>(__end_).__self());
561 _LIBCPP_INLINE_VISIBILITY
562 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
563 _LIBCPP_INLINE_VISIBILITY
564 const size_type& __sz() const _NOEXCEPT
565 {return __size_alloc_.first();}
566 _LIBCPP_INLINE_VISIBILITY
567 __node_allocator& __node_alloc() _NOEXCEPT
568 {return __size_alloc_.second();}
569 _LIBCPP_INLINE_VISIBILITY
570 const __node_allocator& __node_alloc() const _NOEXCEPT
571 {return __size_alloc_.second();}
573 _LIBCPP_INLINE_VISIBILITY
574 size_type __node_alloc_max_size() const _NOEXCEPT {
575 return __node_alloc_traits::max_size(__node_alloc());
577 _LIBCPP_INLINE_VISIBILITY
578 static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
580 _LIBCPP_INLINE_VISIBILITY
582 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
583 _LIBCPP_INLINE_VISIBILITY
584 __list_imp(const allocator_type& __a);
586 void clear() _NOEXCEPT;
587 _LIBCPP_INLINE_VISIBILITY
588 bool empty() const _NOEXCEPT {return __sz() == 0;}
590 _LIBCPP_INLINE_VISIBILITY
591 iterator begin() _NOEXCEPT
593 #if _LIBCPP_DEBUG_LEVEL >= 2
594 return iterator(__end_.__next_, this);
596 return iterator(__end_.__next_);
599 _LIBCPP_INLINE_VISIBILITY
600 const_iterator begin() const _NOEXCEPT
602 #if _LIBCPP_DEBUG_LEVEL >= 2
603 return const_iterator(__end_.__next_, this);
605 return const_iterator(__end_.__next_);
608 _LIBCPP_INLINE_VISIBILITY
609 iterator end() _NOEXCEPT
611 #if _LIBCPP_DEBUG_LEVEL >= 2
612 return iterator(__end_as_link(), this);
614 return iterator(__end_as_link());
617 _LIBCPP_INLINE_VISIBILITY
618 const_iterator end() const _NOEXCEPT
620 #if _LIBCPP_DEBUG_LEVEL >= 2
621 return const_iterator(__end_as_link(), this);
623 return const_iterator(__end_as_link());
627 void swap(__list_imp& __c)
628 #if _LIBCPP_STD_VER >= 14
631 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
632 __is_nothrow_swappable<allocator_type>::value);
635 _LIBCPP_INLINE_VISIBILITY
636 void __copy_assign_alloc(const __list_imp& __c)
637 {__copy_assign_alloc(__c, integral_constant<bool,
638 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
640 _LIBCPP_INLINE_VISIBILITY
641 void __move_assign_alloc(__list_imp& __c)
643 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
644 is_nothrow_move_assignable<__node_allocator>::value)
645 {__move_assign_alloc(__c, integral_constant<bool,
646 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
649 _LIBCPP_INLINE_VISIBILITY
650 void __copy_assign_alloc(const __list_imp& __c, true_type)
652 if (__node_alloc() != __c.__node_alloc())
654 __node_alloc() = __c.__node_alloc();
657 _LIBCPP_INLINE_VISIBILITY
658 void __copy_assign_alloc(const __list_imp&, false_type)
661 _LIBCPP_INLINE_VISIBILITY
662 void __move_assign_alloc(__list_imp& __c, true_type)
663 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
665 __node_alloc() = _VSTD::move(__c.__node_alloc());
668 _LIBCPP_INLINE_VISIBILITY
669 void __move_assign_alloc(__list_imp&, false_type)
673 _LIBCPP_INLINE_VISIBILITY
674 void __invalidate_all_iterators() {
675 #if _LIBCPP_DEBUG_LEVEL >= 2
676 __get_db()->__invalidate_all(this);
681 // Unlink nodes [__f, __l]
682 template <class _Tp, class _Alloc>
685 __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
688 __f->__prev_->__next_ = __l->__next_;
689 __l->__next_->__prev_ = __f->__prev_;
692 template <class _Tp, class _Alloc>
694 __list_imp<_Tp, _Alloc>::__list_imp()
695 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
700 template <class _Tp, class _Alloc>
702 __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
703 : __size_alloc_(0, __node_allocator(__a))
707 template <class _Tp, class _Alloc>
708 __list_imp<_Tp, _Alloc>::~__list_imp()
711 #if _LIBCPP_DEBUG_LEVEL >= 2
712 __get_db()->__erase_c(this);
716 template <class _Tp, class _Alloc>
718 __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
722 __node_allocator& __na = __node_alloc();
723 __link_pointer __f = __end_.__next_;
724 __link_pointer __l = __end_as_link();
725 __unlink_nodes(__f, __l->__prev_);
729 __node_pointer __np = __f->__as_node();
731 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
732 __node_alloc_traits::deallocate(__na, __np, 1);
734 __invalidate_all_iterators();
738 template <class _Tp, class _Alloc>
740 __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
741 #if _LIBCPP_STD_VER >= 14
744 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
745 __is_nothrow_swappable<allocator_type>::value)
748 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
749 this->__node_alloc() == __c.__node_alloc(),
750 "list::swap: Either propagate_on_container_swap must be true"
751 " or the allocators must compare equal");
753 __swap_allocator(__node_alloc(), __c.__node_alloc());
754 swap(__sz(), __c.__sz());
755 swap(__end_, __c.__end_);
757 __end_.__next_ = __end_.__prev_ = __end_as_link();
759 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
761 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
763 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
765 #if _LIBCPP_DEBUG_LEVEL >= 2
766 __libcpp_db* __db = __get_db();
767 __c_node* __cn1 = __db->__find_c_and_lock(this);
768 __c_node* __cn2 = __db->__find_c(&__c);
769 std::swap(__cn1->beg_, __cn2->beg_);
770 std::swap(__cn1->end_, __cn2->end_);
771 std::swap(__cn1->cap_, __cn2->cap_);
772 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
775 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
776 if (__i->__ptr_ == __c.__end_as_link())
779 if (--__cn1->end_ != __p)
780 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
783 (*__p)->__c_ = __cn1;
785 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
788 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
789 if (__i->__ptr_ == __end_as_link())
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_TEMPLATE_VIS 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;
813 typedef typename base::__link_pointer __link_pointer;
816 typedef _Tp value_type;
817 typedef _Alloc allocator_type;
818 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
819 "Invalid allocator::value_type");
820 typedef value_type& reference;
821 typedef const value_type& const_reference;
822 typedef typename base::pointer pointer;
823 typedef typename base::const_pointer const_pointer;
824 typedef typename base::size_type size_type;
825 typedef typename base::difference_type difference_type;
826 typedef typename base::iterator iterator;
827 typedef typename base::const_iterator const_iterator;
828 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
829 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
831 _LIBCPP_INLINE_VISIBILITY
833 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
835 #if _LIBCPP_DEBUG_LEVEL >= 2
836 __get_db()->__insert_c(this);
839 _LIBCPP_INLINE_VISIBILITY
840 explicit list(const allocator_type& __a) : base(__a)
842 #if _LIBCPP_DEBUG_LEVEL >= 2
843 __get_db()->__insert_c(this);
846 explicit list(size_type __n);
847 #if _LIBCPP_STD_VER > 11
848 explicit list(size_type __n, const allocator_type& __a);
850 list(size_type __n, const value_type& __x);
851 list(size_type __n, const value_type& __x, const allocator_type& __a);
852 template <class _InpIter>
853 list(_InpIter __f, _InpIter __l,
854 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
855 template <class _InpIter>
856 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
857 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
859 list(const list& __c);
860 list(const list& __c, const allocator_type& __a);
861 _LIBCPP_INLINE_VISIBILITY
862 list& operator=(const list& __c);
863 #ifndef _LIBCPP_CXX03_LANG
864 list(initializer_list<value_type> __il);
865 list(initializer_list<value_type> __il, const allocator_type& __a);
867 _LIBCPP_INLINE_VISIBILITY
869 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
870 _LIBCPP_INLINE_VISIBILITY
871 list(list&& __c, const allocator_type& __a);
872 _LIBCPP_INLINE_VISIBILITY
873 list& operator=(list&& __c)
875 __node_alloc_traits::propagate_on_container_move_assignment::value &&
876 is_nothrow_move_assignable<__node_allocator>::value);
878 _LIBCPP_INLINE_VISIBILITY
879 list& operator=(initializer_list<value_type> __il)
880 {assign(__il.begin(), __il.end()); return *this;}
882 _LIBCPP_INLINE_VISIBILITY
883 void assign(initializer_list<value_type> __il)
884 {assign(__il.begin(), __il.end());}
885 #endif // _LIBCPP_CXX03_LANG
887 template <class _InpIter>
888 void assign(_InpIter __f, _InpIter __l,
889 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
890 void assign(size_type __n, const value_type& __x);
892 _LIBCPP_INLINE_VISIBILITY
893 allocator_type get_allocator() const _NOEXCEPT;
895 _LIBCPP_INLINE_VISIBILITY
896 size_type size() const _NOEXCEPT {return base::__sz();}
897 _LIBCPP_INLINE_VISIBILITY
898 bool empty() const _NOEXCEPT {return base::empty();}
899 _LIBCPP_INLINE_VISIBILITY
900 size_type max_size() const _NOEXCEPT
902 return std::min<size_type>(
903 base::__node_alloc_max_size(),
904 numeric_limits<difference_type >::max());
907 _LIBCPP_INLINE_VISIBILITY
908 iterator begin() _NOEXCEPT {return base::begin();}
909 _LIBCPP_INLINE_VISIBILITY
910 const_iterator begin() const _NOEXCEPT {return base::begin();}
911 _LIBCPP_INLINE_VISIBILITY
912 iterator end() _NOEXCEPT {return base::end();}
913 _LIBCPP_INLINE_VISIBILITY
914 const_iterator end() const _NOEXCEPT {return base::end();}
915 _LIBCPP_INLINE_VISIBILITY
916 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
917 _LIBCPP_INLINE_VISIBILITY
918 const_iterator cend() const _NOEXCEPT {return base::end();}
920 _LIBCPP_INLINE_VISIBILITY
921 reverse_iterator rbegin() _NOEXCEPT
922 {return reverse_iterator(end());}
923 _LIBCPP_INLINE_VISIBILITY
924 const_reverse_iterator rbegin() const _NOEXCEPT
925 {return const_reverse_iterator(end());}
926 _LIBCPP_INLINE_VISIBILITY
927 reverse_iterator rend() _NOEXCEPT
928 {return reverse_iterator(begin());}
929 _LIBCPP_INLINE_VISIBILITY
930 const_reverse_iterator rend() const _NOEXCEPT
931 {return const_reverse_iterator(begin());}
932 _LIBCPP_INLINE_VISIBILITY
933 const_reverse_iterator crbegin() const _NOEXCEPT
934 {return const_reverse_iterator(end());}
935 _LIBCPP_INLINE_VISIBILITY
936 const_reverse_iterator crend() const _NOEXCEPT
937 {return const_reverse_iterator(begin());}
939 _LIBCPP_INLINE_VISIBILITY
942 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
943 return base::__end_.__next_->__as_node()->__value_;
945 _LIBCPP_INLINE_VISIBILITY
946 const_reference front() const
948 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
949 return base::__end_.__next_->__as_node()->__value_;
951 _LIBCPP_INLINE_VISIBILITY
954 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
955 return base::__end_.__prev_->__as_node()->__value_;
957 _LIBCPP_INLINE_VISIBILITY
958 const_reference back() const
960 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
961 return base::__end_.__prev_->__as_node()->__value_;
964 #ifndef _LIBCPP_CXX03_LANG
965 void push_front(value_type&& __x);
966 void push_back(value_type&& __x);
968 template <class... _Args>
969 #if _LIBCPP_STD_VER > 14
970 reference emplace_front(_Args&&... __args);
972 void emplace_front(_Args&&... __args);
974 template <class... _Args>
975 #if _LIBCPP_STD_VER > 14
976 reference emplace_back(_Args&&... __args);
978 void emplace_back(_Args&&... __args);
980 template <class... _Args>
981 iterator emplace(const_iterator __p, _Args&&... __args);
983 iterator insert(const_iterator __p, value_type&& __x);
985 _LIBCPP_INLINE_VISIBILITY
986 iterator insert(const_iterator __p, initializer_list<value_type> __il)
987 {return insert(__p, __il.begin(), __il.end());}
988 #endif // _LIBCPP_CXX03_LANG
990 void push_front(const value_type& __x);
991 void push_back(const value_type& __x);
993 iterator insert(const_iterator __p, const value_type& __x);
994 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
995 template <class _InpIter>
996 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
997 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
999 _LIBCPP_INLINE_VISIBILITY
1000 void swap(list& __c)
1001 #if _LIBCPP_STD_VER >= 14
1004 _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value ||
1005 __is_nothrow_swappable<__node_allocator>::value)
1008 _LIBCPP_INLINE_VISIBILITY
1009 void clear() _NOEXCEPT {base::clear();}
1014 iterator erase(const_iterator __p);
1015 iterator erase(const_iterator __f, const_iterator __l);
1017 void resize(size_type __n);
1018 void resize(size_type __n, const value_type& __x);
1020 void splice(const_iterator __p, list& __c);
1021 #ifndef _LIBCPP_CXX03_LANG
1022 _LIBCPP_INLINE_VISIBILITY
1023 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1024 _LIBCPP_INLINE_VISIBILITY
1025 void splice(const_iterator __p, list&& __c, const_iterator __i)
1026 {splice(__p, __c, __i);}
1027 _LIBCPP_INLINE_VISIBILITY
1028 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1029 {splice(__p, __c, __f, __l);}
1031 void splice(const_iterator __p, list& __c, const_iterator __i);
1032 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
1034 void remove(const value_type& __x);
1035 template <class _Pred> void remove_if(_Pred __pred);
1036 _LIBCPP_INLINE_VISIBILITY
1038 template <class _BinaryPred>
1039 void unique(_BinaryPred __binary_pred);
1040 _LIBCPP_INLINE_VISIBILITY
1041 void merge(list& __c);
1042 #ifndef _LIBCPP_CXX03_LANG
1043 _LIBCPP_INLINE_VISIBILITY
1044 void merge(list&& __c) {merge(__c);}
1046 template <class _Comp>
1047 _LIBCPP_INLINE_VISIBILITY
1048 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
1050 template <class _Comp>
1051 void merge(list& __c, _Comp __comp);
1053 _LIBCPP_INLINE_VISIBILITY
1055 template <class _Comp>
1056 _LIBCPP_INLINE_VISIBILITY
1057 void sort(_Comp __comp);
1059 void reverse() _NOEXCEPT;
1061 bool __invariants() const;
1063 #if _LIBCPP_DEBUG_LEVEL >= 2
1065 bool __dereferenceable(const const_iterator* __i) const;
1066 bool __decrementable(const const_iterator* __i) const;
1067 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1068 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1070 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1073 _LIBCPP_INLINE_VISIBILITY
1074 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
1075 _LIBCPP_INLINE_VISIBILITY
1076 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
1077 _LIBCPP_INLINE_VISIBILITY
1078 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
1079 iterator __iterator(size_type __n);
1080 template <class _Comp>
1081 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1083 void __move_assign(list& __c, true_type)
1084 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
1085 void __move_assign(list& __c, false_type);
1088 // Link in nodes [__f, __l] just prior to __p
1089 template <class _Tp, class _Alloc>
1092 list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
1094 __p->__prev_->__next_ = __f;
1095 __f->__prev_ = __p->__prev_;
1100 // Link in nodes [__f, __l] at the front of the list
1101 template <class _Tp, class _Alloc>
1104 list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
1106 __f->__prev_ = base::__end_as_link();
1107 __l->__next_ = base::__end_.__next_;
1108 __l->__next_->__prev_ = __l;
1109 base::__end_.__next_ = __f;
1112 // Link in nodes [__f, __l] at the front of the list
1113 template <class _Tp, class _Alloc>
1116 list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
1118 __l->__next_ = base::__end_as_link();
1119 __f->__prev_ = base::__end_.__prev_;
1120 __f->__prev_->__next_ = __f;
1121 base::__end_.__prev_ = __l;
1125 template <class _Tp, class _Alloc>
1127 typename list<_Tp, _Alloc>::iterator
1128 list<_Tp, _Alloc>::__iterator(size_type __n)
1130 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1131 : _VSTD::prev(end(), base::__sz() - __n);
1134 template <class _Tp, class _Alloc>
1135 list<_Tp, _Alloc>::list(size_type __n)
1137 #if _LIBCPP_DEBUG_LEVEL >= 2
1138 __get_db()->__insert_c(this);
1140 for (; __n > 0; --__n)
1141 #ifndef _LIBCPP_CXX03_LANG
1144 push_back(value_type());
1148 #if _LIBCPP_STD_VER > 11
1149 template <class _Tp, class _Alloc>
1150 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1152 #if _LIBCPP_DEBUG_LEVEL >= 2
1153 __get_db()->__insert_c(this);
1155 for (; __n > 0; --__n)
1160 template <class _Tp, class _Alloc>
1161 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1163 #if _LIBCPP_DEBUG_LEVEL >= 2
1164 __get_db()->__insert_c(this);
1166 for (; __n > 0; --__n)
1170 template <class _Tp, class _Alloc>
1171 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1174 #if _LIBCPP_DEBUG_LEVEL >= 2
1175 __get_db()->__insert_c(this);
1177 for (; __n > 0; --__n)
1181 template <class _Tp, class _Alloc>
1182 template <class _InpIter>
1183 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1184 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1186 #if _LIBCPP_DEBUG_LEVEL >= 2
1187 __get_db()->__insert_c(this);
1189 for (; __f != __l; ++__f)
1193 template <class _Tp, class _Alloc>
1194 template <class _InpIter>
1195 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1196 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1199 #if _LIBCPP_DEBUG_LEVEL >= 2
1200 __get_db()->__insert_c(this);
1202 for (; __f != __l; ++__f)
1206 template <class _Tp, class _Alloc>
1207 list<_Tp, _Alloc>::list(const list& __c)
1208 : base(allocator_type(
1209 __node_alloc_traits::select_on_container_copy_construction(
1210 __c.__node_alloc())))
1212 #if _LIBCPP_DEBUG_LEVEL >= 2
1213 __get_db()->__insert_c(this);
1215 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1219 template <class _Tp, class _Alloc>
1220 list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1223 #if _LIBCPP_DEBUG_LEVEL >= 2
1224 __get_db()->__insert_c(this);
1226 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1230 #ifndef _LIBCPP_CXX03_LANG
1232 template <class _Tp, class _Alloc>
1233 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1236 #if _LIBCPP_DEBUG_LEVEL >= 2
1237 __get_db()->__insert_c(this);
1239 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1240 __e = __il.end(); __i != __e; ++__i)
1244 template <class _Tp, class _Alloc>
1245 list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1247 #if _LIBCPP_DEBUG_LEVEL >= 2
1248 __get_db()->__insert_c(this);
1250 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1251 __e = __il.end(); __i != __e; ++__i)
1255 template <class _Tp, class _Alloc>
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>
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>
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_CXX03_LANG
1322 template <class _Tp, class _Alloc>
1325 list<_Tp, _Alloc>::operator=(const list& __c)
1329 base::__copy_assign_alloc(__c);
1330 assign(__c.begin(), __c.end());
1335 template <class _Tp, class _Alloc>
1336 template <class _InpIter>
1338 list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1339 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1341 iterator __i = begin();
1342 iterator __e = end();
1343 for (; __f != __l && __i != __e; ++__f, ++__i)
1346 insert(__e, __f, __l);
1349 #if _LIBCPP_DEBUG_LEVEL >= 2
1350 __get_db()->__invalidate_all(this);
1354 template <class _Tp, class _Alloc>
1356 list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1358 iterator __i = begin();
1359 iterator __e = end();
1360 for (; __n > 0 && __i != __e; --__n, ++__i)
1363 insert(__e, __n, __x);
1366 #if _LIBCPP_DEBUG_LEVEL >= 2
1367 __get_db()->__invalidate_all(this);
1371 template <class _Tp, class _Alloc>
1374 list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
1376 return allocator_type(base::__node_alloc());
1379 template <class _Tp, class _Alloc>
1380 typename list<_Tp, _Alloc>::iterator
1381 list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1383 #if _LIBCPP_DEBUG_LEVEL >= 2
1384 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1385 "list::insert(iterator, x) called with an iterator not"
1386 " referring to this list");
1388 __node_allocator& __na = base::__node_alloc();
1389 typedef __allocator_destructor<__node_allocator> _Dp;
1390 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1391 __hold->__prev_ = 0;
1392 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1393 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
1395 #if _LIBCPP_DEBUG_LEVEL >= 2
1396 return iterator(__hold.release()->__as_link(), this);
1398 return iterator(__hold.release()->__as_link());
1402 template <class _Tp, class _Alloc>
1403 typename list<_Tp, _Alloc>::iterator
1404 list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1406 #if _LIBCPP_DEBUG_LEVEL >= 2
1407 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1408 "list::insert(iterator, n, x) called with an iterator not"
1409 " referring to this list");
1410 iterator __r(__p.__ptr_, this);
1412 iterator __r(__p.__ptr_);
1417 __node_allocator& __na = base::__node_alloc();
1418 typedef __allocator_destructor<__node_allocator> _Dp;
1419 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1420 __hold->__prev_ = 0;
1421 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1423 #if _LIBCPP_DEBUG_LEVEL >= 2
1424 __r = iterator(__hold->__as_link(), this);
1426 __r = iterator(__hold->__as_link());
1430 #ifndef _LIBCPP_NO_EXCEPTIONS
1433 #endif // _LIBCPP_NO_EXCEPTIONS
1434 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1436 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1437 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1438 __e.__ptr_->__next_ = __hold->__as_link();
1439 __hold->__prev_ = __e.__ptr_;
1442 #ifndef _LIBCPP_NO_EXCEPTIONS
1448 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1449 __link_pointer __prev = __e.__ptr_->__prev_;
1450 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1453 #if _LIBCPP_DEBUG_LEVEL >= 2
1454 __e = iterator(__prev, this);
1456 __e = iterator(__prev);
1461 #endif // _LIBCPP_NO_EXCEPTIONS
1462 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1463 base::__sz() += __ds;
1468 template <class _Tp, class _Alloc>
1469 template <class _InpIter>
1470 typename list<_Tp, _Alloc>::iterator
1471 list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1472 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1474 #if _LIBCPP_DEBUG_LEVEL >= 2
1475 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1476 "list::insert(iterator, range) called with an iterator not"
1477 " referring to this list");
1478 iterator __r(__p.__ptr_, this);
1480 iterator __r(__p.__ptr_);
1485 __node_allocator& __na = base::__node_alloc();
1486 typedef __allocator_destructor<__node_allocator> _Dp;
1487 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1488 __hold->__prev_ = 0;
1489 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1491 #if _LIBCPP_DEBUG_LEVEL >= 2
1492 __r = iterator(__hold.get()->__as_link(), this);
1494 __r = iterator(__hold.get()->__as_link());
1498 #ifndef _LIBCPP_NO_EXCEPTIONS
1501 #endif // _LIBCPP_NO_EXCEPTIONS
1502 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
1504 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1505 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1506 __e.__ptr_->__next_ = __hold.get()->__as_link();
1507 __hold->__prev_ = __e.__ptr_;
1510 #ifndef _LIBCPP_NO_EXCEPTIONS
1516 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1517 __link_pointer __prev = __e.__ptr_->__prev_;
1518 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1521 #if _LIBCPP_DEBUG_LEVEL >= 2
1522 __e = iterator(__prev, this);
1524 __e = iterator(__prev);
1529 #endif // _LIBCPP_NO_EXCEPTIONS
1530 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1531 base::__sz() += __ds;
1536 template <class _Tp, class _Alloc>
1538 list<_Tp, _Alloc>::push_front(const value_type& __x)
1540 __node_allocator& __na = base::__node_alloc();
1541 typedef __allocator_destructor<__node_allocator> _Dp;
1542 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1543 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1544 __link_pointer __nl = __hold->__as_link();
1545 __link_nodes_at_front(__nl, __nl);
1550 template <class _Tp, class _Alloc>
1552 list<_Tp, _Alloc>::push_back(const value_type& __x)
1554 __node_allocator& __na = base::__node_alloc();
1555 typedef __allocator_destructor<__node_allocator> _Dp;
1556 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1557 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1558 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
1563 #ifndef _LIBCPP_CXX03_LANG
1565 template <class _Tp, class _Alloc>
1567 list<_Tp, _Alloc>::push_front(value_type&& __x)
1569 __node_allocator& __na = base::__node_alloc();
1570 typedef __allocator_destructor<__node_allocator> _Dp;
1571 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1572 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1573 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
1578 template <class _Tp, class _Alloc>
1580 list<_Tp, _Alloc>::push_back(value_type&& __x)
1582 __node_allocator& __na = base::__node_alloc();
1583 typedef __allocator_destructor<__node_allocator> _Dp;
1584 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1585 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1586 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
1591 template <class _Tp, class _Alloc>
1592 template <class... _Args>
1593 #if _LIBCPP_STD_VER > 14
1594 typename list<_Tp, _Alloc>::reference
1598 list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1600 __node_allocator& __na = base::__node_alloc();
1601 typedef __allocator_destructor<__node_allocator> _Dp;
1602 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1603 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1604 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
1606 #if _LIBCPP_STD_VER > 14
1607 return __hold.release()->__value_;
1613 template <class _Tp, class _Alloc>
1614 template <class... _Args>
1615 #if _LIBCPP_STD_VER > 14
1616 typename list<_Tp, _Alloc>::reference
1620 list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1622 __node_allocator& __na = base::__node_alloc();
1623 typedef __allocator_destructor<__node_allocator> _Dp;
1624 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1625 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1626 __link_pointer __nl = __hold->__as_link();
1627 __link_nodes_at_back(__nl, __nl);
1629 #if _LIBCPP_STD_VER > 14
1630 return __hold.release()->__value_;
1636 template <class _Tp, class _Alloc>
1637 template <class... _Args>
1638 typename list<_Tp, _Alloc>::iterator
1639 list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1641 #if _LIBCPP_DEBUG_LEVEL >= 2
1642 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1643 "list::emplace(iterator, args...) called with an iterator not"
1644 " referring to this list");
1646 __node_allocator& __na = base::__node_alloc();
1647 typedef __allocator_destructor<__node_allocator> _Dp;
1648 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1649 __hold->__prev_ = 0;
1650 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1651 __link_pointer __nl = __hold.get()->__as_link();
1652 __link_nodes(__p.__ptr_, __nl, __nl);
1655 #if _LIBCPP_DEBUG_LEVEL >= 2
1656 return iterator(__nl, this);
1658 return iterator(__nl);
1662 template <class _Tp, class _Alloc>
1663 typename list<_Tp, _Alloc>::iterator
1664 list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1666 #if _LIBCPP_DEBUG_LEVEL >= 2
1667 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1668 "list::insert(iterator, x) called with an iterator not"
1669 " referring to this list");
1671 __node_allocator& __na = base::__node_alloc();
1672 typedef __allocator_destructor<__node_allocator> _Dp;
1673 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1674 __hold->__prev_ = 0;
1675 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1676 __link_pointer __nl = __hold->__as_link();
1677 __link_nodes(__p.__ptr_, __nl, __nl);
1680 #if _LIBCPP_DEBUG_LEVEL >= 2
1681 return iterator(__nl, this);
1683 return iterator(__nl);
1687 #endif // _LIBCPP_CXX03_LANG
1689 template <class _Tp, class _Alloc>
1691 list<_Tp, _Alloc>::pop_front()
1693 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
1694 __node_allocator& __na = base::__node_alloc();
1695 __link_pointer __n = base::__end_.__next_;
1696 base::__unlink_nodes(__n, __n);
1698 #if _LIBCPP_DEBUG_LEVEL >= 2
1699 __c_node* __c = __get_db()->__find_c_and_lock(this);
1700 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1703 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1704 if (__i->__ptr_ == __n)
1706 (*__p)->__c_ = nullptr;
1707 if (--__c->end_ != __p)
1708 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1711 __get_db()->unlock();
1713 __node_pointer __np = __n->__as_node();
1714 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1715 __node_alloc_traits::deallocate(__na, __np, 1);
1718 template <class _Tp, class _Alloc>
1720 list<_Tp, _Alloc>::pop_back()
1722 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
1723 __node_allocator& __na = base::__node_alloc();
1724 __link_pointer __n = base::__end_.__prev_;
1725 base::__unlink_nodes(__n, __n);
1727 #if _LIBCPP_DEBUG_LEVEL >= 2
1728 __c_node* __c = __get_db()->__find_c_and_lock(this);
1729 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1732 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1733 if (__i->__ptr_ == __n)
1735 (*__p)->__c_ = nullptr;
1736 if (--__c->end_ != __p)
1737 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1740 __get_db()->unlock();
1742 __node_pointer __np = __n->__as_node();
1743 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1744 __node_alloc_traits::deallocate(__na, __np, 1);
1747 template <class _Tp, class _Alloc>
1748 typename list<_Tp, _Alloc>::iterator
1749 list<_Tp, _Alloc>::erase(const_iterator __p)
1751 #if _LIBCPP_DEBUG_LEVEL >= 2
1752 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1753 "list::erase(iterator) called with an iterator not"
1754 " referring to this list");
1756 _LIBCPP_ASSERT(__p != end(),
1757 "list::erase(iterator) called with a non-dereferenceable iterator");
1758 __node_allocator& __na = base::__node_alloc();
1759 __link_pointer __n = __p.__ptr_;
1760 __link_pointer __r = __n->__next_;
1761 base::__unlink_nodes(__n, __n);
1763 #if _LIBCPP_DEBUG_LEVEL >= 2
1764 __c_node* __c = __get_db()->__find_c_and_lock(this);
1765 for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
1768 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
1769 if (__i->__ptr_ == __n)
1771 (*__ip)->__c_ = nullptr;
1772 if (--__c->end_ != __ip)
1773 memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
1776 __get_db()->unlock();
1778 __node_pointer __np = __n->__as_node();
1779 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1780 __node_alloc_traits::deallocate(__na, __np, 1);
1781 #if _LIBCPP_DEBUG_LEVEL >= 2
1782 return iterator(__r, this);
1784 return iterator(__r);
1788 template <class _Tp, class _Alloc>
1789 typename list<_Tp, _Alloc>::iterator
1790 list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1792 #if _LIBCPP_DEBUG_LEVEL >= 2
1793 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1794 "list::erase(iterator, iterator) called with an iterator not"
1795 " referring to this list");
1796 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
1797 "list::erase(iterator, iterator) called with an iterator not"
1798 " referring to this list");
1802 __node_allocator& __na = base::__node_alloc();
1803 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1806 __link_pointer __n = __f.__ptr_;
1809 #if _LIBCPP_DEBUG_LEVEL >= 2
1810 __c_node* __c = __get_db()->__find_c_and_lock(this);
1811 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1814 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1815 if (__i->__ptr_ == __n)
1817 (*__p)->__c_ = nullptr;
1818 if (--__c->end_ != __p)
1819 memmove(__p, __p+1, (__c->end_ - __p)*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);
1829 #if _LIBCPP_DEBUG_LEVEL >= 2
1830 return iterator(__l.__ptr_, this);
1832 return iterator(__l.__ptr_);
1836 template <class _Tp, class _Alloc>
1838 list<_Tp, _Alloc>::resize(size_type __n)
1840 if (__n < base::__sz())
1841 erase(__iterator(__n), end());
1842 else if (__n > base::__sz())
1844 __n -= base::__sz();
1846 __node_allocator& __na = base::__node_alloc();
1847 typedef __allocator_destructor<__node_allocator> _Dp;
1848 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1849 __hold->__prev_ = 0;
1850 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1852 #if _LIBCPP_DEBUG_LEVEL >= 2
1853 iterator __r = iterator(__hold.release()->__as_link(), this);
1855 iterator __r = iterator(__hold.release()->__as_link());
1858 #ifndef _LIBCPP_NO_EXCEPTIONS
1861 #endif // _LIBCPP_NO_EXCEPTIONS
1862 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1864 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1865 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1866 __e.__ptr_->__next_ = __hold.get()->__as_link();
1867 __hold->__prev_ = __e.__ptr_;
1870 #ifndef _LIBCPP_NO_EXCEPTIONS
1876 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1877 __link_pointer __prev = __e.__ptr_->__prev_;
1878 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1881 #if _LIBCPP_DEBUG_LEVEL >= 2
1882 __e = iterator(__prev, this);
1884 __e = iterator(__prev);
1889 #endif // _LIBCPP_NO_EXCEPTIONS
1890 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1891 base::__sz() += __ds;
1895 template <class _Tp, class _Alloc>
1897 list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1899 if (__n < base::__sz())
1900 erase(__iterator(__n), end());
1901 else if (__n > base::__sz())
1903 __n -= base::__sz();
1905 __node_allocator& __na = base::__node_alloc();
1906 typedef __allocator_destructor<__node_allocator> _Dp;
1907 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1908 __hold->__prev_ = 0;
1909 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1911 __link_pointer __nl = __hold.release()->__as_link();
1912 #if _LIBCPP_DEBUG_LEVEL >= 2
1913 iterator __r = iterator(__nl, this);
1915 iterator __r = iterator(__nl);
1918 #ifndef _LIBCPP_NO_EXCEPTIONS
1921 #endif // _LIBCPP_NO_EXCEPTIONS
1922 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1924 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1925 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1926 __e.__ptr_->__next_ = __hold.get()->__as_link();
1927 __hold->__prev_ = __e.__ptr_;
1930 #ifndef _LIBCPP_NO_EXCEPTIONS
1936 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1937 __link_pointer __prev = __e.__ptr_->__prev_;
1938 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1941 #if _LIBCPP_DEBUG_LEVEL >= 2
1942 __e = iterator(__prev, this);
1944 __e = iterator(__prev);
1949 #endif // _LIBCPP_NO_EXCEPTIONS
1950 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1951 base::__sz() += __ds;
1955 template <class _Tp, class _Alloc>
1957 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1959 _LIBCPP_ASSERT(this != &__c,
1960 "list::splice(iterator, list) called with this == &list");
1961 #if _LIBCPP_DEBUG_LEVEL >= 2
1962 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1963 "list::splice(iterator, list) called with an iterator not"
1964 " referring to this list");
1968 __link_pointer __f = __c.__end_.__next_;
1969 __link_pointer __l = __c.__end_.__prev_;
1970 base::__unlink_nodes(__f, __l);
1971 __link_nodes(__p.__ptr_, __f, __l);
1972 base::__sz() += __c.__sz();
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** __ip = __cn2->end_; __ip != __cn2->beg_;)
1981 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
1982 if (__i->__ptr_ != __c.__end_as_link())
1984 __cn1->__add(*__ip);
1985 (*__ip)->__c_ = __cn1;
1986 if (--__cn2->end_ != __ip)
1987 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
1995 template <class _Tp, class _Alloc>
1997 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1999 #if _LIBCPP_DEBUG_LEVEL >= 2
2000 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2001 "list::splice(iterator, list, iterator) called with first iterator not"
2002 " referring to this list");
2003 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
2004 "list::splice(iterator, list, iterator) called with second iterator not"
2005 " referring to list argument");
2006 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
2007 "list::splice(iterator, list, iterator) called with second iterator not"
2010 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
2012 __link_pointer __f = __i.__ptr_;
2013 base::__unlink_nodes(__f, __f);
2014 __link_nodes(__p.__ptr_, __f, __f);
2017 #if _LIBCPP_DEBUG_LEVEL >= 2
2018 __libcpp_db* __db = __get_db();
2019 __c_node* __cn1 = __db->__find_c_and_lock(this);
2020 __c_node* __cn2 = __db->__find_c(&__c);
2021 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
2024 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
2025 if (__j->__ptr_ == __f)
2027 __cn1->__add(*__ip);
2028 (*__ip)->__c_ = __cn1;
2029 if (--__cn2->end_ != __ip)
2030 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2038 template <class _Tp, class _Alloc>
2040 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
2042 #if _LIBCPP_DEBUG_LEVEL >= 2
2043 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2044 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2045 " referring to this list");
2046 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2047 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2048 " referring to list argument");
2051 for (const_iterator __i = __f; __i != __l; ++__i)
2052 _LIBCPP_ASSERT(__i != __p,
2053 "list::splice(iterator, list, iterator, iterator)"
2054 " called with the first iterator within the range"
2055 " of the second and third iterators");
2062 size_type __s = _VSTD::distance(__f, __l);
2064 base::__sz() += __s;
2066 __link_pointer __first = __f.__ptr_;
2068 __link_pointer __last = __l.__ptr_;
2069 base::__unlink_nodes(__first, __last);
2070 __link_nodes(__p.__ptr_, __first, __last);
2071 #if _LIBCPP_DEBUG_LEVEL >= 2
2072 __libcpp_db* __db = __get_db();
2073 __c_node* __cn1 = __db->__find_c_and_lock(this);
2074 __c_node* __cn2 = __db->__find_c(&__c);
2075 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
2078 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
2079 for (__link_pointer __k = __f.__ptr_;
2080 __k != __l.__ptr_; __k = __k->__next_)
2082 if (__j->__ptr_ == __k)
2084 __cn1->__add(*__ip);
2085 (*__ip)->__c_ = __cn1;
2086 if (--__cn2->end_ != __ip)
2087 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2096 template <class _Tp, class _Alloc>
2098 list<_Tp, _Alloc>::remove(const value_type& __x)
2100 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
2101 for (const_iterator __i = begin(), __e = end(); __i != __e;)
2105 const_iterator __j = _VSTD::next(__i);
2106 for (; __j != __e && *__j == __x; ++__j)
2108 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2118 template <class _Tp, class _Alloc>
2119 template <class _Pred>
2121 list<_Tp, _Alloc>::remove_if(_Pred __pred)
2123 for (iterator __i = begin(), __e = end(); __i != __e;)
2127 iterator __j = _VSTD::next(__i);
2128 for (; __j != __e && __pred(*__j); ++__j)
2130 __i = erase(__i, __j);
2139 template <class _Tp, class _Alloc>
2142 list<_Tp, _Alloc>::unique()
2144 unique(__equal_to<value_type>());
2147 template <class _Tp, class _Alloc>
2148 template <class _BinaryPred>
2150 list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2152 for (iterator __i = begin(), __e = end(); __i != __e;)
2154 iterator __j = _VSTD::next(__i);
2155 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2158 __i = erase(__i, __j);
2162 template <class _Tp, class _Alloc>
2165 list<_Tp, _Alloc>::merge(list& __c)
2167 merge(__c, __less<value_type>());
2170 template <class _Tp, class _Alloc>
2171 template <class _Comp>
2173 list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2177 iterator __f1 = begin();
2178 iterator __e1 = end();
2179 iterator __f2 = __c.begin();
2180 iterator __e2 = __c.end();
2181 while (__f1 != __e1 && __f2 != __e2)
2183 if (__comp(*__f2, *__f1))
2186 iterator __m2 = _VSTD::next(__f2);
2187 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2189 base::__sz() += __ds;
2191 __link_pointer __f = __f2.__ptr_;
2192 __link_pointer __l = __m2.__ptr_->__prev_;
2194 base::__unlink_nodes(__f, __l);
2195 __m2 = _VSTD::next(__f1);
2196 __link_nodes(__f1.__ptr_, __f, __l);
2203 #if _LIBCPP_DEBUG_LEVEL >= 2
2204 __libcpp_db* __db = __get_db();
2205 __c_node* __cn1 = __db->__find_c_and_lock(this);
2206 __c_node* __cn2 = __db->__find_c(&__c);
2207 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2210 iterator* __i = static_cast<iterator*>((*__p)->__i_);
2211 if (__i->__ptr_ != __c.__end_as_link())
2214 (*__p)->__c_ = __cn1;
2215 if (--__cn2->end_ != __p)
2216 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2224 template <class _Tp, class _Alloc>
2227 list<_Tp, _Alloc>::sort()
2229 sort(__less<value_type>());
2232 template <class _Tp, class _Alloc>
2233 template <class _Comp>
2236 list<_Tp, _Alloc>::sort(_Comp __comp)
2238 __sort(begin(), end(), base::__sz(), __comp);
2241 template <class _Tp, class _Alloc>
2242 template <class _Comp>
2243 typename list<_Tp, _Alloc>::iterator
2244 list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2252 if (__comp(*--__e2, *__f1))
2254 __link_pointer __f = __e2.__ptr_;
2255 base::__unlink_nodes(__f, __f);
2256 __link_nodes(__f1.__ptr_, __f, __f);
2261 size_type __n2 = __n / 2;
2262 iterator __e1 = _VSTD::next(__f1, __n2);
2263 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2264 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2265 if (__comp(*__f2, *__f1))
2267 iterator __m2 = _VSTD::next(__f2);
2268 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2270 __link_pointer __f = __f2.__ptr_;
2271 __link_pointer __l = __m2.__ptr_->__prev_;
2274 base::__unlink_nodes(__f, __l);
2275 __m2 = _VSTD::next(__f1);
2276 __link_nodes(__f1.__ptr_, __f, __l);
2281 while (__f1 != __e1 && __f2 != __e2)
2283 if (__comp(*__f2, *__f1))
2285 iterator __m2 = _VSTD::next(__f2);
2286 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2288 __link_pointer __f = __f2.__ptr_;
2289 __link_pointer __l = __m2.__ptr_->__prev_;
2293 base::__unlink_nodes(__f, __l);
2294 __m2 = _VSTD::next(__f1);
2295 __link_nodes(__f1.__ptr_, __f, __l);
2304 template <class _Tp, class _Alloc>
2306 list<_Tp, _Alloc>::reverse() _NOEXCEPT
2308 if (base::__sz() > 1)
2310 iterator __e = end();
2311 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2313 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
2314 __i.__ptr_ = __i.__ptr_->__prev_;
2316 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
2320 template <class _Tp, class _Alloc>
2322 list<_Tp, _Alloc>::__invariants() const
2324 return size() == _VSTD::distance(begin(), end());
2327 #if _LIBCPP_DEBUG_LEVEL >= 2
2329 template <class _Tp, class _Alloc>
2331 list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2333 return __i->__ptr_ != this->__end_as_link();
2336 template <class _Tp, class _Alloc>
2338 list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2340 return !empty() && __i->__ptr_ != base::__end_.__next_;
2343 template <class _Tp, class _Alloc>
2345 list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2350 template <class _Tp, class _Alloc>
2352 list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2357 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2359 template <class _Tp, class _Alloc>
2360 inline _LIBCPP_INLINE_VISIBILITY
2362 operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2364 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2367 template <class _Tp, class _Alloc>
2368 inline _LIBCPP_INLINE_VISIBILITY
2370 operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2372 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2375 template <class _Tp, class _Alloc>
2376 inline _LIBCPP_INLINE_VISIBILITY
2378 operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2380 return !(__x == __y);
2383 template <class _Tp, class _Alloc>
2384 inline _LIBCPP_INLINE_VISIBILITY
2386 operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2391 template <class _Tp, class _Alloc>
2392 inline _LIBCPP_INLINE_VISIBILITY
2394 operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2396 return !(__x < __y);
2399 template <class _Tp, class _Alloc>
2400 inline _LIBCPP_INLINE_VISIBILITY
2402 operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2404 return !(__y < __x);
2407 template <class _Tp, class _Alloc>
2408 inline _LIBCPP_INLINE_VISIBILITY
2410 swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
2411 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2416 _LIBCPP_END_NAMESPACE_STD
2418 #endif // _LIBCPP_LIST