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>
182 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
183 #pragma GCC system_header
187 #include <__undef_macros>
190 _LIBCPP_BEGIN_NAMESPACE_STD
192 template <class _Tp, class _VoidPtr> struct __list_node;
193 template <class _Tp, class _VoidPtr> struct __list_node_base;
195 template <class _Tp, class _VoidPtr>
196 struct __list_node_pointer_traits {
197 typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
199 typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
202 #if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
203 typedef __base_pointer __link_pointer;
205 typedef typename conditional<
206 is_pointer<_VoidPtr>::value,
209 >::type __link_pointer;
212 typedef typename conditional<
213 is_same<__link_pointer, __node_pointer>::value,
216 >::type __non_link_pointer;
218 static _LIBCPP_INLINE_VISIBILITY
219 __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
223 static _LIBCPP_INLINE_VISIBILITY
224 __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
225 return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
230 template <class _Tp, class _VoidPtr>
231 struct __list_node_base
233 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
234 typedef typename _NodeTraits::__node_pointer __node_pointer;
235 typedef typename _NodeTraits::__base_pointer __base_pointer;
236 typedef typename _NodeTraits::__link_pointer __link_pointer;
238 __link_pointer __prev_;
239 __link_pointer __next_;
241 _LIBCPP_INLINE_VISIBILITY
242 __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
243 __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
245 _LIBCPP_INLINE_VISIBILITY
246 __base_pointer __self() {
247 return pointer_traits<__base_pointer>::pointer_to(*this);
250 _LIBCPP_INLINE_VISIBILITY
251 __node_pointer __as_node() {
252 return static_cast<__node_pointer>(__self());
256 template <class _Tp, class _VoidPtr>
258 : public __list_node_base<_Tp, _VoidPtr>
262 typedef __list_node_base<_Tp, _VoidPtr> __base;
263 typedef typename __base::__link_pointer __link_pointer;
265 _LIBCPP_INLINE_VISIBILITY
266 __link_pointer __as_link() {
267 return static_cast<__link_pointer>(__base::__self());
271 template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
272 template <class _Tp, class _Alloc> class __list_imp;
273 template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
275 template <class _Tp, class _VoidPtr>
276 class _LIBCPP_TEMPLATE_VIS __list_iterator
278 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
279 typedef typename _NodeTraits::__link_pointer __link_pointer;
281 __link_pointer __ptr_;
283 #if _LIBCPP_DEBUG_LEVEL >= 2
284 _LIBCPP_INLINE_VISIBILITY
285 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
288 __get_db()->__insert_ic(this, __c);
291 _LIBCPP_INLINE_VISIBILITY
292 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
297 template<class, class> friend class list;
298 template<class, class> friend class __list_imp;
299 template<class, class> friend class __list_const_iterator;
301 typedef bidirectional_iterator_tag iterator_category;
302 typedef _Tp value_type;
303 typedef value_type& reference;
304 typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
305 typedef typename pointer_traits<pointer>::difference_type difference_type;
307 _LIBCPP_INLINE_VISIBILITY
308 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
310 #if _LIBCPP_DEBUG_LEVEL >= 2
311 __get_db()->__insert_i(this);
315 #if _LIBCPP_DEBUG_LEVEL >= 2
317 _LIBCPP_INLINE_VISIBILITY
318 __list_iterator(const __list_iterator& __p)
321 __get_db()->__iterator_copy(this, &__p);
324 _LIBCPP_INLINE_VISIBILITY
327 __get_db()->__erase_i(this);
330 _LIBCPP_INLINE_VISIBILITY
331 __list_iterator& operator=(const __list_iterator& __p)
335 __get_db()->__iterator_copy(this, &__p);
341 #endif // _LIBCPP_DEBUG_LEVEL >= 2
343 _LIBCPP_INLINE_VISIBILITY
344 reference operator*() const
346 #if _LIBCPP_DEBUG_LEVEL >= 2
347 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
348 "Attempted to dereference a non-dereferenceable list::iterator");
350 return __ptr_->__as_node()->__value_;
352 _LIBCPP_INLINE_VISIBILITY
353 pointer operator->() const
355 #if _LIBCPP_DEBUG_LEVEL >= 2
356 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
357 "Attempted to dereference a non-dereferenceable list::iterator");
359 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
362 _LIBCPP_INLINE_VISIBILITY
363 __list_iterator& operator++()
365 #if _LIBCPP_DEBUG_LEVEL >= 2
366 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
367 "Attempted to increment non-incrementable list::iterator");
369 __ptr_ = __ptr_->__next_;
372 _LIBCPP_INLINE_VISIBILITY
373 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
375 _LIBCPP_INLINE_VISIBILITY
376 __list_iterator& operator--()
378 #if _LIBCPP_DEBUG_LEVEL >= 2
379 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
380 "Attempted to decrement non-decrementable list::iterator");
382 __ptr_ = __ptr_->__prev_;
385 _LIBCPP_INLINE_VISIBILITY
386 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
388 friend _LIBCPP_INLINE_VISIBILITY
389 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
391 return __x.__ptr_ == __y.__ptr_;
393 friend _LIBCPP_INLINE_VISIBILITY
394 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
395 {return !(__x == __y);}
398 template <class _Tp, class _VoidPtr>
399 class _LIBCPP_TEMPLATE_VIS __list_const_iterator
401 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
402 typedef typename _NodeTraits::__link_pointer __link_pointer;
404 __link_pointer __ptr_;
406 #if _LIBCPP_DEBUG_LEVEL >= 2
407 _LIBCPP_INLINE_VISIBILITY
408 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
411 __get_db()->__insert_ic(this, __c);
414 _LIBCPP_INLINE_VISIBILITY
415 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
418 template<class, class> friend class list;
419 template<class, class> friend class __list_imp;
421 typedef bidirectional_iterator_tag iterator_category;
422 typedef _Tp value_type;
423 typedef const value_type& reference;
424 typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
425 typedef typename pointer_traits<pointer>::difference_type difference_type;
427 _LIBCPP_INLINE_VISIBILITY
428 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
430 #if _LIBCPP_DEBUG_LEVEL >= 2
431 __get_db()->__insert_i(this);
434 _LIBCPP_INLINE_VISIBILITY
435 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
438 #if _LIBCPP_DEBUG_LEVEL >= 2
439 __get_db()->__iterator_copy(this, &__p);
443 #if _LIBCPP_DEBUG_LEVEL >= 2
445 _LIBCPP_INLINE_VISIBILITY
446 __list_const_iterator(const __list_const_iterator& __p)
449 __get_db()->__iterator_copy(this, &__p);
452 _LIBCPP_INLINE_VISIBILITY
453 ~__list_const_iterator()
455 __get_db()->__erase_i(this);
458 _LIBCPP_INLINE_VISIBILITY
459 __list_const_iterator& operator=(const __list_const_iterator& __p)
463 __get_db()->__iterator_copy(this, &__p);
469 #endif // _LIBCPP_DEBUG_LEVEL >= 2
470 _LIBCPP_INLINE_VISIBILITY
471 reference operator*() const
473 #if _LIBCPP_DEBUG_LEVEL >= 2
474 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
475 "Attempted to dereference a non-dereferenceable list::const_iterator");
477 return __ptr_->__as_node()->__value_;
479 _LIBCPP_INLINE_VISIBILITY
480 pointer operator->() const
482 #if _LIBCPP_DEBUG_LEVEL >= 2
483 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
484 "Attempted to dereference a non-dereferenceable list::iterator");
486 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
489 _LIBCPP_INLINE_VISIBILITY
490 __list_const_iterator& operator++()
492 #if _LIBCPP_DEBUG_LEVEL >= 2
493 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
494 "Attempted to increment non-incrementable list::const_iterator");
496 __ptr_ = __ptr_->__next_;
499 _LIBCPP_INLINE_VISIBILITY
500 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
502 _LIBCPP_INLINE_VISIBILITY
503 __list_const_iterator& operator--()
505 #if _LIBCPP_DEBUG_LEVEL >= 2
506 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
507 "Attempted to decrement non-decrementable list::const_iterator");
509 __ptr_ = __ptr_->__prev_;
512 _LIBCPP_INLINE_VISIBILITY
513 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
515 friend _LIBCPP_INLINE_VISIBILITY
516 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
518 return __x.__ptr_ == __y.__ptr_;
520 friend _LIBCPP_INLINE_VISIBILITY
521 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
522 {return !(__x == __y);}
525 template <class _Tp, class _Alloc>
528 __list_imp(const __list_imp&);
529 __list_imp& operator=(const __list_imp&);
531 typedef _Tp value_type;
532 typedef _Alloc allocator_type;
533 typedef allocator_traits<allocator_type> __alloc_traits;
534 typedef typename __alloc_traits::size_type size_type;
535 typedef typename __alloc_traits::void_pointer __void_pointer;
536 typedef __list_iterator<value_type, __void_pointer> iterator;
537 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
538 typedef __list_node_base<value_type, __void_pointer> __node_base;
539 typedef __list_node<value_type, __void_pointer> __node;
540 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
541 typedef allocator_traits<__node_allocator> __node_alloc_traits;
542 typedef typename __node_alloc_traits::pointer __node_pointer;
543 typedef typename __node_alloc_traits::pointer __node_const_pointer;
544 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
545 typedef typename __node_pointer_traits::__link_pointer __link_pointer;
546 typedef __link_pointer __link_const_pointer;
547 typedef typename __alloc_traits::pointer pointer;
548 typedef typename __alloc_traits::const_pointer const_pointer;
549 typedef typename __alloc_traits::difference_type difference_type;
551 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
552 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
555 __compressed_pair<size_type, __node_allocator> __size_alloc_;
557 _LIBCPP_INLINE_VISIBILITY
558 __link_pointer __end_as_link() const _NOEXCEPT {
559 return __node_pointer_traits::__unsafe_link_pointer_cast(
560 const_cast<__node_base&>(__end_).__self());
563 _LIBCPP_INLINE_VISIBILITY
564 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
565 _LIBCPP_INLINE_VISIBILITY
566 const size_type& __sz() const _NOEXCEPT
567 {return __size_alloc_.first();}
568 _LIBCPP_INLINE_VISIBILITY
569 __node_allocator& __node_alloc() _NOEXCEPT
570 {return __size_alloc_.second();}
571 _LIBCPP_INLINE_VISIBILITY
572 const __node_allocator& __node_alloc() const _NOEXCEPT
573 {return __size_alloc_.second();}
575 _LIBCPP_INLINE_VISIBILITY
576 size_type __node_alloc_max_size() const _NOEXCEPT {
577 return __node_alloc_traits::max_size(__node_alloc());
579 _LIBCPP_INLINE_VISIBILITY
580 static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
582 _LIBCPP_INLINE_VISIBILITY
584 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
585 _LIBCPP_INLINE_VISIBILITY
586 __list_imp(const allocator_type& __a);
588 void clear() _NOEXCEPT;
589 _LIBCPP_INLINE_VISIBILITY
590 bool empty() const _NOEXCEPT {return __sz() == 0;}
592 _LIBCPP_INLINE_VISIBILITY
593 iterator begin() _NOEXCEPT
595 #if _LIBCPP_DEBUG_LEVEL >= 2
596 return iterator(__end_.__next_, this);
598 return iterator(__end_.__next_);
601 _LIBCPP_INLINE_VISIBILITY
602 const_iterator begin() const _NOEXCEPT
604 #if _LIBCPP_DEBUG_LEVEL >= 2
605 return const_iterator(__end_.__next_, this);
607 return const_iterator(__end_.__next_);
610 _LIBCPP_INLINE_VISIBILITY
611 iterator end() _NOEXCEPT
613 #if _LIBCPP_DEBUG_LEVEL >= 2
614 return iterator(__end_as_link(), this);
616 return iterator(__end_as_link());
619 _LIBCPP_INLINE_VISIBILITY
620 const_iterator end() const _NOEXCEPT
622 #if _LIBCPP_DEBUG_LEVEL >= 2
623 return const_iterator(__end_as_link(), this);
625 return const_iterator(__end_as_link());
629 void swap(__list_imp& __c)
630 #if _LIBCPP_STD_VER >= 14
633 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
634 __is_nothrow_swappable<allocator_type>::value);
637 _LIBCPP_INLINE_VISIBILITY
638 void __copy_assign_alloc(const __list_imp& __c)
639 {__copy_assign_alloc(__c, integral_constant<bool,
640 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
642 _LIBCPP_INLINE_VISIBILITY
643 void __move_assign_alloc(__list_imp& __c)
645 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
646 is_nothrow_move_assignable<__node_allocator>::value)
647 {__move_assign_alloc(__c, integral_constant<bool,
648 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
651 _LIBCPP_INLINE_VISIBILITY
652 void __copy_assign_alloc(const __list_imp& __c, true_type)
654 if (__node_alloc() != __c.__node_alloc())
656 __node_alloc() = __c.__node_alloc();
659 _LIBCPP_INLINE_VISIBILITY
660 void __copy_assign_alloc(const __list_imp&, false_type)
663 _LIBCPP_INLINE_VISIBILITY
664 void __move_assign_alloc(__list_imp& __c, true_type)
665 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
667 __node_alloc() = _VSTD::move(__c.__node_alloc());
670 _LIBCPP_INLINE_VISIBILITY
671 void __move_assign_alloc(__list_imp&, false_type)
675 _LIBCPP_INLINE_VISIBILITY
676 void __invalidate_all_iterators() {
677 #if _LIBCPP_DEBUG_LEVEL >= 2
678 __get_db()->__invalidate_all(this);
683 // Unlink nodes [__f, __l]
684 template <class _Tp, class _Alloc>
687 __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
690 __f->__prev_->__next_ = __l->__next_;
691 __l->__next_->__prev_ = __f->__prev_;
694 template <class _Tp, class _Alloc>
696 __list_imp<_Tp, _Alloc>::__list_imp()
697 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
702 template <class _Tp, class _Alloc>
704 __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
705 : __size_alloc_(0, __node_allocator(__a))
709 template <class _Tp, class _Alloc>
710 __list_imp<_Tp, _Alloc>::~__list_imp()
713 #if _LIBCPP_DEBUG_LEVEL >= 2
714 __get_db()->__erase_c(this);
718 template <class _Tp, class _Alloc>
720 __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
724 __node_allocator& __na = __node_alloc();
725 __link_pointer __f = __end_.__next_;
726 __link_pointer __l = __end_as_link();
727 __unlink_nodes(__f, __l->__prev_);
731 __node_pointer __np = __f->__as_node();
733 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
734 __node_alloc_traits::deallocate(__na, __np, 1);
736 __invalidate_all_iterators();
740 template <class _Tp, class _Alloc>
742 __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
743 #if _LIBCPP_STD_VER >= 14
746 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
747 __is_nothrow_swappable<allocator_type>::value)
750 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
751 this->__node_alloc() == __c.__node_alloc(),
752 "list::swap: Either propagate_on_container_swap must be true"
753 " or the allocators must compare equal");
755 __swap_allocator(__node_alloc(), __c.__node_alloc());
756 swap(__sz(), __c.__sz());
757 swap(__end_, __c.__end_);
759 __end_.__next_ = __end_.__prev_ = __end_as_link();
761 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
763 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
765 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
767 #if _LIBCPP_DEBUG_LEVEL >= 2
768 __libcpp_db* __db = __get_db();
769 __c_node* __cn1 = __db->__find_c_and_lock(this);
770 __c_node* __cn2 = __db->__find_c(&__c);
771 std::swap(__cn1->beg_, __cn2->beg_);
772 std::swap(__cn1->end_, __cn2->end_);
773 std::swap(__cn1->cap_, __cn2->cap_);
774 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
777 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
778 if (__i->__ptr_ == __c.__end_as_link())
781 if (--__cn1->end_ != __p)
782 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
785 (*__p)->__c_ = __cn1;
787 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
790 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
791 if (__i->__ptr_ == __end_as_link())
794 if (--__cn2->end_ != __p)
795 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
798 (*__p)->__c_ = __cn2;
804 template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
805 class _LIBCPP_TEMPLATE_VIS list
806 : private __list_imp<_Tp, _Alloc>
808 typedef __list_imp<_Tp, _Alloc> base;
809 typedef typename base::__node __node;
810 typedef typename base::__node_allocator __node_allocator;
811 typedef typename base::__node_pointer __node_pointer;
812 typedef typename base::__node_alloc_traits __node_alloc_traits;
813 typedef typename base::__node_base __node_base;
814 typedef typename base::__node_base_pointer __node_base_pointer;
815 typedef typename base::__link_pointer __link_pointer;
818 typedef _Tp value_type;
819 typedef _Alloc allocator_type;
820 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
821 "Invalid allocator::value_type");
822 typedef value_type& reference;
823 typedef const value_type& const_reference;
824 typedef typename base::pointer pointer;
825 typedef typename base::const_pointer const_pointer;
826 typedef typename base::size_type size_type;
827 typedef typename base::difference_type difference_type;
828 typedef typename base::iterator iterator;
829 typedef typename base::const_iterator const_iterator;
830 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
831 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
833 _LIBCPP_INLINE_VISIBILITY
835 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
837 #if _LIBCPP_DEBUG_LEVEL >= 2
838 __get_db()->__insert_c(this);
841 _LIBCPP_INLINE_VISIBILITY
842 explicit list(const allocator_type& __a) : base(__a)
844 #if _LIBCPP_DEBUG_LEVEL >= 2
845 __get_db()->__insert_c(this);
848 explicit list(size_type __n);
849 #if _LIBCPP_STD_VER > 11
850 explicit list(size_type __n, const allocator_type& __a);
852 list(size_type __n, const value_type& __x);
853 list(size_type __n, const value_type& __x, const allocator_type& __a);
854 template <class _InpIter>
855 list(_InpIter __f, _InpIter __l,
856 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
857 template <class _InpIter>
858 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
859 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
861 list(const list& __c);
862 list(const list& __c, const allocator_type& __a);
863 _LIBCPP_INLINE_VISIBILITY
864 list& operator=(const list& __c);
865 #ifndef _LIBCPP_CXX03_LANG
866 list(initializer_list<value_type> __il);
867 list(initializer_list<value_type> __il, const allocator_type& __a);
869 _LIBCPP_INLINE_VISIBILITY
871 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
872 _LIBCPP_INLINE_VISIBILITY
873 list(list&& __c, const allocator_type& __a);
874 _LIBCPP_INLINE_VISIBILITY
875 list& operator=(list&& __c)
877 __node_alloc_traits::propagate_on_container_move_assignment::value &&
878 is_nothrow_move_assignable<__node_allocator>::value);
880 _LIBCPP_INLINE_VISIBILITY
881 list& operator=(initializer_list<value_type> __il)
882 {assign(__il.begin(), __il.end()); return *this;}
884 _LIBCPP_INLINE_VISIBILITY
885 void assign(initializer_list<value_type> __il)
886 {assign(__il.begin(), __il.end());}
887 #endif // _LIBCPP_CXX03_LANG
889 template <class _InpIter>
890 void assign(_InpIter __f, _InpIter __l,
891 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
892 void assign(size_type __n, const value_type& __x);
894 _LIBCPP_INLINE_VISIBILITY
895 allocator_type get_allocator() const _NOEXCEPT;
897 _LIBCPP_INLINE_VISIBILITY
898 size_type size() const _NOEXCEPT {return base::__sz();}
899 _LIBCPP_INLINE_VISIBILITY
900 bool empty() const _NOEXCEPT {return base::empty();}
901 _LIBCPP_INLINE_VISIBILITY
902 size_type max_size() const _NOEXCEPT
904 return std::min<size_type>(
905 base::__node_alloc_max_size(),
906 numeric_limits<difference_type >::max());
909 _LIBCPP_INLINE_VISIBILITY
910 iterator begin() _NOEXCEPT {return base::begin();}
911 _LIBCPP_INLINE_VISIBILITY
912 const_iterator begin() const _NOEXCEPT {return base::begin();}
913 _LIBCPP_INLINE_VISIBILITY
914 iterator end() _NOEXCEPT {return base::end();}
915 _LIBCPP_INLINE_VISIBILITY
916 const_iterator end() const _NOEXCEPT {return base::end();}
917 _LIBCPP_INLINE_VISIBILITY
918 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
919 _LIBCPP_INLINE_VISIBILITY
920 const_iterator cend() const _NOEXCEPT {return base::end();}
922 _LIBCPP_INLINE_VISIBILITY
923 reverse_iterator rbegin() _NOEXCEPT
924 {return reverse_iterator(end());}
925 _LIBCPP_INLINE_VISIBILITY
926 const_reverse_iterator rbegin() const _NOEXCEPT
927 {return const_reverse_iterator(end());}
928 _LIBCPP_INLINE_VISIBILITY
929 reverse_iterator rend() _NOEXCEPT
930 {return reverse_iterator(begin());}
931 _LIBCPP_INLINE_VISIBILITY
932 const_reverse_iterator rend() const _NOEXCEPT
933 {return const_reverse_iterator(begin());}
934 _LIBCPP_INLINE_VISIBILITY
935 const_reverse_iterator crbegin() const _NOEXCEPT
936 {return const_reverse_iterator(end());}
937 _LIBCPP_INLINE_VISIBILITY
938 const_reverse_iterator crend() const _NOEXCEPT
939 {return const_reverse_iterator(begin());}
941 _LIBCPP_INLINE_VISIBILITY
944 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
945 return base::__end_.__next_->__as_node()->__value_;
947 _LIBCPP_INLINE_VISIBILITY
948 const_reference front() const
950 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
951 return base::__end_.__next_->__as_node()->__value_;
953 _LIBCPP_INLINE_VISIBILITY
956 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
957 return base::__end_.__prev_->__as_node()->__value_;
959 _LIBCPP_INLINE_VISIBILITY
960 const_reference back() const
962 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
963 return base::__end_.__prev_->__as_node()->__value_;
966 #ifndef _LIBCPP_CXX03_LANG
967 void push_front(value_type&& __x);
968 void push_back(value_type&& __x);
970 template <class... _Args>
971 #if _LIBCPP_STD_VER > 14
972 reference emplace_front(_Args&&... __args);
974 void emplace_front(_Args&&... __args);
976 template <class... _Args>
977 #if _LIBCPP_STD_VER > 14
978 reference emplace_back(_Args&&... __args);
980 void emplace_back(_Args&&... __args);
982 template <class... _Args>
983 iterator emplace(const_iterator __p, _Args&&... __args);
985 iterator insert(const_iterator __p, value_type&& __x);
987 _LIBCPP_INLINE_VISIBILITY
988 iterator insert(const_iterator __p, initializer_list<value_type> __il)
989 {return insert(__p, __il.begin(), __il.end());}
990 #endif // _LIBCPP_CXX03_LANG
992 void push_front(const value_type& __x);
993 void push_back(const value_type& __x);
995 #ifndef _LIBCPP_CXX03_LANG
996 template <class _Arg>
997 _LIBCPP_INLINE_VISIBILITY
998 void __emplace_back(_Arg&& __arg) { emplace_back(_VSTD::forward<_Arg>(__arg)); }
1000 _LIBCPP_INLINE_VISIBILITY
1001 void __emplace_back(value_type const& __arg) { push_back(__arg); }
1004 iterator insert(const_iterator __p, const value_type& __x);
1005 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
1006 template <class _InpIter>
1007 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
1008 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
1010 _LIBCPP_INLINE_VISIBILITY
1011 void swap(list& __c)
1012 #if _LIBCPP_STD_VER >= 14
1015 _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value ||
1016 __is_nothrow_swappable<__node_allocator>::value)
1019 _LIBCPP_INLINE_VISIBILITY
1020 void clear() _NOEXCEPT {base::clear();}
1025 iterator erase(const_iterator __p);
1026 iterator erase(const_iterator __f, const_iterator __l);
1028 void resize(size_type __n);
1029 void resize(size_type __n, const value_type& __x);
1031 void splice(const_iterator __p, list& __c);
1032 #ifndef _LIBCPP_CXX03_LANG
1033 _LIBCPP_INLINE_VISIBILITY
1034 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1035 _LIBCPP_INLINE_VISIBILITY
1036 void splice(const_iterator __p, list&& __c, const_iterator __i)
1037 {splice(__p, __c, __i);}
1038 _LIBCPP_INLINE_VISIBILITY
1039 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1040 {splice(__p, __c, __f, __l);}
1042 void splice(const_iterator __p, list& __c, const_iterator __i);
1043 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
1045 void remove(const value_type& __x);
1046 template <class _Pred> void remove_if(_Pred __pred);
1047 _LIBCPP_INLINE_VISIBILITY
1049 template <class _BinaryPred>
1050 void unique(_BinaryPred __binary_pred);
1051 _LIBCPP_INLINE_VISIBILITY
1052 void merge(list& __c);
1053 #ifndef _LIBCPP_CXX03_LANG
1054 _LIBCPP_INLINE_VISIBILITY
1055 void merge(list&& __c) {merge(__c);}
1057 template <class _Comp>
1058 _LIBCPP_INLINE_VISIBILITY
1059 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
1061 template <class _Comp>
1062 void merge(list& __c, _Comp __comp);
1064 _LIBCPP_INLINE_VISIBILITY
1066 template <class _Comp>
1067 _LIBCPP_INLINE_VISIBILITY
1068 void sort(_Comp __comp);
1070 void reverse() _NOEXCEPT;
1072 bool __invariants() const;
1074 #if _LIBCPP_DEBUG_LEVEL >= 2
1076 bool __dereferenceable(const const_iterator* __i) const;
1077 bool __decrementable(const const_iterator* __i) const;
1078 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1079 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1081 #endif // _LIBCPP_DEBUG_LEVEL >= 2
1084 _LIBCPP_INLINE_VISIBILITY
1085 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
1086 _LIBCPP_INLINE_VISIBILITY
1087 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
1088 _LIBCPP_INLINE_VISIBILITY
1089 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
1090 iterator __iterator(size_type __n);
1091 template <class _Comp>
1092 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1094 void __move_assign(list& __c, true_type)
1095 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
1096 void __move_assign(list& __c, false_type);
1099 // Link in nodes [__f, __l] just prior to __p
1100 template <class _Tp, class _Alloc>
1103 list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
1105 __p->__prev_->__next_ = __f;
1106 __f->__prev_ = __p->__prev_;
1111 // Link in nodes [__f, __l] at the front of the list
1112 template <class _Tp, class _Alloc>
1115 list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
1117 __f->__prev_ = base::__end_as_link();
1118 __l->__next_ = base::__end_.__next_;
1119 __l->__next_->__prev_ = __l;
1120 base::__end_.__next_ = __f;
1123 // Link in nodes [__f, __l] at the front of the list
1124 template <class _Tp, class _Alloc>
1127 list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
1129 __l->__next_ = base::__end_as_link();
1130 __f->__prev_ = base::__end_.__prev_;
1131 __f->__prev_->__next_ = __f;
1132 base::__end_.__prev_ = __l;
1136 template <class _Tp, class _Alloc>
1138 typename list<_Tp, _Alloc>::iterator
1139 list<_Tp, _Alloc>::__iterator(size_type __n)
1141 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1142 : _VSTD::prev(end(), base::__sz() - __n);
1145 template <class _Tp, class _Alloc>
1146 list<_Tp, _Alloc>::list(size_type __n)
1148 #if _LIBCPP_DEBUG_LEVEL >= 2
1149 __get_db()->__insert_c(this);
1151 for (; __n > 0; --__n)
1152 #ifndef _LIBCPP_CXX03_LANG
1155 push_back(value_type());
1159 #if _LIBCPP_STD_VER > 11
1160 template <class _Tp, class _Alloc>
1161 list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1163 #if _LIBCPP_DEBUG_LEVEL >= 2
1164 __get_db()->__insert_c(this);
1166 for (; __n > 0; --__n)
1171 template <class _Tp, class _Alloc>
1172 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1174 #if _LIBCPP_DEBUG_LEVEL >= 2
1175 __get_db()->__insert_c(this);
1177 for (; __n > 0; --__n)
1181 template <class _Tp, class _Alloc>
1182 list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1185 #if _LIBCPP_DEBUG_LEVEL >= 2
1186 __get_db()->__insert_c(this);
1188 for (; __n > 0; --__n)
1192 template <class _Tp, class _Alloc>
1193 template <class _InpIter>
1194 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1195 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1197 #if _LIBCPP_DEBUG_LEVEL >= 2
1198 __get_db()->__insert_c(this);
1200 for (; __f != __l; ++__f)
1201 __emplace_back(*__f);
1204 template <class _Tp, class _Alloc>
1205 template <class _InpIter>
1206 list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1207 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1210 #if _LIBCPP_DEBUG_LEVEL >= 2
1211 __get_db()->__insert_c(this);
1213 for (; __f != __l; ++__f)
1214 __emplace_back(*__f);
1217 template <class _Tp, class _Alloc>
1218 list<_Tp, _Alloc>::list(const list& __c)
1219 : base(allocator_type(
1220 __node_alloc_traits::select_on_container_copy_construction(
1221 __c.__node_alloc())))
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 template <class _Tp, class _Alloc>
1231 list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1234 #if _LIBCPP_DEBUG_LEVEL >= 2
1235 __get_db()->__insert_c(this);
1237 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1241 #ifndef _LIBCPP_CXX03_LANG
1243 template <class _Tp, class _Alloc>
1244 list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
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>
1256 list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1258 #if _LIBCPP_DEBUG_LEVEL >= 2
1259 __get_db()->__insert_c(this);
1261 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1262 __e = __il.end(); __i != __e; ++__i)
1266 template <class _Tp, class _Alloc>
1268 list<_Tp, _Alloc>::list(list&& __c)
1269 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
1270 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
1272 #if _LIBCPP_DEBUG_LEVEL >= 2
1273 __get_db()->__insert_c(this);
1278 template <class _Tp, class _Alloc>
1280 list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1283 #if _LIBCPP_DEBUG_LEVEL >= 2
1284 __get_db()->__insert_c(this);
1286 if (__a == __c.get_allocator())
1290 typedef move_iterator<iterator> _Ip;
1291 assign(_Ip(__c.begin()), _Ip(__c.end()));
1295 template <class _Tp, class _Alloc>
1298 list<_Tp, _Alloc>::operator=(list&& __c)
1300 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1301 is_nothrow_move_assignable<__node_allocator>::value)
1303 __move_assign(__c, integral_constant<bool,
1304 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1308 template <class _Tp, class _Alloc>
1310 list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1312 if (base::__node_alloc() != __c.__node_alloc())
1314 typedef move_iterator<iterator> _Ip;
1315 assign(_Ip(__c.begin()), _Ip(__c.end()));
1318 __move_assign(__c, true_type());
1321 template <class _Tp, class _Alloc>
1323 list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
1324 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
1327 base::__move_assign_alloc(__c);
1331 #endif // _LIBCPP_CXX03_LANG
1333 template <class _Tp, class _Alloc>
1336 list<_Tp, _Alloc>::operator=(const list& __c)
1340 base::__copy_assign_alloc(__c);
1341 assign(__c.begin(), __c.end());
1346 template <class _Tp, class _Alloc>
1347 template <class _InpIter>
1349 list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1350 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1352 iterator __i = begin();
1353 iterator __e = end();
1354 for (; __f != __l && __i != __e; ++__f, ++__i)
1357 insert(__e, __f, __l);
1360 #if _LIBCPP_DEBUG_LEVEL >= 2
1361 __get_db()->__invalidate_all(this);
1365 template <class _Tp, class _Alloc>
1367 list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1369 iterator __i = begin();
1370 iterator __e = end();
1371 for (; __n > 0 && __i != __e; --__n, ++__i)
1374 insert(__e, __n, __x);
1377 #if _LIBCPP_DEBUG_LEVEL >= 2
1378 __get_db()->__invalidate_all(this);
1382 template <class _Tp, class _Alloc>
1385 list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
1387 return allocator_type(base::__node_alloc());
1390 template <class _Tp, class _Alloc>
1391 typename list<_Tp, _Alloc>::iterator
1392 list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1394 #if _LIBCPP_DEBUG_LEVEL >= 2
1395 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1396 "list::insert(iterator, x) called with an iterator not"
1397 " referring to this list");
1399 __node_allocator& __na = base::__node_alloc();
1400 typedef __allocator_destructor<__node_allocator> _Dp;
1401 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1402 __hold->__prev_ = 0;
1403 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1404 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
1406 #if _LIBCPP_DEBUG_LEVEL >= 2
1407 return iterator(__hold.release()->__as_link(), this);
1409 return iterator(__hold.release()->__as_link());
1413 template <class _Tp, class _Alloc>
1414 typename list<_Tp, _Alloc>::iterator
1415 list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1417 #if _LIBCPP_DEBUG_LEVEL >= 2
1418 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1419 "list::insert(iterator, n, x) called with an iterator not"
1420 " referring to this list");
1421 iterator __r(__p.__ptr_, this);
1423 iterator __r(__p.__ptr_);
1428 __node_allocator& __na = base::__node_alloc();
1429 typedef __allocator_destructor<__node_allocator> _Dp;
1430 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1431 __hold->__prev_ = 0;
1432 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1434 #if _LIBCPP_DEBUG_LEVEL >= 2
1435 __r = iterator(__hold->__as_link(), this);
1437 __r = iterator(__hold->__as_link());
1441 #ifndef _LIBCPP_NO_EXCEPTIONS
1444 #endif // _LIBCPP_NO_EXCEPTIONS
1445 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1447 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1448 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1449 __e.__ptr_->__next_ = __hold->__as_link();
1450 __hold->__prev_ = __e.__ptr_;
1453 #ifndef _LIBCPP_NO_EXCEPTIONS
1459 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1460 __link_pointer __prev = __e.__ptr_->__prev_;
1461 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1464 #if _LIBCPP_DEBUG_LEVEL >= 2
1465 __e = iterator(__prev, this);
1467 __e = iterator(__prev);
1472 #endif // _LIBCPP_NO_EXCEPTIONS
1473 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1474 base::__sz() += __ds;
1479 template <class _Tp, class _Alloc>
1480 template <class _InpIter>
1481 typename list<_Tp, _Alloc>::iterator
1482 list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1483 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1485 #if _LIBCPP_DEBUG_LEVEL >= 2
1486 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1487 "list::insert(iterator, range) called with an iterator not"
1488 " referring to this list");
1489 iterator __r(__p.__ptr_, this);
1491 iterator __r(__p.__ptr_);
1496 __node_allocator& __na = base::__node_alloc();
1497 typedef __allocator_destructor<__node_allocator> _Dp;
1498 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1499 __hold->__prev_ = 0;
1500 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1502 #if _LIBCPP_DEBUG_LEVEL >= 2
1503 __r = iterator(__hold.get()->__as_link(), this);
1505 __r = iterator(__hold.get()->__as_link());
1509 #ifndef _LIBCPP_NO_EXCEPTIONS
1512 #endif // _LIBCPP_NO_EXCEPTIONS
1513 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
1515 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1516 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
1517 __e.__ptr_->__next_ = __hold.get()->__as_link();
1518 __hold->__prev_ = __e.__ptr_;
1521 #ifndef _LIBCPP_NO_EXCEPTIONS
1527 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1528 __link_pointer __prev = __e.__ptr_->__prev_;
1529 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1532 #if _LIBCPP_DEBUG_LEVEL >= 2
1533 __e = iterator(__prev, this);
1535 __e = iterator(__prev);
1540 #endif // _LIBCPP_NO_EXCEPTIONS
1541 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
1542 base::__sz() += __ds;
1547 template <class _Tp, class _Alloc>
1549 list<_Tp, _Alloc>::push_front(const value_type& __x)
1551 __node_allocator& __na = base::__node_alloc();
1552 typedef __allocator_destructor<__node_allocator> _Dp;
1553 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1554 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1555 __link_pointer __nl = __hold->__as_link();
1556 __link_nodes_at_front(__nl, __nl);
1561 template <class _Tp, class _Alloc>
1563 list<_Tp, _Alloc>::push_back(const value_type& __x)
1565 __node_allocator& __na = base::__node_alloc();
1566 typedef __allocator_destructor<__node_allocator> _Dp;
1567 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1568 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1569 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
1574 #ifndef _LIBCPP_CXX03_LANG
1576 template <class _Tp, class _Alloc>
1578 list<_Tp, _Alloc>::push_front(value_type&& __x)
1580 __node_allocator& __na = base::__node_alloc();
1581 typedef __allocator_destructor<__node_allocator> _Dp;
1582 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1583 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1584 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
1589 template <class _Tp, class _Alloc>
1591 list<_Tp, _Alloc>::push_back(value_type&& __x)
1593 __node_allocator& __na = base::__node_alloc();
1594 typedef __allocator_destructor<__node_allocator> _Dp;
1595 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1596 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1597 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
1602 template <class _Tp, class _Alloc>
1603 template <class... _Args>
1604 #if _LIBCPP_STD_VER > 14
1605 typename list<_Tp, _Alloc>::reference
1609 list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
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 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1615 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
1617 #if _LIBCPP_STD_VER > 14
1618 return __hold.release()->__value_;
1624 template <class _Tp, class _Alloc>
1625 template <class... _Args>
1626 #if _LIBCPP_STD_VER > 14
1627 typename list<_Tp, _Alloc>::reference
1631 list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1633 __node_allocator& __na = base::__node_alloc();
1634 typedef __allocator_destructor<__node_allocator> _Dp;
1635 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1636 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1637 __link_pointer __nl = __hold->__as_link();
1638 __link_nodes_at_back(__nl, __nl);
1640 #if _LIBCPP_STD_VER > 14
1641 return __hold.release()->__value_;
1647 template <class _Tp, class _Alloc>
1648 template <class... _Args>
1649 typename list<_Tp, _Alloc>::iterator
1650 list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1652 #if _LIBCPP_DEBUG_LEVEL >= 2
1653 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1654 "list::emplace(iterator, args...) called with an iterator not"
1655 " referring to this list");
1657 __node_allocator& __na = base::__node_alloc();
1658 typedef __allocator_destructor<__node_allocator> _Dp;
1659 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1660 __hold->__prev_ = 0;
1661 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
1662 __link_pointer __nl = __hold.get()->__as_link();
1663 __link_nodes(__p.__ptr_, __nl, __nl);
1666 #if _LIBCPP_DEBUG_LEVEL >= 2
1667 return iterator(__nl, this);
1669 return iterator(__nl);
1673 template <class _Tp, class _Alloc>
1674 typename list<_Tp, _Alloc>::iterator
1675 list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1677 #if _LIBCPP_DEBUG_LEVEL >= 2
1678 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1679 "list::insert(iterator, x) called with an iterator not"
1680 " referring to this list");
1682 __node_allocator& __na = base::__node_alloc();
1683 typedef __allocator_destructor<__node_allocator> _Dp;
1684 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1685 __hold->__prev_ = 0;
1686 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
1687 __link_pointer __nl = __hold->__as_link();
1688 __link_nodes(__p.__ptr_, __nl, __nl);
1691 #if _LIBCPP_DEBUG_LEVEL >= 2
1692 return iterator(__nl, this);
1694 return iterator(__nl);
1698 #endif // _LIBCPP_CXX03_LANG
1700 template <class _Tp, class _Alloc>
1702 list<_Tp, _Alloc>::pop_front()
1704 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
1705 __node_allocator& __na = base::__node_alloc();
1706 __link_pointer __n = base::__end_.__next_;
1707 base::__unlink_nodes(__n, __n);
1709 #if _LIBCPP_DEBUG_LEVEL >= 2
1710 __c_node* __c = __get_db()->__find_c_and_lock(this);
1711 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1714 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1715 if (__i->__ptr_ == __n)
1717 (*__p)->__c_ = nullptr;
1718 if (--__c->end_ != __p)
1719 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1722 __get_db()->unlock();
1724 __node_pointer __np = __n->__as_node();
1725 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1726 __node_alloc_traits::deallocate(__na, __np, 1);
1729 template <class _Tp, class _Alloc>
1731 list<_Tp, _Alloc>::pop_back()
1733 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
1734 __node_allocator& __na = base::__node_alloc();
1735 __link_pointer __n = base::__end_.__prev_;
1736 base::__unlink_nodes(__n, __n);
1738 #if _LIBCPP_DEBUG_LEVEL >= 2
1739 __c_node* __c = __get_db()->__find_c_and_lock(this);
1740 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1743 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1744 if (__i->__ptr_ == __n)
1746 (*__p)->__c_ = nullptr;
1747 if (--__c->end_ != __p)
1748 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1751 __get_db()->unlock();
1753 __node_pointer __np = __n->__as_node();
1754 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1755 __node_alloc_traits::deallocate(__na, __np, 1);
1758 template <class _Tp, class _Alloc>
1759 typename list<_Tp, _Alloc>::iterator
1760 list<_Tp, _Alloc>::erase(const_iterator __p)
1762 #if _LIBCPP_DEBUG_LEVEL >= 2
1763 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1764 "list::erase(iterator) called with an iterator not"
1765 " referring to this list");
1767 _LIBCPP_ASSERT(__p != end(),
1768 "list::erase(iterator) called with a non-dereferenceable iterator");
1769 __node_allocator& __na = base::__node_alloc();
1770 __link_pointer __n = __p.__ptr_;
1771 __link_pointer __r = __n->__next_;
1772 base::__unlink_nodes(__n, __n);
1774 #if _LIBCPP_DEBUG_LEVEL >= 2
1775 __c_node* __c = __get_db()->__find_c_and_lock(this);
1776 for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
1779 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
1780 if (__i->__ptr_ == __n)
1782 (*__ip)->__c_ = nullptr;
1783 if (--__c->end_ != __ip)
1784 memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
1787 __get_db()->unlock();
1789 __node_pointer __np = __n->__as_node();
1790 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1791 __node_alloc_traits::deallocate(__na, __np, 1);
1792 #if _LIBCPP_DEBUG_LEVEL >= 2
1793 return iterator(__r, this);
1795 return iterator(__r);
1799 template <class _Tp, class _Alloc>
1800 typename list<_Tp, _Alloc>::iterator
1801 list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1803 #if _LIBCPP_DEBUG_LEVEL >= 2
1804 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1805 "list::erase(iterator, iterator) called with an iterator not"
1806 " referring to this list");
1807 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
1808 "list::erase(iterator, iterator) called with an iterator not"
1809 " referring to this list");
1813 __node_allocator& __na = base::__node_alloc();
1814 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
1817 __link_pointer __n = __f.__ptr_;
1820 #if _LIBCPP_DEBUG_LEVEL >= 2
1821 __c_node* __c = __get_db()->__find_c_and_lock(this);
1822 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1825 iterator* __i = static_cast<iterator*>((*__p)->__i_);
1826 if (__i->__ptr_ == __n)
1828 (*__p)->__c_ = nullptr;
1829 if (--__c->end_ != __p)
1830 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1833 __get_db()->unlock();
1835 __node_pointer __np = __n->__as_node();
1836 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1837 __node_alloc_traits::deallocate(__na, __np, 1);
1840 #if _LIBCPP_DEBUG_LEVEL >= 2
1841 return iterator(__l.__ptr_, this);
1843 return iterator(__l.__ptr_);
1847 template <class _Tp, class _Alloc>
1849 list<_Tp, _Alloc>::resize(size_type __n)
1851 if (__n < base::__sz())
1852 erase(__iterator(__n), end());
1853 else if (__n > base::__sz())
1855 __n -= base::__sz();
1857 __node_allocator& __na = base::__node_alloc();
1858 typedef __allocator_destructor<__node_allocator> _Dp;
1859 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1860 __hold->__prev_ = 0;
1861 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1863 #if _LIBCPP_DEBUG_LEVEL >= 2
1864 iterator __r = iterator(__hold.release()->__as_link(), this);
1866 iterator __r = iterator(__hold.release()->__as_link());
1869 #ifndef _LIBCPP_NO_EXCEPTIONS
1872 #endif // _LIBCPP_NO_EXCEPTIONS
1873 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1875 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1876 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
1877 __e.__ptr_->__next_ = __hold.get()->__as_link();
1878 __hold->__prev_ = __e.__ptr_;
1881 #ifndef _LIBCPP_NO_EXCEPTIONS
1887 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1888 __link_pointer __prev = __e.__ptr_->__prev_;
1889 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1892 #if _LIBCPP_DEBUG_LEVEL >= 2
1893 __e = iterator(__prev, this);
1895 __e = iterator(__prev);
1900 #endif // _LIBCPP_NO_EXCEPTIONS
1901 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
1902 base::__sz() += __ds;
1906 template <class _Tp, class _Alloc>
1908 list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1910 if (__n < base::__sz())
1911 erase(__iterator(__n), end());
1912 else if (__n > base::__sz())
1914 __n -= base::__sz();
1916 __node_allocator& __na = base::__node_alloc();
1917 typedef __allocator_destructor<__node_allocator> _Dp;
1918 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
1919 __hold->__prev_ = 0;
1920 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1922 __link_pointer __nl = __hold.release()->__as_link();
1923 #if _LIBCPP_DEBUG_LEVEL >= 2
1924 iterator __r = iterator(__nl, this);
1926 iterator __r = iterator(__nl);
1929 #ifndef _LIBCPP_NO_EXCEPTIONS
1932 #endif // _LIBCPP_NO_EXCEPTIONS
1933 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1935 __hold.reset(__node_alloc_traits::allocate(__na, 1));
1936 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
1937 __e.__ptr_->__next_ = __hold.get()->__as_link();
1938 __hold->__prev_ = __e.__ptr_;
1941 #ifndef _LIBCPP_NO_EXCEPTIONS
1947 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
1948 __link_pointer __prev = __e.__ptr_->__prev_;
1949 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
1952 #if _LIBCPP_DEBUG_LEVEL >= 2
1953 __e = iterator(__prev, this);
1955 __e = iterator(__prev);
1960 #endif // _LIBCPP_NO_EXCEPTIONS
1961 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
1962 base::__sz() += __ds;
1966 template <class _Tp, class _Alloc>
1968 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1970 _LIBCPP_ASSERT(this != &__c,
1971 "list::splice(iterator, list) called with this == &list");
1972 #if _LIBCPP_DEBUG_LEVEL >= 2
1973 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1974 "list::splice(iterator, list) called with an iterator not"
1975 " referring to this list");
1979 __link_pointer __f = __c.__end_.__next_;
1980 __link_pointer __l = __c.__end_.__prev_;
1981 base::__unlink_nodes(__f, __l);
1982 __link_nodes(__p.__ptr_, __f, __l);
1983 base::__sz() += __c.__sz();
1985 #if _LIBCPP_DEBUG_LEVEL >= 2
1986 __libcpp_db* __db = __get_db();
1987 __c_node* __cn1 = __db->__find_c_and_lock(this);
1988 __c_node* __cn2 = __db->__find_c(&__c);
1989 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
1992 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
1993 if (__i->__ptr_ != __c.__end_as_link())
1995 __cn1->__add(*__ip);
1996 (*__ip)->__c_ = __cn1;
1997 if (--__cn2->end_ != __ip)
1998 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2006 template <class _Tp, class _Alloc>
2008 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
2010 #if _LIBCPP_DEBUG_LEVEL >= 2
2011 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2012 "list::splice(iterator, list, iterator) called with first iterator not"
2013 " referring to this list");
2014 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
2015 "list::splice(iterator, list, iterator) called with second iterator not"
2016 " referring to list argument");
2017 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
2018 "list::splice(iterator, list, iterator) called with second iterator not"
2021 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
2023 __link_pointer __f = __i.__ptr_;
2024 base::__unlink_nodes(__f, __f);
2025 __link_nodes(__p.__ptr_, __f, __f);
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** __ip = __cn2->end_; __ip != __cn2->beg_;)
2035 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
2036 if (__j->__ptr_ == __f)
2038 __cn1->__add(*__ip);
2039 (*__ip)->__c_ = __cn1;
2040 if (--__cn2->end_ != __ip)
2041 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2049 template <class _Tp, class _Alloc>
2051 list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
2053 #if _LIBCPP_DEBUG_LEVEL >= 2
2054 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2055 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2056 " referring to this list");
2057 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2058 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2059 " referring to list argument");
2062 for (const_iterator __i = __f; __i != __l; ++__i)
2063 _LIBCPP_ASSERT(__i != __p,
2064 "list::splice(iterator, list, iterator, iterator)"
2065 " called with the first iterator within the range"
2066 " of the second and third iterators");
2073 size_type __s = _VSTD::distance(__f, __l);
2075 base::__sz() += __s;
2077 __link_pointer __first = __f.__ptr_;
2079 __link_pointer __last = __l.__ptr_;
2080 base::__unlink_nodes(__first, __last);
2081 __link_nodes(__p.__ptr_, __first, __last);
2082 #if _LIBCPP_DEBUG_LEVEL >= 2
2083 __libcpp_db* __db = __get_db();
2084 __c_node* __cn1 = __db->__find_c_and_lock(this);
2085 __c_node* __cn2 = __db->__find_c(&__c);
2086 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
2089 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
2090 for (__link_pointer __k = __f.__ptr_;
2091 __k != __l.__ptr_; __k = __k->__next_)
2093 if (__j->__ptr_ == __k)
2095 __cn1->__add(*__ip);
2096 (*__ip)->__c_ = __cn1;
2097 if (--__cn2->end_ != __ip)
2098 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
2107 template <class _Tp, class _Alloc>
2109 list<_Tp, _Alloc>::remove(const value_type& __x)
2111 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
2112 for (const_iterator __i = begin(), __e = end(); __i != __e;)
2116 const_iterator __j = _VSTD::next(__i);
2117 for (; __j != __e && *__j == __x; ++__j)
2119 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2129 template <class _Tp, class _Alloc>
2130 template <class _Pred>
2132 list<_Tp, _Alloc>::remove_if(_Pred __pred)
2134 for (iterator __i = begin(), __e = end(); __i != __e;)
2138 iterator __j = _VSTD::next(__i);
2139 for (; __j != __e && __pred(*__j); ++__j)
2141 __i = erase(__i, __j);
2150 template <class _Tp, class _Alloc>
2153 list<_Tp, _Alloc>::unique()
2155 unique(__equal_to<value_type>());
2158 template <class _Tp, class _Alloc>
2159 template <class _BinaryPred>
2161 list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2163 for (iterator __i = begin(), __e = end(); __i != __e;)
2165 iterator __j = _VSTD::next(__i);
2166 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2169 __i = erase(__i, __j);
2173 template <class _Tp, class _Alloc>
2176 list<_Tp, _Alloc>::merge(list& __c)
2178 merge(__c, __less<value_type>());
2181 template <class _Tp, class _Alloc>
2182 template <class _Comp>
2184 list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2188 iterator __f1 = begin();
2189 iterator __e1 = end();
2190 iterator __f2 = __c.begin();
2191 iterator __e2 = __c.end();
2192 while (__f1 != __e1 && __f2 != __e2)
2194 if (__comp(*__f2, *__f1))
2197 iterator __m2 = _VSTD::next(__f2);
2198 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2200 base::__sz() += __ds;
2202 __link_pointer __f = __f2.__ptr_;
2203 __link_pointer __l = __m2.__ptr_->__prev_;
2205 base::__unlink_nodes(__f, __l);
2206 __m2 = _VSTD::next(__f1);
2207 __link_nodes(__f1.__ptr_, __f, __l);
2214 #if _LIBCPP_DEBUG_LEVEL >= 2
2215 __libcpp_db* __db = __get_db();
2216 __c_node* __cn1 = __db->__find_c_and_lock(this);
2217 __c_node* __cn2 = __db->__find_c(&__c);
2218 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2221 iterator* __i = static_cast<iterator*>((*__p)->__i_);
2222 if (__i->__ptr_ != __c.__end_as_link())
2225 (*__p)->__c_ = __cn1;
2226 if (--__cn2->end_ != __p)
2227 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2235 template <class _Tp, class _Alloc>
2238 list<_Tp, _Alloc>::sort()
2240 sort(__less<value_type>());
2243 template <class _Tp, class _Alloc>
2244 template <class _Comp>
2247 list<_Tp, _Alloc>::sort(_Comp __comp)
2249 __sort(begin(), end(), base::__sz(), __comp);
2252 template <class _Tp, class _Alloc>
2253 template <class _Comp>
2254 typename list<_Tp, _Alloc>::iterator
2255 list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2263 if (__comp(*--__e2, *__f1))
2265 __link_pointer __f = __e2.__ptr_;
2266 base::__unlink_nodes(__f, __f);
2267 __link_nodes(__f1.__ptr_, __f, __f);
2272 size_type __n2 = __n / 2;
2273 iterator __e1 = _VSTD::next(__f1, __n2);
2274 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2275 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2276 if (__comp(*__f2, *__f1))
2278 iterator __m2 = _VSTD::next(__f2);
2279 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2281 __link_pointer __f = __f2.__ptr_;
2282 __link_pointer __l = __m2.__ptr_->__prev_;
2285 base::__unlink_nodes(__f, __l);
2286 __m2 = _VSTD::next(__f1);
2287 __link_nodes(__f1.__ptr_, __f, __l);
2292 while (__f1 != __e1 && __f2 != __e2)
2294 if (__comp(*__f2, *__f1))
2296 iterator __m2 = _VSTD::next(__f2);
2297 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2299 __link_pointer __f = __f2.__ptr_;
2300 __link_pointer __l = __m2.__ptr_->__prev_;
2304 base::__unlink_nodes(__f, __l);
2305 __m2 = _VSTD::next(__f1);
2306 __link_nodes(__f1.__ptr_, __f, __l);
2315 template <class _Tp, class _Alloc>
2317 list<_Tp, _Alloc>::reverse() _NOEXCEPT
2319 if (base::__sz() > 1)
2321 iterator __e = end();
2322 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2324 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
2325 __i.__ptr_ = __i.__ptr_->__prev_;
2327 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
2331 template <class _Tp, class _Alloc>
2333 list<_Tp, _Alloc>::__invariants() const
2335 return size() == _VSTD::distance(begin(), end());
2338 #if _LIBCPP_DEBUG_LEVEL >= 2
2340 template <class _Tp, class _Alloc>
2342 list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2344 return __i->__ptr_ != this->__end_as_link();
2347 template <class _Tp, class _Alloc>
2349 list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2351 return !empty() && __i->__ptr_ != base::__end_.__next_;
2354 template <class _Tp, class _Alloc>
2356 list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
2361 template <class _Tp, class _Alloc>
2363 list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
2368 #endif // _LIBCPP_DEBUG_LEVEL >= 2
2370 template <class _Tp, class _Alloc>
2371 inline _LIBCPP_INLINE_VISIBILITY
2373 operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2375 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
2378 template <class _Tp, class _Alloc>
2379 inline _LIBCPP_INLINE_VISIBILITY
2381 operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2383 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
2386 template <class _Tp, class _Alloc>
2387 inline _LIBCPP_INLINE_VISIBILITY
2389 operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2391 return !(__x == __y);
2394 template <class _Tp, class _Alloc>
2395 inline _LIBCPP_INLINE_VISIBILITY
2397 operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2402 template <class _Tp, class _Alloc>
2403 inline _LIBCPP_INLINE_VISIBILITY
2405 operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2407 return !(__x < __y);
2410 template <class _Tp, class _Alloc>
2411 inline _LIBCPP_INLINE_VISIBILITY
2413 operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2415 return !(__y < __x);
2418 template <class _Tp, class _Alloc>
2419 inline _LIBCPP_INLINE_VISIBILITY
2421 swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
2422 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
2427 _LIBCPP_END_NAMESPACE_STD
2431 #endif // _LIBCPP_LIST