blob: 44b20e2fa28cc2d4ed685c8845eb4885c84de1d9 [file] [log] [blame]
Howard Hinnant3e519522010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- list ------------------------------------===//
3//
Howard Hinnant5b08a8a2010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnant3e519522010-05-11 19:42:16 +00005//
Howard Hinnant412dbeb2010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnant3e519522010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_LIST
12#define _LIBCPP_LIST
13
14/*
15 list synopsis
16
17namespace std
18{
19
20template <class T, class Alloc = allocator<T> >
21class list
22{
23public:
24
25 // types:
26 typedef T value_type;
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;
38
Howard Hinnant45900102011-06-03 17:30:28 +000039 list()
40 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000041 explicit list(const allocator_type& a);
42 explicit list(size_type n);
Marshall Clowf1b6d1b2013-09-09 18:19:45 +000043 explicit list(size_type n, const allocator_type& a); // C++14
Howard Hinnant3e519522010-05-11 19:42:16 +000044 list(size_type n, const value_type& value);
45 list(size_type n, const value_type& value, const allocator_type& a);
46 template <class Iter>
47 list(Iter first, Iter last);
48 template <class Iter>
49 list(Iter first, Iter last, const allocator_type& a);
50 list(const list& x);
51 list(const list&, const allocator_type& a);
Howard Hinnant45900102011-06-03 17:30:28 +000052 list(list&& x)
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000054 list(list&&, const allocator_type& a);
55 list(initializer_list<value_type>);
56 list(initializer_list<value_type>, const allocator_type& a);
57
58 ~list();
59
60 list& operator=(const list& x);
Howard Hinnant45900102011-06-03 17:30:28 +000061 list& operator=(list&& x)
62 noexcept(
63 allocator_type::propagate_on_container_move_assignment::value &&
64 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +000065 list& operator=(initializer_list<value_type>);
66 template <class Iter>
67 void assign(Iter first, Iter last);
68 void assign(size_type n, const value_type& t);
69 void assign(initializer_list<value_type>);
70
Howard Hinnant45900102011-06-03 17:30:28 +000071 allocator_type get_allocator() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000072
Howard Hinnant45900102011-06-03 17:30:28 +000073 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;
Howard Hinnant3e519522010-05-11 19:42:16 +000085
86 reference front();
87 const_reference front() const;
88 reference back();
89 const_reference back() const;
90
Howard Hinnant45900102011-06-03 17:30:28 +000091 bool empty() const noexcept;
92 size_type size() const noexcept;
93 size_type max_size() const noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +000094
95 template <class... Args>
96 void emplace_front(Args&&... args);
97 void pop_front();
98 template <class... Args>
99 void emplace_back(Args&&... args);
100 void pop_back();
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);
113
114 iterator erase(const_iterator position);
115 iterator erase(const_iterator position, const_iterator last);
116
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
119
Howard Hinnant45900102011-06-03 17:30:28 +0000120 void swap(list&)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000121 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnant45900102011-06-03 17:30:28 +0000122 void clear() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000123
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);
132
133 void remove(const value_type& value);
134 template <class Pred> void remove_if(Pred pred);
135 void unique();
136 template <class BinaryPredicate>
137 void unique(BinaryPredicate binary_pred);
138 void merge(list& x);
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);
144 void sort();
145 template <class Compare>
146 void sort(Compare comp);
Howard Hinnant45900102011-06-03 17:30:28 +0000147 void reverse() noexcept;
Howard Hinnant3e519522010-05-11 19:42:16 +0000148};
149
150template <class T, class Alloc>
151 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
152template <class T, class Alloc>
153 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
154template <class T, class Alloc>
155 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
156template <class T, class Alloc>
157 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
158template <class T, class Alloc>
159 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
160template <class T, class Alloc>
161 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
162
163template <class T, class Alloc>
Howard Hinnant45900102011-06-03 17:30:28 +0000164 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
165 noexcept(noexcept(x.swap(y)));
Howard Hinnant3e519522010-05-11 19:42:16 +0000166
167} // std
168
169*/
170
171#include <__config>
172
173#include <memory>
174#include <limits>
175#include <initializer_list>
176#include <iterator>
177#include <algorithm>
Eric Fiselierb88ea352015-12-30 20:57:59 +0000178#include <type_traits>
Howard Hinnant3e519522010-05-11 19:42:16 +0000179
Howard Hinnantab4f4382011-11-29 16:45:27 +0000180#include <__undef_min_max>
181
Eric Fiselierc1bd9192014-08-10 23:53:08 +0000182#include <__debug>
Howard Hinnant42a30462013-08-02 00:26:35 +0000183
Howard Hinnant073458b2011-10-17 20:05:10 +0000184#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnant3e519522010-05-11 19:42:16 +0000185#pragma GCC system_header
Howard Hinnant073458b2011-10-17 20:05:10 +0000186#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000187
188_LIBCPP_BEGIN_NAMESPACE_STD
189
Howard Hinnantce534202011-06-14 19:58:17 +0000190template <class _Tp, class _VoidPtr> struct __list_node;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000191template <class _Tp, class _VoidPtr> struct __list_node_base;
192
193template <class _Tp, class _VoidPtr>
194struct __list_node_pointer_traits {
195 typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
196 __node_pointer;
197 typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
198 __base_pointer;
199
200#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
201 typedef __base_pointer __link_pointer;
202#else
203 typedef typename conditional<
204 is_pointer<_VoidPtr>::value,
205 __base_pointer,
206 __node_pointer
207 >::type __link_pointer;
208#endif
209
Eric Fiselier5243e192016-01-04 03:27:52 +0000210 typedef typename conditional<
211 is_same<__link_pointer, __node_pointer>::value,
212 __base_pointer,
213 __node_pointer
214 >::type __non_link_pointer;
215
216 static _LIBCPP_INLINE_VISIBILITY
217 __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
218 return __p;
219 }
220
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));
224 }
225
Eric Fiselierb88ea352015-12-30 20:57:59 +0000226};
Howard Hinnant3e519522010-05-11 19:42:16 +0000227
228template <class _Tp, class _VoidPtr>
229struct __list_node_base
230{
Eric Fiselierb88ea352015-12-30 20:57:59 +0000231 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;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000235
Eric Fiselierb88ea352015-12-30 20:57:59 +0000236 __link_pointer __prev_;
237 __link_pointer __next_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000238
Howard Hinnant848a5372010-09-22 16:48:34 +0000239 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5243e192016-01-04 03:27:52 +0000240 __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
241 __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
Marshall Clow28d65da2014-08-05 01:34:12 +0000242
243 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5243e192016-01-04 03:27:52 +0000244 __base_pointer __self() {
Eric Fiselierb88ea352015-12-30 20:57:59 +0000245 return pointer_traits<__base_pointer>::pointer_to(*this);
246 }
247
248 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000249 __node_pointer __as_node() {
Eric Fiselier5243e192016-01-04 03:27:52 +0000250 return static_cast<__node_pointer>(__self());
Marshall Clow28d65da2014-08-05 01:34:12 +0000251 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000252};
253
254template <class _Tp, class _VoidPtr>
255struct __list_node
256 : public __list_node_base<_Tp, _VoidPtr>
257{
258 _Tp __value_;
Eric Fiselier5243e192016-01-04 03:27:52 +0000259
260 typedef __list_node_base<_Tp, _VoidPtr> __base;
261 typedef typename __base::__link_pointer __link_pointer;
262
263 _LIBCPP_INLINE_VISIBILITY
264 __link_pointer __as_link() {
265 return static_cast<__link_pointer>(__base::__self());
266 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000267};
268
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000269template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnantce534202011-06-14 19:58:17 +0000270template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnantf0544c22013-08-12 18:38:34 +0000271template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000272
273template <class _Tp, class _VoidPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000274class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000275{
Eric Fiselierb88ea352015-12-30 20:57:59 +0000276 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
277 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000278
Eric Fiselierb88ea352015-12-30 20:57:59 +0000279 __link_pointer __ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000280
Howard Hinnant920b56c2011-09-27 23:55:03 +0000281#if _LIBCPP_DEBUG_LEVEL >= 2
282 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000283 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000284 : __ptr_(__p)
285 {
286 __get_db()->__insert_ic(this, __c);
287 }
288#else
Howard Hinnant848a5372010-09-22 16:48:34 +0000289 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000290 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant920b56c2011-09-27 23:55:03 +0000291#endif
292
293
Howard Hinnant3e519522010-05-11 19:42:16 +0000294
295 template<class, class> friend class list;
296 template<class, class> friend class __list_imp;
297 template<class, class> friend class __list_const_iterator;
298public:
299 typedef bidirectional_iterator_tag iterator_category;
300 typedef _Tp value_type;
301 typedef value_type& reference;
Eric Fiselier1c813402015-08-23 02:56:05 +0000302 typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000303 typedef typename pointer_traits<pointer>::difference_type difference_type;
304
Howard Hinnant848a5372010-09-22 16:48:34 +0000305 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0c37cfd2013-08-05 21:23:28 +0000306 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000307 {
308#if _LIBCPP_DEBUG_LEVEL >= 2
309 __get_db()->__insert_i(this);
310#endif
311 }
312
313#if _LIBCPP_DEBUG_LEVEL >= 2
314
Howard Hinnant27745452011-01-28 23:46:28 +0000315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000316 __list_iterator(const __list_iterator& __p)
317 : __ptr_(__p.__ptr_)
318 {
319 __get_db()->__iterator_copy(this, &__p);
320 }
321
322 _LIBCPP_INLINE_VISIBILITY
323 ~__list_iterator()
324 {
325 __get_db()->__erase_i(this);
326 }
327
328 _LIBCPP_INLINE_VISIBILITY
329 __list_iterator& operator=(const __list_iterator& __p)
330 {
331 if (this != &__p)
332 {
333 __get_db()->__iterator_copy(this, &__p);
334 __ptr_ = __p.__ptr_;
335 }
336 return *this;
337 }
338
339#endif // _LIBCPP_DEBUG_LEVEL >= 2
340
341 _LIBCPP_INLINE_VISIBILITY
342 reference operator*() const
343 {
344#if _LIBCPP_DEBUG_LEVEL >= 2
345 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
346 "Attempted to dereference a non-dereferenceable list::iterator");
347#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000348 return __ptr_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000349 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000351 pointer operator->() const
352 {
353#if _LIBCPP_DEBUG_LEVEL >= 2
354 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
355 "Attempted to dereference a non-dereferenceable list::iterator");
356#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000357 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000358 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000359
Howard Hinnant848a5372010-09-22 16:48:34 +0000360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000361 __list_iterator& operator++()
362 {
363#if _LIBCPP_DEBUG_LEVEL >= 2
364 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
365 "Attempted to increment non-incrementable list::iterator");
366#endif
367 __ptr_ = __ptr_->__next_;
368 return *this;
369 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000371 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
372
Howard Hinnant848a5372010-09-22 16:48:34 +0000373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000374 __list_iterator& operator--()
375 {
376#if _LIBCPP_DEBUG_LEVEL >= 2
377 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
378 "Attempted to decrement non-decrementable list::iterator");
379#endif
380 __ptr_ = __ptr_->__prev_;
381 return *this;
382 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000384 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
385
Howard Hinnant848a5372010-09-22 16:48:34 +0000386 friend _LIBCPP_INLINE_VISIBILITY
387 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000388 {
Howard Hinnant920b56c2011-09-27 23:55:03 +0000389 return __x.__ptr_ == __y.__ptr_;
390 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000391 friend _LIBCPP_INLINE_VISIBILITY
392 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000393 {return !(__x == __y);}
394};
395
396template <class _Tp, class _VoidPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000397class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000398{
Eric Fiselierb88ea352015-12-30 20:57:59 +0000399 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
400 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000401
Eric Fiselierb88ea352015-12-30 20:57:59 +0000402 __link_pointer __ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000403
Howard Hinnant920b56c2011-09-27 23:55:03 +0000404#if _LIBCPP_DEBUG_LEVEL >= 2
405 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000406 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000407 : __ptr_(__p)
408 {
409 __get_db()->__insert_ic(this, __c);
410 }
411#else
Howard Hinnant848a5372010-09-22 16:48:34 +0000412 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000413 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant920b56c2011-09-27 23:55:03 +0000414#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000415
416 template<class, class> friend class list;
417 template<class, class> friend class __list_imp;
418public:
419 typedef bidirectional_iterator_tag iterator_category;
420 typedef _Tp value_type;
421 typedef const value_type& reference;
Eric Fiselier1c813402015-08-23 02:56:05 +0000422 typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000423 typedef typename pointer_traits<pointer>::difference_type difference_type;
424
Howard Hinnant848a5372010-09-22 16:48:34 +0000425 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0c37cfd2013-08-05 21:23:28 +0000426 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000427 {
428#if _LIBCPP_DEBUG_LEVEL >= 2
429 __get_db()->__insert_i(this);
430#endif
431 }
Howard Hinnant27745452011-01-28 23:46:28 +0000432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7509232013-04-05 17:58:52 +0000433 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000434 : __ptr_(__p.__ptr_)
435 {
436#if _LIBCPP_DEBUG_LEVEL >= 2
437 __get_db()->__iterator_copy(this, &__p);
438#endif
439 }
440
441#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant3e519522010-05-11 19:42:16 +0000442
Howard Hinnant848a5372010-09-22 16:48:34 +0000443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000444 __list_const_iterator(const __list_const_iterator& __p)
445 : __ptr_(__p.__ptr_)
446 {
447 __get_db()->__iterator_copy(this, &__p);
448 }
449
450 _LIBCPP_INLINE_VISIBILITY
451 ~__list_const_iterator()
452 {
453 __get_db()->__erase_i(this);
454 }
455
456 _LIBCPP_INLINE_VISIBILITY
457 __list_const_iterator& operator=(const __list_const_iterator& __p)
458 {
459 if (this != &__p)
460 {
461 __get_db()->__iterator_copy(this, &__p);
462 __ptr_ = __p.__ptr_;
463 }
464 return *this;
465 }
466
467#endif // _LIBCPP_DEBUG_LEVEL >= 2
468 _LIBCPP_INLINE_VISIBILITY
469 reference operator*() const
470 {
471#if _LIBCPP_DEBUG_LEVEL >= 2
472 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
473 "Attempted to dereference a non-dereferenceable list::const_iterator");
474#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000475 return __ptr_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000476 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000478 pointer operator->() const
479 {
480#if _LIBCPP_DEBUG_LEVEL >= 2
481 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
482 "Attempted to dereference a non-dereferenceable list::iterator");
483#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000484 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000485 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000486
Howard Hinnant848a5372010-09-22 16:48:34 +0000487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000488 __list_const_iterator& operator++()
489 {
490#if _LIBCPP_DEBUG_LEVEL >= 2
491 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
492 "Attempted to increment non-incrementable list::const_iterator");
493#endif
494 __ptr_ = __ptr_->__next_;
495 return *this;
496 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000498 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
499
Howard Hinnant848a5372010-09-22 16:48:34 +0000500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000501 __list_const_iterator& operator--()
502 {
503#if _LIBCPP_DEBUG_LEVEL >= 2
504 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
505 "Attempted to decrement non-decrementable list::const_iterator");
506#endif
507 __ptr_ = __ptr_->__prev_;
508 return *this;
509 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000511 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
512
Howard Hinnant848a5372010-09-22 16:48:34 +0000513 friend _LIBCPP_INLINE_VISIBILITY
514 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000515 {
Howard Hinnant920b56c2011-09-27 23:55:03 +0000516 return __x.__ptr_ == __y.__ptr_;
517 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000518 friend _LIBCPP_INLINE_VISIBILITY
519 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000520 {return !(__x == __y);}
521};
522
523template <class _Tp, class _Alloc>
524class __list_imp
525{
526 __list_imp(const __list_imp&);
527 __list_imp& operator=(const __list_imp&);
528protected:
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;
Marshall Clow1f508012015-04-07 05:21:38 +0000538 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000539 typedef allocator_traits<__node_allocator> __node_alloc_traits;
540 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000541 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Eric Fiselier5243e192016-01-04 03:27:52 +0000542 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
543 typedef typename __node_pointer_traits::__link_pointer __link_pointer;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000544 typedef __link_pointer __link_const_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000545 typedef typename __alloc_traits::pointer pointer;
546 typedef typename __alloc_traits::const_pointer const_pointer;
547 typedef typename __alloc_traits::difference_type difference_type;
548
Marshall Clow1f508012015-04-07 05:21:38 +0000549 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000550 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
551
Howard Hinnant3e519522010-05-11 19:42:16 +0000552 __node_base __end_;
553 __compressed_pair<size_type, __node_allocator> __size_alloc_;
554
Howard Hinnant848a5372010-09-22 16:48:34 +0000555 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5243e192016-01-04 03:27:52 +0000556 __link_pointer __end_as_link() const _NOEXCEPT {
557 return __node_pointer_traits::__unsafe_link_pointer_cast(
558 const_cast<__node_base&>(__end_).__self());
559 }
560
561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000562 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000564 const size_type& __sz() const _NOEXCEPT
565 {return __size_alloc_.first();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000567 __node_allocator& __node_alloc() _NOEXCEPT
568 {return __size_alloc_.second();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000570 const __node_allocator& __node_alloc() const _NOEXCEPT
571 {return __size_alloc_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000572
Eric Fiselierb88ea352015-12-30 20:57:59 +0000573 static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000574
Howard Hinnant45900102011-06-03 17:30:28 +0000575 __list_imp()
576 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000577 __list_imp(const allocator_type& __a);
578 ~__list_imp();
Howard Hinnant45900102011-06-03 17:30:28 +0000579 void clear() _NOEXCEPT;
Howard Hinnant848a5372010-09-22 16:48:34 +0000580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000581 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000582
Howard Hinnant848a5372010-09-22 16:48:34 +0000583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000584 iterator begin() _NOEXCEPT
585 {
586#if _LIBCPP_DEBUG_LEVEL >= 2
587 return iterator(__end_.__next_, this);
588#else
589 return iterator(__end_.__next_);
590#endif
591 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000592 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000593 const_iterator begin() const _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000594 {
595#if _LIBCPP_DEBUG_LEVEL >= 2
596 return const_iterator(__end_.__next_, this);
597#else
598 return const_iterator(__end_.__next_);
599#endif
600 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000601 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000602 iterator end() _NOEXCEPT
603 {
604#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5243e192016-01-04 03:27:52 +0000605 return iterator(__end_as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +0000606#else
Eric Fiselier5243e192016-01-04 03:27:52 +0000607 return iterator(__end_as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +0000608#endif
609 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000610 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000611 const_iterator end() const _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000612 {
613#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5243e192016-01-04 03:27:52 +0000614 return const_iterator(__end_as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +0000615#else
Eric Fiselier5243e192016-01-04 03:27:52 +0000616 return const_iterator(__end_as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +0000617#endif
618 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000619
Howard Hinnant45900102011-06-03 17:30:28 +0000620 void swap(__list_imp& __c)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000621#if _LIBCPP_STD_VER >= 14
622 _NOEXCEPT;
623#else
624 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
625 __is_nothrow_swappable<allocator_type>::value);
626#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000627
Howard Hinnant848a5372010-09-22 16:48:34 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000629 void __copy_assign_alloc(const __list_imp& __c)
630 {__copy_assign_alloc(__c, integral_constant<bool,
631 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
632
Howard Hinnant848a5372010-09-22 16:48:34 +0000633 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000634 void __move_assign_alloc(__list_imp& __c)
Howard Hinnant45900102011-06-03 17:30:28 +0000635 _NOEXCEPT_(
636 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
637 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000638 {__move_assign_alloc(__c, integral_constant<bool,
639 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
640
641private:
Howard Hinnant848a5372010-09-22 16:48:34 +0000642 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000643 void __copy_assign_alloc(const __list_imp& __c, true_type)
644 {
645 if (__node_alloc() != __c.__node_alloc())
646 clear();
647 __node_alloc() = __c.__node_alloc();
648 }
649
Howard Hinnant848a5372010-09-22 16:48:34 +0000650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000651 void __copy_assign_alloc(const __list_imp& __c, false_type)
652 {}
653
Howard Hinnant848a5372010-09-22 16:48:34 +0000654 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86681392011-09-02 20:42:31 +0000655 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnant45900102011-06-03 17:30:28 +0000656 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000657 {
Howard Hinnantce48a112011-06-30 21:18:19 +0000658 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +0000659 }
660
Howard Hinnant848a5372010-09-22 16:48:34 +0000661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86681392011-09-02 20:42:31 +0000662 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnant45900102011-06-03 17:30:28 +0000663 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000664 {}
665};
666
667// Unlink nodes [__f, __l]
668template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +0000669inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000670void
Eric Fiselierb88ea352015-12-30 20:57:59 +0000671__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
Howard Hinnant45900102011-06-03 17:30:28 +0000672 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000673{
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000674 __f->__prev_->__next_ = __l->__next_;
675 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000676}
677
678template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +0000679inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000680__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnant45900102011-06-03 17:30:28 +0000681 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000682 : __size_alloc_(0)
683{
684}
685
686template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +0000687inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000688__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
689 : __size_alloc_(0, __node_allocator(__a))
690{
691}
692
693template <class _Tp, class _Alloc>
694__list_imp<_Tp, _Alloc>::~__list_imp()
695{
696 clear();
Howard Hinnant920b56c2011-09-27 23:55:03 +0000697#if _LIBCPP_DEBUG_LEVEL >= 2
698 __get_db()->__erase_c(this);
699#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000700}
701
702template <class _Tp, class _Alloc>
703void
Howard Hinnant45900102011-06-03 17:30:28 +0000704__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000705{
706 if (!empty())
707 {
708 __node_allocator& __na = __node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +0000709 __link_pointer __f = __end_.__next_;
Eric Fiselier5243e192016-01-04 03:27:52 +0000710 __link_pointer __l = __end_as_link();
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000711 __unlink_nodes(__f, __l->__prev_);
Howard Hinnant3e519522010-05-11 19:42:16 +0000712 __sz() = 0;
713 while (__f != __l)
714 {
Eric Fiselierb88ea352015-12-30 20:57:59 +0000715 __node_pointer __np = __f->__as_node();
Howard Hinnant920b56c2011-09-27 23:55:03 +0000716 __f = __f->__next_;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000717 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
718 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +0000719 }
Howard Hinnant920b56c2011-09-27 23:55:03 +0000720#if _LIBCPP_DEBUG_LEVEL >= 2
721 __c_node* __c = __get_db()->__find_c_and_lock(this);
722 for (__i_node** __p = __c->end_; __p != __c->beg_; )
723 {
724 --__p;
725 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
726 if (__i->__ptr_ != __l)
727 {
728 (*__p)->__c_ = nullptr;
729 if (--__c->end_ != __p)
730 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
731 }
732 }
733 __get_db()->unlock();
734#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000735 }
736}
737
738template <class _Tp, class _Alloc>
739void
740__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000741#if _LIBCPP_STD_VER >= 14
742 _NOEXCEPT
743#else
744 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
745 __is_nothrow_swappable<allocator_type>::value)
746#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000747{
Howard Hinnant920b56c2011-09-27 23:55:03 +0000748 _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");
Howard Hinnantce48a112011-06-30 21:18:19 +0000752 using _VSTD::swap;
Marshall Clowe3fbe142015-07-13 20:04:56 +0000753 __swap_allocator(__node_alloc(), __c.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +0000754 swap(__sz(), __c.__sz());
755 swap(__end_, __c.__end_);
756 if (__sz() == 0)
Eric Fiselier5243e192016-01-04 03:27:52 +0000757 __end_.__next_ = __end_.__prev_ = __end_as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +0000758 else
Eric Fiselier5243e192016-01-04 03:27:52 +0000759 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +0000760 if (__c.__sz() == 0)
Eric Fiselier5243e192016-01-04 03:27:52 +0000761 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +0000762 else
Eric Fiselier5243e192016-01-04 03:27:52 +0000763 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
Marshall Clow28d65da2014-08-05 01:34:12 +0000764
Howard Hinnant920b56c2011-09-27 23:55:03 +0000765#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_;)
773 {
774 --__p;
775 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselier5243e192016-01-04 03:27:52 +0000776 if (__i->__ptr_ == __c.__end_as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +0000777 {
778 __cn2->__add(*__p);
779 if (--__cn1->end_ != __p)
780 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
781 }
782 else
783 (*__p)->__c_ = __cn1;
784 }
785 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
786 {
787 --__p;
788 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselier5243e192016-01-04 03:27:52 +0000789 if (__i->__ptr_ == __end_as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +0000790 {
791 __cn1->__add(*__p);
792 if (--__cn2->end_ != __p)
793 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
794 }
795 else
796 (*__p)->__c_ = __cn2;
797 }
798 __db->unlock();
799#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000800}
801
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000802template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000803class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnant3e519522010-05-11 19:42:16 +0000804 : private __list_imp<_Tp, _Alloc>
805{
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;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000811 typedef typename base::__node_base __node_base;
812 typedef typename base::__node_base_pointer __node_base_pointer;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000813 typedef typename base::__link_pointer __link_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000814
815public:
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;
Howard Hinnantce48a112011-06-30 21:18:19 +0000828 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
829 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000830
Howard Hinnant848a5372010-09-22 16:48:34 +0000831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000832 list()
833 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000834 {
835#if _LIBCPP_DEBUG_LEVEL >= 2
836 __get_db()->__insert_c(this);
837#endif
838 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000839 _LIBCPP_INLINE_VISIBILITY
Marshall Clowfb829762013-09-08 19:11:51 +0000840 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000841 {
842#if _LIBCPP_DEBUG_LEVEL >= 2
843 __get_db()->__insert_c(this);
844#endif
845 }
Marshall Clowfb829762013-09-08 19:11:51 +0000846 explicit list(size_type __n);
847#if _LIBCPP_STD_VER > 11
848 explicit list(size_type __n, const allocator_type& __a);
849#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000850 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);
858
859 list(const list& __c);
860 list(const list& __c, const allocator_type& __a);
861 list& operator=(const list& __c);
Howard Hinnant54976f22011-08-12 21:56:02 +0000862#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000863 list(initializer_list<value_type> __il);
864 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000865#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000866#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant45900102011-06-03 17:30:28 +0000867 list(list&& __c)
868 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000869 list(list&& __c, const allocator_type& __a);
Howard Hinnant45900102011-06-03 17:30:28 +0000870 list& operator=(list&& __c)
871 _NOEXCEPT_(
872 __node_alloc_traits::propagate_on_container_move_assignment::value &&
873 is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000874#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000875#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant848a5372010-09-22 16:48:34 +0000876 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000877 list& operator=(initializer_list<value_type> __il)
878 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnant54976f22011-08-12 21:56:02 +0000879#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000880
881 template <class _InpIter>
882 void assign(_InpIter __f, _InpIter __l,
883 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
884 void assign(size_type __n, const value_type& __x);
Howard Hinnant54976f22011-08-12 21:56:02 +0000885#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant848a5372010-09-22 16:48:34 +0000886 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000887 void assign(initializer_list<value_type> __il)
888 {assign(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000889#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000890
Howard Hinnant45900102011-06-03 17:30:28 +0000891 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000892
Howard Hinnant848a5372010-09-22 16:48:34 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000894 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000896 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000898 size_type max_size() const _NOEXCEPT
899 {return numeric_limits<difference_type>::max();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000900
Howard Hinnant848a5372010-09-22 16:48:34 +0000901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000902 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000904 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000906 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000908 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000910 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000912 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000913
Howard Hinnant848a5372010-09-22 16:48:34 +0000914 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000915 reverse_iterator rbegin() _NOEXCEPT
916 {return reverse_iterator(end());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000918 const_reverse_iterator rbegin() const _NOEXCEPT
919 {return const_reverse_iterator(end());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000921 reverse_iterator rend() _NOEXCEPT
922 {return reverse_iterator(begin());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000924 const_reverse_iterator rend() const _NOEXCEPT
925 {return const_reverse_iterator(begin());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000927 const_reverse_iterator crbegin() const _NOEXCEPT
928 {return const_reverse_iterator(end());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000930 const_reverse_iterator crend() const _NOEXCEPT
931 {return const_reverse_iterator(begin());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000932
Howard Hinnant848a5372010-09-22 16:48:34 +0000933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000934 reference front()
935 {
936 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000937 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000938 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000940 const_reference front() const
941 {
942 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000943 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000944 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000946 reference back()
947 {
948 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000949 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000950 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000952 const_reference back() const
953 {
954 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000955 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000956 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000957
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000958#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000959 void push_front(value_type&& __x);
960 void push_back(value_type&& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000961#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000962 template <class... _Args>
963 void emplace_front(_Args&&... __args);
964 template <class... _Args>
965 void emplace_back(_Args&&... __args);
966 template <class... _Args>
967 iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000968#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000969 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000970#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000971
972 void push_front(const value_type& __x);
973 void push_back(const value_type& __x);
974
975 iterator insert(const_iterator __p, const value_type& __x);
976 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
977 template <class _InpIter>
978 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
979 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnant54976f22011-08-12 21:56:02 +0000980#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant848a5372010-09-22 16:48:34 +0000981 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000982 iterator insert(const_iterator __p, initializer_list<value_type> __il)
983 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000984#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000985
Howard Hinnant848a5372010-09-22 16:48:34 +0000986 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000987 void swap(list& __c)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000988#if _LIBCPP_STD_VER >= 14
989 _NOEXCEPT
990#else
Howard Hinnant45900102011-06-03 17:30:28 +0000991 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
992 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000993#endif
Howard Hinnant45900102011-06-03 17:30:28 +0000994 {base::swap(__c);}
Howard Hinnant848a5372010-09-22 16:48:34 +0000995 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000996 void clear() _NOEXCEPT {base::clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000997
998 void pop_front();
999 void pop_back();
1000
1001 iterator erase(const_iterator __p);
1002 iterator erase(const_iterator __f, const_iterator __l);
1003
1004 void resize(size_type __n);
1005 void resize(size_type __n, const value_type& __x);
1006
1007 void splice(const_iterator __p, list& __c);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001008#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001010 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1011#endif
1012 void splice(const_iterator __p, list& __c, const_iterator __i);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +00001014 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001015 void splice(const_iterator __p, list&& __c, const_iterator __i)
1016 {splice(__p, __c, __i);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001017#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001018 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001019#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +00001020 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001021 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1022 {splice(__p, __c, __f, __l);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001023#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001024
1025 void remove(const value_type& __x);
1026 template <class _Pred> void remove_if(_Pred __pred);
1027 void unique();
1028 template <class _BinaryPred>
1029 void unique(_BinaryPred __binary_pred);
1030 void merge(list& __c);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001031#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +00001032 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001033 void merge(list&& __c) {merge(__c);}
1034#endif
1035 template <class _Comp>
1036 void merge(list& __c, _Comp __comp);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001037#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001038 template <class _Comp>
Howard Hinnant848a5372010-09-22 16:48:34 +00001039 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001040 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001041#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001042 void sort();
1043 template <class _Comp>
1044 void sort(_Comp __comp);
1045
Howard Hinnant45900102011-06-03 17:30:28 +00001046 void reverse() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001047
Howard Hinnant920b56c2011-09-27 23:55:03 +00001048 bool __invariants() const;
1049
1050#if _LIBCPP_DEBUG_LEVEL >= 2
1051
1052 bool __dereferenceable(const const_iterator* __i) const;
1053 bool __decrementable(const const_iterator* __i) const;
1054 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1055 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1056
1057#endif // _LIBCPP_DEBUG_LEVEL >= 2
1058
Howard Hinnant3e519522010-05-11 19:42:16 +00001059private:
Eric Fiselierb88ea352015-12-30 20:57:59 +00001060 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
1061 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
1062 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00001063 iterator __iterator(size_type __n);
1064 template <class _Comp>
1065 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1066
Howard Hinnant45900102011-06-03 17:30:28 +00001067 void __move_assign(list& __c, true_type)
1068 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001069 void __move_assign(list& __c, false_type);
1070};
1071
1072// Link in nodes [__f, __l] just prior to __p
1073template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001074inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001075void
Eric Fiselierb88ea352015-12-30 20:57:59 +00001076list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
Howard Hinnant3e519522010-05-11 19:42:16 +00001077{
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001078 __p->__prev_->__next_ = __f;
1079 __f->__prev_ = __p->__prev_;
1080 __p->__prev_ = __l;
1081 __l->__next_ = __p;
Howard Hinnant3e519522010-05-11 19:42:16 +00001082}
1083
Marshall Clow28d65da2014-08-05 01:34:12 +00001084// Link in nodes [__f, __l] at the front of the list
1085template <class _Tp, class _Alloc>
1086inline _LIBCPP_INLINE_VISIBILITY
1087void
Eric Fiselierb88ea352015-12-30 20:57:59 +00001088list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
Marshall Clow28d65da2014-08-05 01:34:12 +00001089{
Eric Fiselier5243e192016-01-04 03:27:52 +00001090 __f->__prev_ = base::__end_as_link();
Marshall Clowced70062014-08-08 15:35:52 +00001091 __l->__next_ = base::__end_.__next_;
1092 __l->__next_->__prev_ = __l;
1093 base::__end_.__next_ = __f;
Marshall Clow28d65da2014-08-05 01:34:12 +00001094}
1095
1096// Link in nodes [__f, __l] at the front of the list
1097template <class _Tp, class _Alloc>
1098inline _LIBCPP_INLINE_VISIBILITY
1099void
Eric Fiselierb88ea352015-12-30 20:57:59 +00001100list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
Marshall Clow28d65da2014-08-05 01:34:12 +00001101{
Eric Fiselier5243e192016-01-04 03:27:52 +00001102 __l->__next_ = base::__end_as_link();
Marshall Clowced70062014-08-08 15:35:52 +00001103 __f->__prev_ = base::__end_.__prev_;
1104 __f->__prev_->__next_ = __f;
1105 base::__end_.__prev_ = __l;
Marshall Clow28d65da2014-08-05 01:34:12 +00001106}
1107
1108
Howard Hinnant3e519522010-05-11 19:42:16 +00001109template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001110inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001111typename list<_Tp, _Alloc>::iterator
1112list<_Tp, _Alloc>::__iterator(size_type __n)
1113{
Howard Hinnantce48a112011-06-30 21:18:19 +00001114 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1115 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnant3e519522010-05-11 19:42:16 +00001116}
1117
1118template <class _Tp, class _Alloc>
1119list<_Tp, _Alloc>::list(size_type __n)
1120{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001121#if _LIBCPP_DEBUG_LEVEL >= 2
1122 __get_db()->__insert_c(this);
1123#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001124 for (; __n > 0; --__n)
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001125#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001126 emplace_back();
1127#else
1128 push_back(value_type());
1129#endif
1130}
1131
Marshall Clowfb829762013-09-08 19:11:51 +00001132#if _LIBCPP_STD_VER > 11
1133template <class _Tp, class _Alloc>
1134list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1135{
1136#if _LIBCPP_DEBUG_LEVEL >= 2
1137 __get_db()->__insert_c(this);
1138#endif
1139 for (; __n > 0; --__n)
1140#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1141 emplace_back();
1142#else
1143 push_back(value_type());
1144#endif
1145}
1146#endif
1147
Howard Hinnant3e519522010-05-11 19:42:16 +00001148template <class _Tp, class _Alloc>
1149list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1150{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001151#if _LIBCPP_DEBUG_LEVEL >= 2
1152 __get_db()->__insert_c(this);
1153#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001154 for (; __n > 0; --__n)
1155 push_back(__x);
1156}
1157
1158template <class _Tp, class _Alloc>
1159list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1160 : base(__a)
1161{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001162#if _LIBCPP_DEBUG_LEVEL >= 2
1163 __get_db()->__insert_c(this);
1164#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001165 for (; __n > 0; --__n)
1166 push_back(__x);
1167}
1168
1169template <class _Tp, class _Alloc>
1170template <class _InpIter>
1171list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1172 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1173{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001174#if _LIBCPP_DEBUG_LEVEL >= 2
1175 __get_db()->__insert_c(this);
1176#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001177 for (; __f != __l; ++__f)
1178 push_back(*__f);
1179}
1180
1181template <class _Tp, class _Alloc>
1182template <class _InpIter>
1183list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1184 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1185 : base(__a)
1186{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001187#if _LIBCPP_DEBUG_LEVEL >= 2
1188 __get_db()->__insert_c(this);
1189#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001190 for (; __f != __l; ++__f)
1191 push_back(*__f);
1192}
1193
1194template <class _Tp, class _Alloc>
1195list<_Tp, _Alloc>::list(const list& __c)
1196 : base(allocator_type(
1197 __node_alloc_traits::select_on_container_copy_construction(
1198 __c.__node_alloc())))
1199{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001200#if _LIBCPP_DEBUG_LEVEL >= 2
1201 __get_db()->__insert_c(this);
1202#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001203 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1204 push_back(*__i);
1205}
1206
1207template <class _Tp, class _Alloc>
1208list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1209 : base(__a)
1210{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001211#if _LIBCPP_DEBUG_LEVEL >= 2
1212 __get_db()->__insert_c(this);
1213#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001214 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1215 push_back(*__i);
1216}
1217
Howard Hinnant54976f22011-08-12 21:56:02 +00001218#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1219
Howard Hinnant3e519522010-05-11 19:42:16 +00001220template <class _Tp, class _Alloc>
1221list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1222 : base(__a)
1223{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001224#if _LIBCPP_DEBUG_LEVEL >= 2
1225 __get_db()->__insert_c(this);
1226#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001227 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1228 __e = __il.end(); __i != __e; ++__i)
1229 push_back(*__i);
1230}
1231
1232template <class _Tp, class _Alloc>
1233list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1234{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001235#if _LIBCPP_DEBUG_LEVEL >= 2
1236 __get_db()->__insert_c(this);
1237#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001238 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1239 __e = __il.end(); __i != __e; ++__i)
1240 push_back(*__i);
1241}
1242
Howard Hinnant54976f22011-08-12 21:56:02 +00001243#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1244
Howard Hinnant3e519522010-05-11 19:42:16 +00001245template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001246inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001247list<_Tp, _Alloc>&
1248list<_Tp, _Alloc>::operator=(const list& __c)
1249{
1250 if (this != &__c)
1251 {
1252 base::__copy_assign_alloc(__c);
1253 assign(__c.begin(), __c.end());
1254 }
1255 return *this;
1256}
1257
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001258#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001259
1260template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001261inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001262list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnant45900102011-06-03 17:30:28 +00001263 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001264 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnant3e519522010-05-11 19:42:16 +00001265{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001266#if _LIBCPP_DEBUG_LEVEL >= 2
1267 __get_db()->__insert_c(this);
1268#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001269 splice(end(), __c);
1270}
1271
1272template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001273inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001274list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1275 : base(__a)
1276{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001277#if _LIBCPP_DEBUG_LEVEL >= 2
1278 __get_db()->__insert_c(this);
1279#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001280 if (__a == __c.get_allocator())
1281 splice(end(), __c);
1282 else
1283 {
Howard Hinnantc003db12011-11-29 18:15:50 +00001284 typedef move_iterator<iterator> _Ip;
1285 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +00001286 }
1287}
1288
1289template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001290inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001291list<_Tp, _Alloc>&
1292list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnant45900102011-06-03 17:30:28 +00001293 _NOEXCEPT_(
1294 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1295 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001296{
1297 __move_assign(__c, integral_constant<bool,
1298 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1299 return *this;
1300}
1301
1302template <class _Tp, class _Alloc>
1303void
1304list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1305{
1306 if (base::__node_alloc() != __c.__node_alloc())
1307 {
Howard Hinnantc003db12011-11-29 18:15:50 +00001308 typedef move_iterator<iterator> _Ip;
1309 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +00001310 }
1311 else
1312 __move_assign(__c, true_type());
1313}
1314
1315template <class _Tp, class _Alloc>
1316void
1317list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnant45900102011-06-03 17:30:28 +00001318 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001319{
1320 clear();
1321 base::__move_assign_alloc(__c);
1322 splice(end(), __c);
1323}
1324
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001325#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001326
1327template <class _Tp, class _Alloc>
1328template <class _InpIter>
1329void
1330list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1331 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1332{
1333 iterator __i = begin();
1334 iterator __e = end();
1335 for (; __f != __l && __i != __e; ++__f, ++__i)
1336 *__i = *__f;
1337 if (__i == __e)
1338 insert(__e, __f, __l);
1339 else
1340 erase(__i, __e);
1341}
1342
1343template <class _Tp, class _Alloc>
1344void
1345list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1346{
1347 iterator __i = begin();
1348 iterator __e = end();
1349 for (; __n > 0 && __i != __e; --__n, ++__i)
1350 *__i = __x;
1351 if (__i == __e)
1352 insert(__e, __n, __x);
1353 else
1354 erase(__i, __e);
1355}
1356
1357template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001358inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001359_Alloc
Howard Hinnant45900102011-06-03 17:30:28 +00001360list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001361{
1362 return allocator_type(base::__node_alloc());
1363}
1364
1365template <class _Tp, class _Alloc>
1366typename list<_Tp, _Alloc>::iterator
1367list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1368{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001369#if _LIBCPP_DEBUG_LEVEL >= 2
1370 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1371 "list::insert(iterator, x) called with an iterator not"
1372 " referring to this list");
1373#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001374 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001375 typedef __allocator_destructor<__node_allocator> _Dp;
1376 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001377 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001378 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001379 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001380 ++base::__sz();
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001381#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001382 return iterator(__hold.release()->__as_link(), this);
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001383#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001384 return iterator(__hold.release()->__as_link());
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001385#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001386}
1387
1388template <class _Tp, class _Alloc>
1389typename list<_Tp, _Alloc>::iterator
1390list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1391{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001392#if _LIBCPP_DEBUG_LEVEL >= 2
1393 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1394 "list::insert(iterator, n, x) called with an iterator not"
1395 " referring to this list");
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001396 iterator __r(__p.__ptr_, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001397#else
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001398 iterator __r(__p.__ptr_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001399#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001400 if (__n > 0)
1401 {
1402 size_type __ds = 0;
1403 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001404 typedef __allocator_destructor<__node_allocator> _Dp;
1405 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001406 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001407 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant3e519522010-05-11 19:42:16 +00001408 ++__ds;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001409#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001410 __r = iterator(__hold->__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001411#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001412 __r = iterator(__hold->__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +00001413#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001414 __hold.release();
1415 iterator __e = __r;
1416#ifndef _LIBCPP_NO_EXCEPTIONS
1417 try
1418 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001419#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001420 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1421 {
1422 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001423 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001424 __e.__ptr_->__next_ = __hold->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001425 __hold->__prev_ = __e.__ptr_;
1426 __hold.release();
1427 }
1428#ifndef _LIBCPP_NO_EXCEPTIONS
1429 }
1430 catch (...)
1431 {
1432 while (true)
1433 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001434 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001435 __link_pointer __prev = __e.__ptr_->__prev_;
1436 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001437 if (__prev == 0)
1438 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001439#if _LIBCPP_DEBUG_LEVEL >= 2
1440 __e = iterator(__prev, this);
1441#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001442 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001443#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001444 }
1445 throw;
1446 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001447#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001448 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001449 base::__sz() += __ds;
1450 }
1451 return __r;
1452}
1453
1454template <class _Tp, class _Alloc>
1455template <class _InpIter>
1456typename list<_Tp, _Alloc>::iterator
1457list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1458 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1459{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001460#if _LIBCPP_DEBUG_LEVEL >= 2
1461 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1462 "list::insert(iterator, range) called with an iterator not"
1463 " referring to this list");
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001464 iterator __r(__p.__ptr_, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001465#else
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001466 iterator __r(__p.__ptr_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001467#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001468 if (__f != __l)
1469 {
1470 size_type __ds = 0;
1471 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001472 typedef __allocator_destructor<__node_allocator> _Dp;
1473 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001474 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001475 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001476 ++__ds;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001477#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001478 __r = iterator(__hold.get()->__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001479#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001480 __r = iterator(__hold.get()->__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +00001481#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001482 __hold.release();
1483 iterator __e = __r;
1484#ifndef _LIBCPP_NO_EXCEPTIONS
1485 try
1486 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001487#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier61bff612015-03-19 03:20:02 +00001488 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnant3e519522010-05-11 19:42:16 +00001489 {
1490 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001491 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001492 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001493 __hold->__prev_ = __e.__ptr_;
1494 __hold.release();
1495 }
1496#ifndef _LIBCPP_NO_EXCEPTIONS
1497 }
1498 catch (...)
1499 {
1500 while (true)
1501 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001502 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001503 __link_pointer __prev = __e.__ptr_->__prev_;
1504 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001505 if (__prev == 0)
1506 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001507#if _LIBCPP_DEBUG_LEVEL >= 2
1508 __e = iterator(__prev, this);
1509#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001510 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001511#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001512 }
1513 throw;
1514 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001515#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001516 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001517 base::__sz() += __ds;
1518 }
1519 return __r;
1520}
1521
1522template <class _Tp, class _Alloc>
1523void
1524list<_Tp, _Alloc>::push_front(const value_type& __x)
1525{
1526 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001527 typedef __allocator_destructor<__node_allocator> _Dp;
1528 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001529 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001530 __link_pointer __nl = __hold->__as_link();
1531 __link_nodes_at_front(__nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001532 ++base::__sz();
1533 __hold.release();
1534}
1535
1536template <class _Tp, class _Alloc>
1537void
1538list<_Tp, _Alloc>::push_back(const value_type& __x)
1539{
1540 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001541 typedef __allocator_destructor<__node_allocator> _Dp;
1542 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001543 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001544 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001545 ++base::__sz();
1546 __hold.release();
1547}
1548
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001549#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001550
1551template <class _Tp, class _Alloc>
1552void
1553list<_Tp, _Alloc>::push_front(value_type&& __x)
1554{
1555 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001556 typedef __allocator_destructor<__node_allocator> _Dp;
1557 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001558 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001559 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001560 ++base::__sz();
1561 __hold.release();
1562}
1563
1564template <class _Tp, class _Alloc>
1565void
1566list<_Tp, _Alloc>::push_back(value_type&& __x)
1567{
1568 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001569 typedef __allocator_destructor<__node_allocator> _Dp;
1570 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001571 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001572 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001573 ++base::__sz();
1574 __hold.release();
1575}
1576
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001577#ifndef _LIBCPP_HAS_NO_VARIADICS
1578
Howard Hinnant3e519522010-05-11 19:42:16 +00001579template <class _Tp, class _Alloc>
1580template <class... _Args>
1581void
1582list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1583{
1584 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001585 typedef __allocator_destructor<__node_allocator> _Dp;
1586 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001587 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001588 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001589 ++base::__sz();
1590 __hold.release();
1591}
1592
1593template <class _Tp, class _Alloc>
1594template <class... _Args>
1595void
1596list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1597{
1598 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001599 typedef __allocator_destructor<__node_allocator> _Dp;
1600 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001601 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001602 __link_pointer __nl = __hold->__as_link();
1603 __link_nodes_at_back(__nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001604 ++base::__sz();
1605 __hold.release();
1606}
1607
1608template <class _Tp, class _Alloc>
1609template <class... _Args>
1610typename list<_Tp, _Alloc>::iterator
1611list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1612{
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001613#if _LIBCPP_DEBUG_LEVEL >= 2
1614 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1615 "list::emplace(iterator, args...) called with an iterator not"
1616 " referring to this list");
1617#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001618 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001619 typedef __allocator_destructor<__node_allocator> _Dp;
1620 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001621 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001622 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001623 __link_pointer __nl = __hold.get()->__as_link();
1624 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001625 ++base::__sz();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001626 __hold.release();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001627#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001628 return iterator(__nl, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001629#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001630 return iterator(__nl);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001631#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001632}
1633
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001634#endif // _LIBCPP_HAS_NO_VARIADICS
1635
Howard Hinnant3e519522010-05-11 19:42:16 +00001636template <class _Tp, class _Alloc>
1637typename list<_Tp, _Alloc>::iterator
1638list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1639{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001640#if _LIBCPP_DEBUG_LEVEL >= 2
1641 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1642 "list::insert(iterator, x) called with an iterator not"
1643 " referring to this list");
1644#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001645 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001646 typedef __allocator_destructor<__node_allocator> _Dp;
1647 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001648 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001649 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001650 __link_pointer __nl = __hold->__as_link();
1651 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001652 ++base::__sz();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001653 __hold.release();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001654#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001655 return iterator(__nl, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001656#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001657 return iterator(__nl);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001658#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001659}
1660
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001661#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001662
1663template <class _Tp, class _Alloc>
1664void
1665list<_Tp, _Alloc>::pop_front()
1666{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001667 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnant3e519522010-05-11 19:42:16 +00001668 __node_allocator& __na = base::__node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001669 __link_pointer __n = base::__end_.__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001670 base::__unlink_nodes(__n, __n);
1671 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001672#if _LIBCPP_DEBUG_LEVEL >= 2
1673 __c_node* __c = __get_db()->__find_c_and_lock(this);
1674 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1675 {
1676 --__p;
1677 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001678 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001679 {
1680 (*__p)->__c_ = nullptr;
1681 if (--__c->end_ != __p)
1682 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1683 }
1684 }
1685 __get_db()->unlock();
1686#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001687 __node_pointer __np = __n->__as_node();
1688 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1689 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001690}
1691
1692template <class _Tp, class _Alloc>
1693void
1694list<_Tp, _Alloc>::pop_back()
1695{
Dmitri Gribenkoc3f9c802013-06-24 06:15:57 +00001696 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnant3e519522010-05-11 19:42:16 +00001697 __node_allocator& __na = base::__node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001698 __link_pointer __n = base::__end_.__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001699 base::__unlink_nodes(__n, __n);
1700 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001701#if _LIBCPP_DEBUG_LEVEL >= 2
1702 __c_node* __c = __get_db()->__find_c_and_lock(this);
1703 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1704 {
1705 --__p;
1706 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001707 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001708 {
1709 (*__p)->__c_ = nullptr;
1710 if (--__c->end_ != __p)
1711 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1712 }
1713 }
1714 __get_db()->unlock();
1715#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001716 __node_pointer __np = __n->__as_node();
1717 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1718 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001719}
1720
1721template <class _Tp, class _Alloc>
1722typename list<_Tp, _Alloc>::iterator
1723list<_Tp, _Alloc>::erase(const_iterator __p)
1724{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001725#if _LIBCPP_DEBUG_LEVEL >= 2
1726 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1727 "list::erase(iterator) called with an iterator not"
1728 " referring to this list");
1729#endif
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001730 _LIBCPP_ASSERT(__p != end(),
1731 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +00001732 __node_allocator& __na = base::__node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001733 __link_pointer __n = __p.__ptr_;
1734 __link_pointer __r = __n->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001735 base::__unlink_nodes(__n, __n);
1736 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001737#if _LIBCPP_DEBUG_LEVEL >= 2
1738 __c_node* __c = __get_db()->__find_c_and_lock(this);
1739 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1740 {
1741 --__p;
1742 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001743 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001744 {
1745 (*__p)->__c_ = nullptr;
1746 if (--__c->end_ != __p)
1747 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1748 }
1749 }
1750 __get_db()->unlock();
1751#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001752 __node_pointer __np = __n->__as_node();
1753 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1754 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001755#if _LIBCPP_DEBUG_LEVEL >= 2
1756 return iterator(__r, this);
1757#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001758 return iterator(__r);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001759#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001760}
1761
1762template <class _Tp, class _Alloc>
1763typename list<_Tp, _Alloc>::iterator
1764list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1765{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001766#if _LIBCPP_DEBUG_LEVEL >= 2
1767 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1768 "list::erase(iterator, iterator) called with an iterator not"
1769 " referring to this list");
1770#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001771 if (__f != __l)
1772 {
1773 __node_allocator& __na = base::__node_alloc();
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001774 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001775 while (__f != __l)
1776 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00001777 __link_pointer __n = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001778 ++__f;
1779 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001780#if _LIBCPP_DEBUG_LEVEL >= 2
1781 __c_node* __c = __get_db()->__find_c_and_lock(this);
1782 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1783 {
1784 --__p;
1785 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001786 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001787 {
1788 (*__p)->__c_ = nullptr;
1789 if (--__c->end_ != __p)
1790 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1791 }
1792 }
1793 __get_db()->unlock();
1794#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001795 __node_pointer __np = __n->__as_node();
1796 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1797 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001798 }
1799 }
Howard Hinnant920b56c2011-09-27 23:55:03 +00001800#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001801 return iterator(__l.__ptr_, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001802#else
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001803 return iterator(__l.__ptr_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001804#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001805}
1806
1807template <class _Tp, class _Alloc>
1808void
1809list<_Tp, _Alloc>::resize(size_type __n)
1810{
1811 if (__n < base::__sz())
1812 erase(__iterator(__n), end());
1813 else if (__n > base::__sz())
1814 {
1815 __n -= base::__sz();
1816 size_type __ds = 0;
1817 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001818 typedef __allocator_destructor<__node_allocator> _Dp;
1819 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001820 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001821 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001822 ++__ds;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001823#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001824 iterator __r = iterator(__hold.release()->__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001825#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001826 iterator __r = iterator(__hold.release()->__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +00001827#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001828 iterator __e = __r;
1829#ifndef _LIBCPP_NO_EXCEPTIONS
1830 try
1831 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001832#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001833 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1834 {
1835 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001836 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001837 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001838 __hold->__prev_ = __e.__ptr_;
1839 __hold.release();
1840 }
1841#ifndef _LIBCPP_NO_EXCEPTIONS
1842 }
1843 catch (...)
1844 {
1845 while (true)
1846 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001847 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001848 __link_pointer __prev = __e.__ptr_->__prev_;
1849 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001850 if (__prev == 0)
1851 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001852#if _LIBCPP_DEBUG_LEVEL >= 2
1853 __e = iterator(__prev, this);
1854#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001855 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001856#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001857 }
1858 throw;
1859 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001860#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clow28d65da2014-08-05 01:34:12 +00001861 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001862 base::__sz() += __ds;
1863 }
1864}
1865
1866template <class _Tp, class _Alloc>
1867void
1868list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1869{
1870 if (__n < base::__sz())
1871 erase(__iterator(__n), end());
1872 else if (__n > base::__sz())
1873 {
1874 __n -= base::__sz();
1875 size_type __ds = 0;
1876 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001877 typedef __allocator_destructor<__node_allocator> _Dp;
1878 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001879 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001880 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant3e519522010-05-11 19:42:16 +00001881 ++__ds;
Eric Fiselierb88ea352015-12-30 20:57:59 +00001882 __link_pointer __nl = __hold.release()->__as_link();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001883#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001884 iterator __r = iterator(__nl, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001885#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001886 iterator __r = iterator(__nl);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001887#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001888 iterator __e = __r;
1889#ifndef _LIBCPP_NO_EXCEPTIONS
1890 try
1891 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001892#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001893 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1894 {
1895 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001896 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001897 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001898 __hold->__prev_ = __e.__ptr_;
1899 __hold.release();
1900 }
1901#ifndef _LIBCPP_NO_EXCEPTIONS
1902 }
1903 catch (...)
1904 {
1905 while (true)
1906 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001907 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001908 __link_pointer __prev = __e.__ptr_->__prev_;
1909 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001910 if (__prev == 0)
1911 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001912#if _LIBCPP_DEBUG_LEVEL >= 2
1913 __e = iterator(__prev, this);
1914#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001915 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001916#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001917 }
1918 throw;
1919 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001920#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier5243e192016-01-04 03:27:52 +00001921 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001922 base::__sz() += __ds;
Howard Hinnantb3371f62010-08-22 00:02:43 +00001923 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001924}
1925
1926template <class _Tp, class _Alloc>
1927void
1928list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1929{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001930 _LIBCPP_ASSERT(this != &__c,
1931 "list::splice(iterator, list) called with this == &list");
1932#if _LIBCPP_DEBUG_LEVEL >= 2
1933 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1934 "list::splice(iterator, list) called with an iterator not"
1935 " referring to this list");
1936#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001937 if (!__c.empty())
1938 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00001939 __link_pointer __f = __c.__end_.__next_;
1940 __link_pointer __l = __c.__end_.__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001941 base::__unlink_nodes(__f, __l);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001942 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00001943 base::__sz() += __c.__sz();
1944 __c.__sz() = 0;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001945#if _LIBCPP_DEBUG_LEVEL >= 2
1946 __libcpp_db* __db = __get_db();
1947 __c_node* __cn1 = __db->__find_c_and_lock(this);
1948 __c_node* __cn2 = __db->__find_c(&__c);
1949 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1950 {
1951 --__p;
1952 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Eric Fiselier5243e192016-01-04 03:27:52 +00001953 if (__i->__ptr_ != __c.__end_as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +00001954 {
1955 __cn1->__add(*__p);
1956 (*__p)->__c_ = __cn1;
1957 if (--__cn2->end_ != __p)
1958 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1959 }
1960 }
1961 __db->unlock();
1962#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001963 }
1964}
1965
1966template <class _Tp, class _Alloc>
1967void
1968list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1969{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001970#if _LIBCPP_DEBUG_LEVEL >= 2
1971 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1972 "list::splice(iterator, list, iterator) called with first iterator not"
1973 " referring to this list");
1974 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1975 "list::splice(iterator, list, iterator) called with second iterator not"
1976 " referring to list argument");
1977 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
1978 "list::splice(iterator, list, iterator) called with second iterator not"
1979 " derefereceable");
1980#endif
1981 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnant3e519522010-05-11 19:42:16 +00001982 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00001983 __link_pointer __f = __i.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001984 base::__unlink_nodes(__f, __f);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001985 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001986 --__c.__sz();
1987 ++base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001988#if _LIBCPP_DEBUG_LEVEL >= 2
1989 __libcpp_db* __db = __get_db();
1990 __c_node* __cn1 = __db->__find_c_and_lock(this);
1991 __c_node* __cn2 = __db->__find_c(&__c);
1992 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1993 {
1994 --__p;
1995 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001996 if (__j->__ptr_ == __f)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001997 {
1998 __cn1->__add(*__p);
1999 (*__p)->__c_ = __cn1;
2000 if (--__cn2->end_ != __p)
2001 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2002 }
2003 }
2004 __db->unlock();
2005#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002006 }
2007}
2008
2009template <class _Tp, class _Alloc>
2010void
2011list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
2012{
Howard Hinnant920b56c2011-09-27 23:55:03 +00002013#if _LIBCPP_DEBUG_LEVEL >= 2
2014 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2015 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2016 " referring to this list");
2017 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2018 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2019 " referring to list argument");
2020 if (this == &__c)
2021 {
2022 for (const_iterator __i = __f; __i != __l; ++__i)
2023 _LIBCPP_ASSERT(__i != __p,
2024 "list::splice(iterator, list, iterator, iterator)"
2025 " called with the first iterator within the range"
2026 " of the second and third iterators");
2027 }
2028#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002029 if (__f != __l)
2030 {
2031 if (this != &__c)
2032 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002033 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002034 __c.__sz() -= __s;
2035 base::__sz() += __s;
2036 }
Eric Fiselierb88ea352015-12-30 20:57:59 +00002037 __link_pointer __first = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002038 --__l;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002039 __link_pointer __last = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002040 base::__unlink_nodes(__first, __last);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002041 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant920b56c2011-09-27 23:55:03 +00002042#if _LIBCPP_DEBUG_LEVEL >= 2
2043 __libcpp_db* __db = __get_db();
2044 __c_node* __cn1 = __db->__find_c_and_lock(this);
2045 __c_node* __cn2 = __db->__find_c(&__c);
2046 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2047 {
2048 --__p;
2049 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Eric Fiselierb88ea352015-12-30 20:57:59 +00002050 for (__link_pointer __k = __f.__ptr_;
Howard Hinnant920b56c2011-09-27 23:55:03 +00002051 __k != __l.__ptr_; __k = __k->__next_)
2052 {
2053 if (__j->__ptr_ == __k)
2054 {
2055 __cn1->__add(*__p);
2056 (*__p)->__c_ = __cn1;
2057 if (--__cn2->end_ != __p)
2058 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2059 }
2060 }
2061 }
2062 __db->unlock();
2063#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002064 }
2065}
2066
2067template <class _Tp, class _Alloc>
2068void
2069list<_Tp, _Alloc>::remove(const value_type& __x)
2070{
Marshall Clowced70062014-08-08 15:35:52 +00002071 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2072 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnant3e519522010-05-11 19:42:16 +00002073 {
2074 if (*__i == __x)
2075 {
Marshall Clowced70062014-08-08 15:35:52 +00002076 const_iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00002077 for (; __j != __e && *__j == __x; ++__j)
2078 ;
Marshall Clowced70062014-08-08 15:35:52 +00002079 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2080 __i = __j;
Marshall Clow90ba05332014-08-04 17:32:25 +00002081 if (__i != __e)
Marshall Clow28d65da2014-08-05 01:34:12 +00002082 ++__i;
Howard Hinnant3e519522010-05-11 19:42:16 +00002083 }
2084 else
2085 ++__i;
2086 }
2087}
2088
2089template <class _Tp, class _Alloc>
2090template <class _Pred>
2091void
2092list<_Tp, _Alloc>::remove_if(_Pred __pred)
2093{
2094 for (iterator __i = begin(), __e = end(); __i != __e;)
2095 {
2096 if (__pred(*__i))
2097 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002098 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00002099 for (; __j != __e && __pred(*__j); ++__j)
2100 ;
2101 __i = erase(__i, __j);
Marshall Clow90ba05332014-08-04 17:32:25 +00002102 if (__i != __e)
Marshall Clow28d65da2014-08-05 01:34:12 +00002103 ++__i;
Howard Hinnant3e519522010-05-11 19:42:16 +00002104 }
2105 else
2106 ++__i;
2107 }
2108}
2109
2110template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002111inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002112void
2113list<_Tp, _Alloc>::unique()
2114{
2115 unique(__equal_to<value_type>());
2116}
2117
2118template <class _Tp, class _Alloc>
2119template <class _BinaryPred>
2120void
2121list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2122{
2123 for (iterator __i = begin(), __e = end(); __i != __e;)
2124 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002125 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00002126 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2127 ;
2128 if (++__i != __j)
2129 __i = erase(__i, __j);
2130 }
2131}
2132
2133template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002134inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002135void
2136list<_Tp, _Alloc>::merge(list& __c)
2137{
2138 merge(__c, __less<value_type>());
2139}
2140
2141template <class _Tp, class _Alloc>
2142template <class _Comp>
2143void
2144list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2145{
2146 if (this != &__c)
2147 {
2148 iterator __f1 = begin();
2149 iterator __e1 = end();
2150 iterator __f2 = __c.begin();
2151 iterator __e2 = __c.end();
2152 while (__f1 != __e1 && __f2 != __e2)
2153 {
2154 if (__comp(*__f2, *__f1))
2155 {
2156 size_type __ds = 1;
Howard Hinnantce48a112011-06-30 21:18:19 +00002157 iterator __m2 = _VSTD::next(__f2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002158 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2159 ;
2160 base::__sz() += __ds;
2161 __c.__sz() -= __ds;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002162 __link_pointer __f = __f2.__ptr_;
2163 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002164 __f2 = __m2;
2165 base::__unlink_nodes(__f, __l);
Howard Hinnantce48a112011-06-30 21:18:19 +00002166 __m2 = _VSTD::next(__f1);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002167 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002168 __f1 = __m2;
2169 }
2170 else
2171 ++__f1;
2172 }
2173 splice(__e1, __c);
Howard Hinnant920b56c2011-09-27 23:55:03 +00002174#if _LIBCPP_DEBUG_LEVEL >= 2
2175 __libcpp_db* __db = __get_db();
2176 __c_node* __cn1 = __db->__find_c_and_lock(this);
2177 __c_node* __cn2 = __db->__find_c(&__c);
2178 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2179 {
2180 --__p;
2181 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Eric Fiselier5243e192016-01-04 03:27:52 +00002182 if (__i->__ptr_ != __c.__end_as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +00002183 {
2184 __cn1->__add(*__p);
2185 (*__p)->__c_ = __cn1;
2186 if (--__cn2->end_ != __p)
2187 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2188 }
2189 }
2190 __db->unlock();
2191#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002192 }
2193}
2194
2195template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002196inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002197void
2198list<_Tp, _Alloc>::sort()
2199{
2200 sort(__less<value_type>());
2201}
2202
2203template <class _Tp, class _Alloc>
2204template <class _Comp>
Howard Hinnant848a5372010-09-22 16:48:34 +00002205inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002206void
2207list<_Tp, _Alloc>::sort(_Comp __comp)
2208{
2209 __sort(begin(), end(), base::__sz(), __comp);
2210}
2211
2212template <class _Tp, class _Alloc>
2213template <class _Comp>
Howard Hinnant3e519522010-05-11 19:42:16 +00002214typename list<_Tp, _Alloc>::iterator
2215list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2216{
2217 switch (__n)
2218 {
2219 case 0:
2220 case 1:
2221 return __f1;
2222 case 2:
2223 if (__comp(*--__e2, *__f1))
2224 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00002225 __link_pointer __f = __e2.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002226 base::__unlink_nodes(__f, __f);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002227 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnant3e519522010-05-11 19:42:16 +00002228 return __e2;
2229 }
2230 return __f1;
2231 }
2232 size_type __n2 = __n / 2;
Howard Hinnantce48a112011-06-30 21:18:19 +00002233 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002234 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2235 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2236 if (__comp(*__f2, *__f1))
2237 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002238 iterator __m2 = _VSTD::next(__f2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002239 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2240 ;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002241 __link_pointer __f = __f2.__ptr_;
2242 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002243 __r = __f2;
2244 __e1 = __f2 = __m2;
2245 base::__unlink_nodes(__f, __l);
Howard Hinnantce48a112011-06-30 21:18:19 +00002246 __m2 = _VSTD::next(__f1);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002247 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002248 __f1 = __m2;
2249 }
2250 else
2251 ++__f1;
2252 while (__f1 != __e1 && __f2 != __e2)
2253 {
2254 if (__comp(*__f2, *__f1))
2255 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002256 iterator __m2 = _VSTD::next(__f2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002257 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2258 ;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002259 __link_pointer __f = __f2.__ptr_;
2260 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002261 if (__e1 == __f2)
2262 __e1 = __m2;
2263 __f2 = __m2;
2264 base::__unlink_nodes(__f, __l);
Howard Hinnantce48a112011-06-30 21:18:19 +00002265 __m2 = _VSTD::next(__f1);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002266 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002267 __f1 = __m2;
2268 }
2269 else
2270 ++__f1;
2271 }
2272 return __r;
2273}
2274
2275template <class _Tp, class _Alloc>
2276void
Howard Hinnant45900102011-06-03 17:30:28 +00002277list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00002278{
2279 if (base::__sz() > 1)
2280 {
2281 iterator __e = end();
Howard Hinnant920b56c2011-09-27 23:55:03 +00002282 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2283 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002284 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00002285 __i.__ptr_ = __i.__ptr_->__prev_;
2286 }
Howard Hinnantce48a112011-06-30 21:18:19 +00002287 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002288 }
2289}
2290
2291template <class _Tp, class _Alloc>
Howard Hinnant920b56c2011-09-27 23:55:03 +00002292bool
2293list<_Tp, _Alloc>::__invariants() const
2294{
2295 return size() == _VSTD::distance(begin(), end());
2296}
2297
2298#if _LIBCPP_DEBUG_LEVEL >= 2
2299
2300template <class _Tp, class _Alloc>
2301bool
2302list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2303{
Eric Fiselier5243e192016-01-04 03:27:52 +00002304 return __i->__ptr_ != this->__end_as_link();
Howard Hinnant920b56c2011-09-27 23:55:03 +00002305}
2306
2307template <class _Tp, class _Alloc>
2308bool
2309list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2310{
2311 return !empty() && __i->__ptr_ != base::__end_.__next_;
2312}
2313
2314template <class _Tp, class _Alloc>
2315bool
2316list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2317{
2318 return false;
2319}
2320
2321template <class _Tp, class _Alloc>
2322bool
2323list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2324{
2325 return false;
2326}
2327
2328#endif // _LIBCPP_DEBUG_LEVEL >= 2
2329
2330template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002332bool
2333operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2334{
Howard Hinnantce48a112011-06-30 21:18:19 +00002335 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnant3e519522010-05-11 19:42:16 +00002336}
2337
2338template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002340bool
2341operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2342{
Howard Hinnantce48a112011-06-30 21:18:19 +00002343 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnant3e519522010-05-11 19:42:16 +00002344}
2345
2346template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002348bool
2349operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2350{
2351 return !(__x == __y);
2352}
2353
2354template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002356bool
2357operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2358{
2359 return __y < __x;
2360}
2361
2362template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002363inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002364bool
2365operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2366{
2367 return !(__x < __y);
2368}
2369
2370template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002371inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002372bool
2373operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2374{
2375 return !(__y < __x);
2376}
2377
2378template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002379inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002380void
2381swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnant45900102011-06-03 17:30:28 +00002382 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00002383{
2384 __x.swap(__y);
2385}
2386
2387_LIBCPP_END_NAMESPACE_STD
2388
2389#endif // _LIBCPP_LIST