blob: 4bb8339f65c47440796614cf3a677aabed407b68 [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
210};
Howard Hinnant3e519522010-05-11 19:42:16 +0000211
212template <class _Tp, class _VoidPtr>
213struct __list_node_base
214{
Eric Fiselierb88ea352015-12-30 20:57:59 +0000215 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
216 typedef typename _NodeTraits::__node_pointer __node_pointer;
217 typedef typename _NodeTraits::__base_pointer __base_pointer;
218 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000219
Eric Fiselierb88ea352015-12-30 20:57:59 +0000220 __link_pointer __prev_;
221 __link_pointer __next_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000222
Howard Hinnant848a5372010-09-22 16:48:34 +0000223 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000224 __list_node_base() : __prev_(__as_link()), __next_(__as_link()) {}
Marshall Clow28d65da2014-08-05 01:34:12 +0000225
226 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000227 __base_pointer __as_base() {
228 return pointer_traits<__base_pointer>::pointer_to(*this);
229 }
230
231 _LIBCPP_INLINE_VISIBILITY
232 __link_pointer __as_link() {
233 return static_cast<__link_pointer>(static_cast<_VoidPtr>(
234 __as_base()));
235 }
236
237 _LIBCPP_INLINE_VISIBILITY
238 __node_pointer __as_node() {
239 return static_cast<__node_pointer>(__as_base());
Marshall Clow28d65da2014-08-05 01:34:12 +0000240 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000241};
242
243template <class _Tp, class _VoidPtr>
244struct __list_node
245 : public __list_node_base<_Tp, _VoidPtr>
246{
247 _Tp __value_;
248};
249
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000250template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnantce534202011-06-14 19:58:17 +0000251template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnantf0544c22013-08-12 18:38:34 +0000252template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000253
254template <class _Tp, class _VoidPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000255class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000256{
Eric Fiselierb88ea352015-12-30 20:57:59 +0000257 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
258 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000259
Eric Fiselierb88ea352015-12-30 20:57:59 +0000260 __link_pointer __ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000261
Howard Hinnant920b56c2011-09-27 23:55:03 +0000262#if _LIBCPP_DEBUG_LEVEL >= 2
263 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000264 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000265 : __ptr_(__p)
266 {
267 __get_db()->__insert_ic(this, __c);
268 }
269#else
Howard Hinnant848a5372010-09-22 16:48:34 +0000270 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000271 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant920b56c2011-09-27 23:55:03 +0000272#endif
273
274
Howard Hinnant3e519522010-05-11 19:42:16 +0000275
276 template<class, class> friend class list;
277 template<class, class> friend class __list_imp;
278 template<class, class> friend class __list_const_iterator;
279public:
280 typedef bidirectional_iterator_tag iterator_category;
281 typedef _Tp value_type;
282 typedef value_type& reference;
Eric Fiselier1c813402015-08-23 02:56:05 +0000283 typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000284 typedef typename pointer_traits<pointer>::difference_type difference_type;
285
Howard Hinnant848a5372010-09-22 16:48:34 +0000286 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0c37cfd2013-08-05 21:23:28 +0000287 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000288 {
289#if _LIBCPP_DEBUG_LEVEL >= 2
290 __get_db()->__insert_i(this);
291#endif
292 }
293
294#if _LIBCPP_DEBUG_LEVEL >= 2
295
Howard Hinnant27745452011-01-28 23:46:28 +0000296 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000297 __list_iterator(const __list_iterator& __p)
298 : __ptr_(__p.__ptr_)
299 {
300 __get_db()->__iterator_copy(this, &__p);
301 }
302
303 _LIBCPP_INLINE_VISIBILITY
304 ~__list_iterator()
305 {
306 __get_db()->__erase_i(this);
307 }
308
309 _LIBCPP_INLINE_VISIBILITY
310 __list_iterator& operator=(const __list_iterator& __p)
311 {
312 if (this != &__p)
313 {
314 __get_db()->__iterator_copy(this, &__p);
315 __ptr_ = __p.__ptr_;
316 }
317 return *this;
318 }
319
320#endif // _LIBCPP_DEBUG_LEVEL >= 2
321
322 _LIBCPP_INLINE_VISIBILITY
323 reference operator*() const
324 {
325#if _LIBCPP_DEBUG_LEVEL >= 2
326 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
327 "Attempted to dereference a non-dereferenceable list::iterator");
328#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000329 return __ptr_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000330 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000331 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000332 pointer operator->() const
333 {
334#if _LIBCPP_DEBUG_LEVEL >= 2
335 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
336 "Attempted to dereference a non-dereferenceable list::iterator");
337#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000338 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000339 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000340
Howard Hinnant848a5372010-09-22 16:48:34 +0000341 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000342 __list_iterator& operator++()
343 {
344#if _LIBCPP_DEBUG_LEVEL >= 2
345 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
346 "Attempted to increment non-incrementable list::iterator");
347#endif
348 __ptr_ = __ptr_->__next_;
349 return *this;
350 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000351 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000352 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
353
Howard Hinnant848a5372010-09-22 16:48:34 +0000354 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000355 __list_iterator& operator--()
356 {
357#if _LIBCPP_DEBUG_LEVEL >= 2
358 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
359 "Attempted to decrement non-decrementable list::iterator");
360#endif
361 __ptr_ = __ptr_->__prev_;
362 return *this;
363 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000364 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000365 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
366
Howard Hinnant848a5372010-09-22 16:48:34 +0000367 friend _LIBCPP_INLINE_VISIBILITY
368 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000369 {
Howard Hinnant920b56c2011-09-27 23:55:03 +0000370 return __x.__ptr_ == __y.__ptr_;
371 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000372 friend _LIBCPP_INLINE_VISIBILITY
373 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000374 {return !(__x == __y);}
375};
376
377template <class _Tp, class _VoidPtr>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000378class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnant3e519522010-05-11 19:42:16 +0000379{
Eric Fiselierb88ea352015-12-30 20:57:59 +0000380 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
381 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000382
Eric Fiselierb88ea352015-12-30 20:57:59 +0000383 __link_pointer __ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000384
Howard Hinnant920b56c2011-09-27 23:55:03 +0000385#if _LIBCPP_DEBUG_LEVEL >= 2
386 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000387 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000388 : __ptr_(__p)
389 {
390 __get_db()->__insert_ic(this, __c);
391 }
392#else
Howard Hinnant848a5372010-09-22 16:48:34 +0000393 _LIBCPP_INLINE_VISIBILITY
Eric Fiselierb88ea352015-12-30 20:57:59 +0000394 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant920b56c2011-09-27 23:55:03 +0000395#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000396
397 template<class, class> friend class list;
398 template<class, class> friend class __list_imp;
399public:
400 typedef bidirectional_iterator_tag iterator_category;
401 typedef _Tp value_type;
402 typedef const value_type& reference;
Eric Fiselier1c813402015-08-23 02:56:05 +0000403 typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000404 typedef typename pointer_traits<pointer>::difference_type difference_type;
405
Howard Hinnant848a5372010-09-22 16:48:34 +0000406 _LIBCPP_INLINE_VISIBILITY
Marshall Clow0c37cfd2013-08-05 21:23:28 +0000407 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000408 {
409#if _LIBCPP_DEBUG_LEVEL >= 2
410 __get_db()->__insert_i(this);
411#endif
412 }
Howard Hinnant27745452011-01-28 23:46:28 +0000413 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantf7509232013-04-05 17:58:52 +0000414 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000415 : __ptr_(__p.__ptr_)
416 {
417#if _LIBCPP_DEBUG_LEVEL >= 2
418 __get_db()->__iterator_copy(this, &__p);
419#endif
420 }
421
422#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant3e519522010-05-11 19:42:16 +0000423
Howard Hinnant848a5372010-09-22 16:48:34 +0000424 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000425 __list_const_iterator(const __list_const_iterator& __p)
426 : __ptr_(__p.__ptr_)
427 {
428 __get_db()->__iterator_copy(this, &__p);
429 }
430
431 _LIBCPP_INLINE_VISIBILITY
432 ~__list_const_iterator()
433 {
434 __get_db()->__erase_i(this);
435 }
436
437 _LIBCPP_INLINE_VISIBILITY
438 __list_const_iterator& operator=(const __list_const_iterator& __p)
439 {
440 if (this != &__p)
441 {
442 __get_db()->__iterator_copy(this, &__p);
443 __ptr_ = __p.__ptr_;
444 }
445 return *this;
446 }
447
448#endif // _LIBCPP_DEBUG_LEVEL >= 2
449 _LIBCPP_INLINE_VISIBILITY
450 reference operator*() const
451 {
452#if _LIBCPP_DEBUG_LEVEL >= 2
453 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
454 "Attempted to dereference a non-dereferenceable list::const_iterator");
455#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000456 return __ptr_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000457 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000458 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000459 pointer operator->() const
460 {
461#if _LIBCPP_DEBUG_LEVEL >= 2
462 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
463 "Attempted to dereference a non-dereferenceable list::iterator");
464#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +0000465 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000466 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000467
Howard Hinnant848a5372010-09-22 16:48:34 +0000468 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000469 __list_const_iterator& operator++()
470 {
471#if _LIBCPP_DEBUG_LEVEL >= 2
472 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
473 "Attempted to increment non-incrementable list::const_iterator");
474#endif
475 __ptr_ = __ptr_->__next_;
476 return *this;
477 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000478 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000479 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
480
Howard Hinnant848a5372010-09-22 16:48:34 +0000481 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000482 __list_const_iterator& operator--()
483 {
484#if _LIBCPP_DEBUG_LEVEL >= 2
485 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
486 "Attempted to decrement non-decrementable list::const_iterator");
487#endif
488 __ptr_ = __ptr_->__prev_;
489 return *this;
490 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000491 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000492 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
493
Howard Hinnant848a5372010-09-22 16:48:34 +0000494 friend _LIBCPP_INLINE_VISIBILITY
495 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000496 {
Howard Hinnant920b56c2011-09-27 23:55:03 +0000497 return __x.__ptr_ == __y.__ptr_;
498 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000499 friend _LIBCPP_INLINE_VISIBILITY
500 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant3e519522010-05-11 19:42:16 +0000501 {return !(__x == __y);}
502};
503
504template <class _Tp, class _Alloc>
505class __list_imp
506{
507 __list_imp(const __list_imp&);
508 __list_imp& operator=(const __list_imp&);
509protected:
510 typedef _Tp value_type;
511 typedef _Alloc allocator_type;
512 typedef allocator_traits<allocator_type> __alloc_traits;
513 typedef typename __alloc_traits::size_type size_type;
514 typedef typename __alloc_traits::void_pointer __void_pointer;
515 typedef __list_iterator<value_type, __void_pointer> iterator;
516 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
517 typedef __list_node_base<value_type, __void_pointer> __node_base;
518 typedef __list_node<value_type, __void_pointer> __node;
Marshall Clow1f508012015-04-07 05:21:38 +0000519 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000520 typedef allocator_traits<__node_allocator> __node_alloc_traits;
521 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000522 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000523 typedef typename __list_node_pointer_traits<value_type, __void_pointer>::__link_pointer __link_pointer;
524 typedef __link_pointer __link_const_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000525 typedef typename __alloc_traits::pointer pointer;
526 typedef typename __alloc_traits::const_pointer const_pointer;
527 typedef typename __alloc_traits::difference_type difference_type;
528
Marshall Clow1f508012015-04-07 05:21:38 +0000529 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000530 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
531
Howard Hinnant3e519522010-05-11 19:42:16 +0000532 __node_base __end_;
533 __compressed_pair<size_type, __node_allocator> __size_alloc_;
534
Howard Hinnant848a5372010-09-22 16:48:34 +0000535 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000536 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000538 const size_type& __sz() const _NOEXCEPT
539 {return __size_alloc_.first();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000541 __node_allocator& __node_alloc() _NOEXCEPT
542 {return __size_alloc_.second();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000543 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000544 const __node_allocator& __node_alloc() const _NOEXCEPT
545 {return __size_alloc_.second();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000546
Eric Fiselierb88ea352015-12-30 20:57:59 +0000547 static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000548
Howard Hinnant45900102011-06-03 17:30:28 +0000549 __list_imp()
550 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000551 __list_imp(const allocator_type& __a);
552 ~__list_imp();
Howard Hinnant45900102011-06-03 17:30:28 +0000553 void clear() _NOEXCEPT;
Howard Hinnant848a5372010-09-22 16:48:34 +0000554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000555 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnant3e519522010-05-11 19:42:16 +0000556
Howard Hinnant848a5372010-09-22 16:48:34 +0000557 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000558 iterator begin() _NOEXCEPT
559 {
560#if _LIBCPP_DEBUG_LEVEL >= 2
561 return iterator(__end_.__next_, this);
562#else
563 return iterator(__end_.__next_);
564#endif
565 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000567 const_iterator begin() const _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000568 {
569#if _LIBCPP_DEBUG_LEVEL >= 2
570 return const_iterator(__end_.__next_, this);
571#else
572 return const_iterator(__end_.__next_);
573#endif
574 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000576 iterator end() _NOEXCEPT
577 {
578#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +0000579 return iterator(__end_.__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +0000580#else
Eric Fiselierb88ea352015-12-30 20:57:59 +0000581 return iterator(__end_.__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +0000582#endif
583 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000585 const_iterator end() const _NOEXCEPT
Howard Hinnant920b56c2011-09-27 23:55:03 +0000586 {
587#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +0000588 return const_iterator(const_cast<__node_base&>(__end_).__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +0000589#else
Eric Fiselierb88ea352015-12-30 20:57:59 +0000590 return const_iterator(const_cast<__node_base&>(__end_).__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +0000591#endif
592 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000593
Howard Hinnant45900102011-06-03 17:30:28 +0000594 void swap(__list_imp& __c)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000595#if _LIBCPP_STD_VER >= 14
596 _NOEXCEPT;
597#else
598 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
599 __is_nothrow_swappable<allocator_type>::value);
600#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000601
Howard Hinnant848a5372010-09-22 16:48:34 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000603 void __copy_assign_alloc(const __list_imp& __c)
604 {__copy_assign_alloc(__c, integral_constant<bool,
605 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
606
Howard Hinnant848a5372010-09-22 16:48:34 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000608 void __move_assign_alloc(__list_imp& __c)
Howard Hinnant45900102011-06-03 17:30:28 +0000609 _NOEXCEPT_(
610 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
611 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000612 {__move_assign_alloc(__c, integral_constant<bool,
613 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
614
615private:
Howard Hinnant848a5372010-09-22 16:48:34 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000617 void __copy_assign_alloc(const __list_imp& __c, true_type)
618 {
619 if (__node_alloc() != __c.__node_alloc())
620 clear();
621 __node_alloc() = __c.__node_alloc();
622 }
623
Howard Hinnant848a5372010-09-22 16:48:34 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000625 void __copy_assign_alloc(const __list_imp& __c, false_type)
626 {}
627
Howard Hinnant848a5372010-09-22 16:48:34 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86681392011-09-02 20:42:31 +0000629 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnant45900102011-06-03 17:30:28 +0000630 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000631 {
Howard Hinnantce48a112011-06-30 21:18:19 +0000632 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +0000633 }
634
Howard Hinnant848a5372010-09-22 16:48:34 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant86681392011-09-02 20:42:31 +0000636 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnant45900102011-06-03 17:30:28 +0000637 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000638 {}
639};
640
641// Unlink nodes [__f, __l]
642template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +0000643inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000644void
Eric Fiselierb88ea352015-12-30 20:57:59 +0000645__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
Howard Hinnant45900102011-06-03 17:30:28 +0000646 _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000647{
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000648 __f->__prev_->__next_ = __l->__next_;
649 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +0000650}
651
652template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +0000653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000654__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnant45900102011-06-03 17:30:28 +0000655 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +0000656 : __size_alloc_(0)
657{
658}
659
660template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +0000661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000662__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
663 : __size_alloc_(0, __node_allocator(__a))
664{
665}
666
667template <class _Tp, class _Alloc>
668__list_imp<_Tp, _Alloc>::~__list_imp()
669{
670 clear();
Howard Hinnant920b56c2011-09-27 23:55:03 +0000671#if _LIBCPP_DEBUG_LEVEL >= 2
672 __get_db()->__erase_c(this);
673#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000674}
675
676template <class _Tp, class _Alloc>
677void
Howard Hinnant45900102011-06-03 17:30:28 +0000678__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +0000679{
680 if (!empty())
681 {
682 __node_allocator& __na = __node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +0000683 __link_pointer __f = __end_.__next_;
684 __link_pointer __l = __end_.__as_link();
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000685 __unlink_nodes(__f, __l->__prev_);
Howard Hinnant3e519522010-05-11 19:42:16 +0000686 __sz() = 0;
687 while (__f != __l)
688 {
Eric Fiselierb88ea352015-12-30 20:57:59 +0000689 __node_pointer __np = __f->__as_node();
Howard Hinnant920b56c2011-09-27 23:55:03 +0000690 __f = __f->__next_;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000691 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
692 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +0000693 }
Howard Hinnant920b56c2011-09-27 23:55:03 +0000694#if _LIBCPP_DEBUG_LEVEL >= 2
695 __c_node* __c = __get_db()->__find_c_and_lock(this);
696 for (__i_node** __p = __c->end_; __p != __c->beg_; )
697 {
698 --__p;
699 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
700 if (__i->__ptr_ != __l)
701 {
702 (*__p)->__c_ = nullptr;
703 if (--__c->end_ != __p)
704 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
705 }
706 }
707 __get_db()->unlock();
708#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000709 }
710}
711
712template <class _Tp, class _Alloc>
713void
714__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000715#if _LIBCPP_STD_VER >= 14
716 _NOEXCEPT
717#else
718 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
719 __is_nothrow_swappable<allocator_type>::value)
720#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000721{
Howard Hinnant920b56c2011-09-27 23:55:03 +0000722 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
723 this->__node_alloc() == __c.__node_alloc(),
724 "list::swap: Either propagate_on_container_swap must be true"
725 " or the allocators must compare equal");
Howard Hinnantce48a112011-06-30 21:18:19 +0000726 using _VSTD::swap;
Marshall Clowe3fbe142015-07-13 20:04:56 +0000727 __swap_allocator(__node_alloc(), __c.__node_alloc());
Howard Hinnant3e519522010-05-11 19:42:16 +0000728 swap(__sz(), __c.__sz());
729 swap(__end_, __c.__end_);
730 if (__sz() == 0)
Eric Fiselierb88ea352015-12-30 20:57:59 +0000731 __end_.__next_ = __end_.__prev_ = __end_.__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +0000732 else
Eric Fiselierb88ea352015-12-30 20:57:59 +0000733 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +0000734 if (__c.__sz() == 0)
Eric Fiselierb88ea352015-12-30 20:57:59 +0000735 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +0000736 else
Eric Fiselierb88ea352015-12-30 20:57:59 +0000737 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__as_link();
Marshall Clow28d65da2014-08-05 01:34:12 +0000738
Howard Hinnant920b56c2011-09-27 23:55:03 +0000739#if _LIBCPP_DEBUG_LEVEL >= 2
740 __libcpp_db* __db = __get_db();
741 __c_node* __cn1 = __db->__find_c_and_lock(this);
742 __c_node* __cn2 = __db->__find_c(&__c);
743 std::swap(__cn1->beg_, __cn2->beg_);
744 std::swap(__cn1->end_, __cn2->end_);
745 std::swap(__cn1->cap_, __cn2->cap_);
746 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
747 {
748 --__p;
749 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselierb88ea352015-12-30 20:57:59 +0000750 if (__i->__ptr_ == __c.__end_.__as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +0000751 {
752 __cn2->__add(*__p);
753 if (--__cn1->end_ != __p)
754 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
755 }
756 else
757 (*__p)->__c_ = __cn1;
758 }
759 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
760 {
761 --__p;
762 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselierb88ea352015-12-30 20:57:59 +0000763 if (__i->__ptr_ == __end_.__as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +0000764 {
765 __cn1->__add(*__p);
766 if (--__cn2->end_ != __p)
767 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
768 }
769 else
770 (*__p)->__c_ = __cn2;
771 }
772 __db->unlock();
773#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000774}
775
Marshall Clowb5d34aa2015-02-18 17:24:08 +0000776template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnantf0544c22013-08-12 18:38:34 +0000777class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnant3e519522010-05-11 19:42:16 +0000778 : private __list_imp<_Tp, _Alloc>
779{
780 typedef __list_imp<_Tp, _Alloc> base;
781 typedef typename base::__node __node;
782 typedef typename base::__node_allocator __node_allocator;
783 typedef typename base::__node_pointer __node_pointer;
784 typedef typename base::__node_alloc_traits __node_alloc_traits;
Howard Hinnant866d4ef2013-06-25 16:08:47 +0000785 typedef typename base::__node_base __node_base;
786 typedef typename base::__node_base_pointer __node_base_pointer;
Eric Fiselierb88ea352015-12-30 20:57:59 +0000787 typedef typename base::__link_pointer __link_pointer;
Howard Hinnant3e519522010-05-11 19:42:16 +0000788
789public:
790 typedef _Tp value_type;
791 typedef _Alloc allocator_type;
792 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
793 "Invalid allocator::value_type");
794 typedef value_type& reference;
795 typedef const value_type& const_reference;
796 typedef typename base::pointer pointer;
797 typedef typename base::const_pointer const_pointer;
798 typedef typename base::size_type size_type;
799 typedef typename base::difference_type difference_type;
800 typedef typename base::iterator iterator;
801 typedef typename base::const_iterator const_iterator;
Howard Hinnantce48a112011-06-30 21:18:19 +0000802 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
803 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnant3e519522010-05-11 19:42:16 +0000804
Howard Hinnant848a5372010-09-22 16:48:34 +0000805 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000806 list()
807 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000808 {
809#if _LIBCPP_DEBUG_LEVEL >= 2
810 __get_db()->__insert_c(this);
811#endif
812 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000813 _LIBCPP_INLINE_VISIBILITY
Marshall Clowfb829762013-09-08 19:11:51 +0000814 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant920b56c2011-09-27 23:55:03 +0000815 {
816#if _LIBCPP_DEBUG_LEVEL >= 2
817 __get_db()->__insert_c(this);
818#endif
819 }
Marshall Clowfb829762013-09-08 19:11:51 +0000820 explicit list(size_type __n);
821#if _LIBCPP_STD_VER > 11
822 explicit list(size_type __n, const allocator_type& __a);
823#endif
Howard Hinnant3e519522010-05-11 19:42:16 +0000824 list(size_type __n, const value_type& __x);
825 list(size_type __n, const value_type& __x, const allocator_type& __a);
826 template <class _InpIter>
827 list(_InpIter __f, _InpIter __l,
828 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
829 template <class _InpIter>
830 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
831 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
832
833 list(const list& __c);
834 list(const list& __c, const allocator_type& __a);
835 list& operator=(const list& __c);
Howard Hinnant54976f22011-08-12 21:56:02 +0000836#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000837 list(initializer_list<value_type> __il);
838 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnant54976f22011-08-12 21:56:02 +0000839#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000840#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant45900102011-06-03 17:30:28 +0000841 list(list&& __c)
842 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +0000843 list(list&& __c, const allocator_type& __a);
Howard Hinnant45900102011-06-03 17:30:28 +0000844 list& operator=(list&& __c)
845 _NOEXCEPT_(
846 __node_alloc_traits::propagate_on_container_move_assignment::value &&
847 is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000848#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant54976f22011-08-12 21:56:02 +0000849#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant848a5372010-09-22 16:48:34 +0000850 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000851 list& operator=(initializer_list<value_type> __il)
852 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnant54976f22011-08-12 21:56:02 +0000853#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000854
855 template <class _InpIter>
856 void assign(_InpIter __f, _InpIter __l,
857 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
858 void assign(size_type __n, const value_type& __x);
Howard Hinnant54976f22011-08-12 21:56:02 +0000859#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant848a5372010-09-22 16:48:34 +0000860 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000861 void assign(initializer_list<value_type> __il)
862 {assign(__il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000863#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000864
Howard Hinnant45900102011-06-03 17:30:28 +0000865 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +0000866
Howard Hinnant848a5372010-09-22 16:48:34 +0000867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000868 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000870 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000872 size_type max_size() const _NOEXCEPT
873 {return numeric_limits<difference_type>::max();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000874
Howard Hinnant848a5372010-09-22 16:48:34 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000876 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000878 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000880 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000882 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000884 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant848a5372010-09-22 16:48:34 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000886 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000887
Howard Hinnant848a5372010-09-22 16:48:34 +0000888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000889 reverse_iterator rbegin() _NOEXCEPT
890 {return reverse_iterator(end());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000891 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000892 const_reverse_iterator rbegin() const _NOEXCEPT
893 {return const_reverse_iterator(end());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000895 reverse_iterator rend() _NOEXCEPT
896 {return reverse_iterator(begin());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000898 const_reverse_iterator rend() const _NOEXCEPT
899 {return const_reverse_iterator(begin());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000901 const_reverse_iterator crbegin() const _NOEXCEPT
902 {return const_reverse_iterator(end());}
Howard Hinnant848a5372010-09-22 16:48:34 +0000903 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000904 const_reverse_iterator crend() const _NOEXCEPT
905 {return const_reverse_iterator(begin());}
Howard Hinnant3e519522010-05-11 19:42:16 +0000906
Howard Hinnant848a5372010-09-22 16:48:34 +0000907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000908 reference front()
909 {
910 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000911 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000912 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000914 const_reference front() const
915 {
916 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000917 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000918 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000920 reference back()
921 {
922 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000923 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000924 }
Howard Hinnant848a5372010-09-22 16:48:34 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant920b56c2011-09-27 23:55:03 +0000926 const_reference back() const
927 {
928 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselierb88ea352015-12-30 20:57:59 +0000929 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant920b56c2011-09-27 23:55:03 +0000930 }
Howard Hinnant3e519522010-05-11 19:42:16 +0000931
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000932#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000933 void push_front(value_type&& __x);
934 void push_back(value_type&& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000935#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000936 template <class... _Args>
937 void emplace_front(_Args&&... __args);
938 template <class... _Args>
939 void emplace_back(_Args&&... __args);
940 template <class... _Args>
941 iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000942#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnant3e519522010-05-11 19:42:16 +0000943 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000944#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000945
946 void push_front(const value_type& __x);
947 void push_back(const value_type& __x);
948
949 iterator insert(const_iterator __p, const value_type& __x);
950 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
951 template <class _InpIter>
952 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
953 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnant54976f22011-08-12 21:56:02 +0000954#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant848a5372010-09-22 16:48:34 +0000955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000956 iterator insert(const_iterator __p, initializer_list<value_type> __il)
957 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnant54976f22011-08-12 21:56:02 +0000958#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant3e519522010-05-11 19:42:16 +0000959
Howard Hinnant848a5372010-09-22 16:48:34 +0000960 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000961 void swap(list& __c)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000962#if _LIBCPP_STD_VER >= 14
963 _NOEXCEPT
964#else
Howard Hinnant45900102011-06-03 17:30:28 +0000965 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
966 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clowe3fbe142015-07-13 20:04:56 +0000967#endif
Howard Hinnant45900102011-06-03 17:30:28 +0000968 {base::swap(__c);}
Howard Hinnant848a5372010-09-22 16:48:34 +0000969 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant45900102011-06-03 17:30:28 +0000970 void clear() _NOEXCEPT {base::clear();}
Howard Hinnant3e519522010-05-11 19:42:16 +0000971
972 void pop_front();
973 void pop_back();
974
975 iterator erase(const_iterator __p);
976 iterator erase(const_iterator __f, const_iterator __l);
977
978 void resize(size_type __n);
979 void resize(size_type __n, const value_type& __x);
980
981 void splice(const_iterator __p, list& __c);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000982#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +0000983 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000984 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
985#endif
986 void splice(const_iterator __p, list& __c, const_iterator __i);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000987#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +0000988 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000989 void splice(const_iterator __p, list&& __c, const_iterator __i)
990 {splice(__p, __c, __i);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000991#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000992 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000993#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +0000994 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +0000995 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
996 {splice(__p, __c, __f, __l);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +0000997#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +0000998
999 void remove(const value_type& __x);
1000 template <class _Pred> void remove_if(_Pred __pred);
1001 void unique();
1002 template <class _BinaryPred>
1003 void unique(_BinaryPred __binary_pred);
1004 void merge(list& __c);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001005#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant848a5372010-09-22 16:48:34 +00001006 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001007 void merge(list&& __c) {merge(__c);}
1008#endif
1009 template <class _Comp>
1010 void merge(list& __c, _Comp __comp);
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001011#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001012 template <class _Comp>
Howard Hinnant848a5372010-09-22 16:48:34 +00001013 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001014 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001015#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001016 void sort();
1017 template <class _Comp>
1018 void sort(_Comp __comp);
1019
Howard Hinnant45900102011-06-03 17:30:28 +00001020 void reverse() _NOEXCEPT;
Howard Hinnant3e519522010-05-11 19:42:16 +00001021
Howard Hinnant920b56c2011-09-27 23:55:03 +00001022 bool __invariants() const;
1023
1024#if _LIBCPP_DEBUG_LEVEL >= 2
1025
1026 bool __dereferenceable(const const_iterator* __i) const;
1027 bool __decrementable(const const_iterator* __i) const;
1028 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1029 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1030
1031#endif // _LIBCPP_DEBUG_LEVEL >= 2
1032
Howard Hinnant3e519522010-05-11 19:42:16 +00001033private:
Eric Fiselierb88ea352015-12-30 20:57:59 +00001034 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
1035 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
1036 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00001037 iterator __iterator(size_type __n);
1038 template <class _Comp>
1039 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1040
Howard Hinnant45900102011-06-03 17:30:28 +00001041 void __move_assign(list& __c, true_type)
1042 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant3e519522010-05-11 19:42:16 +00001043 void __move_assign(list& __c, false_type);
1044};
1045
1046// Link in nodes [__f, __l] just prior to __p
1047template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001048inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001049void
Eric Fiselierb88ea352015-12-30 20:57:59 +00001050list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
Howard Hinnant3e519522010-05-11 19:42:16 +00001051{
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001052 __p->__prev_->__next_ = __f;
1053 __f->__prev_ = __p->__prev_;
1054 __p->__prev_ = __l;
1055 __l->__next_ = __p;
Howard Hinnant3e519522010-05-11 19:42:16 +00001056}
1057
Marshall Clow28d65da2014-08-05 01:34:12 +00001058// Link in nodes [__f, __l] at the front of the list
1059template <class _Tp, class _Alloc>
1060inline _LIBCPP_INLINE_VISIBILITY
1061void
Eric Fiselierb88ea352015-12-30 20:57:59 +00001062list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
Marshall Clow28d65da2014-08-05 01:34:12 +00001063{
Eric Fiselierb88ea352015-12-30 20:57:59 +00001064 __f->__prev_ = base::__end_.__as_link();
Marshall Clowced70062014-08-08 15:35:52 +00001065 __l->__next_ = base::__end_.__next_;
1066 __l->__next_->__prev_ = __l;
1067 base::__end_.__next_ = __f;
Marshall Clow28d65da2014-08-05 01:34:12 +00001068}
1069
1070// Link in nodes [__f, __l] at the front of the list
1071template <class _Tp, class _Alloc>
1072inline _LIBCPP_INLINE_VISIBILITY
1073void
Eric Fiselierb88ea352015-12-30 20:57:59 +00001074list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
Marshall Clow28d65da2014-08-05 01:34:12 +00001075{
Eric Fiselierb88ea352015-12-30 20:57:59 +00001076 __l->__next_ = base::__end_.__as_link();
Marshall Clowced70062014-08-08 15:35:52 +00001077 __f->__prev_ = base::__end_.__prev_;
1078 __f->__prev_->__next_ = __f;
1079 base::__end_.__prev_ = __l;
Marshall Clow28d65da2014-08-05 01:34:12 +00001080}
1081
1082
Howard Hinnant3e519522010-05-11 19:42:16 +00001083template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001084inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001085typename list<_Tp, _Alloc>::iterator
1086list<_Tp, _Alloc>::__iterator(size_type __n)
1087{
Howard Hinnantce48a112011-06-30 21:18:19 +00001088 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1089 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnant3e519522010-05-11 19:42:16 +00001090}
1091
1092template <class _Tp, class _Alloc>
1093list<_Tp, _Alloc>::list(size_type __n)
1094{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001095#if _LIBCPP_DEBUG_LEVEL >= 2
1096 __get_db()->__insert_c(this);
1097#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001098 for (; __n > 0; --__n)
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001099#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001100 emplace_back();
1101#else
1102 push_back(value_type());
1103#endif
1104}
1105
Marshall Clowfb829762013-09-08 19:11:51 +00001106#if _LIBCPP_STD_VER > 11
1107template <class _Tp, class _Alloc>
1108list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1109{
1110#if _LIBCPP_DEBUG_LEVEL >= 2
1111 __get_db()->__insert_c(this);
1112#endif
1113 for (; __n > 0; --__n)
1114#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1115 emplace_back();
1116#else
1117 push_back(value_type());
1118#endif
1119}
1120#endif
1121
Howard Hinnant3e519522010-05-11 19:42:16 +00001122template <class _Tp, class _Alloc>
1123list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1124{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001125#if _LIBCPP_DEBUG_LEVEL >= 2
1126 __get_db()->__insert_c(this);
1127#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001128 for (; __n > 0; --__n)
1129 push_back(__x);
1130}
1131
1132template <class _Tp, class _Alloc>
1133list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1134 : base(__a)
1135{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001136#if _LIBCPP_DEBUG_LEVEL >= 2
1137 __get_db()->__insert_c(this);
1138#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001139 for (; __n > 0; --__n)
1140 push_back(__x);
1141}
1142
1143template <class _Tp, class _Alloc>
1144template <class _InpIter>
1145list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1146 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1147{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001148#if _LIBCPP_DEBUG_LEVEL >= 2
1149 __get_db()->__insert_c(this);
1150#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001151 for (; __f != __l; ++__f)
1152 push_back(*__f);
1153}
1154
1155template <class _Tp, class _Alloc>
1156template <class _InpIter>
1157list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1158 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1159 : base(__a)
1160{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001161#if _LIBCPP_DEBUG_LEVEL >= 2
1162 __get_db()->__insert_c(this);
1163#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001164 for (; __f != __l; ++__f)
1165 push_back(*__f);
1166}
1167
1168template <class _Tp, class _Alloc>
1169list<_Tp, _Alloc>::list(const list& __c)
1170 : base(allocator_type(
1171 __node_alloc_traits::select_on_container_copy_construction(
1172 __c.__node_alloc())))
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 (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1178 push_back(*__i);
1179}
1180
1181template <class _Tp, class _Alloc>
1182list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1183 : base(__a)
1184{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001185#if _LIBCPP_DEBUG_LEVEL >= 2
1186 __get_db()->__insert_c(this);
1187#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001188 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1189 push_back(*__i);
1190}
1191
Howard Hinnant54976f22011-08-12 21:56:02 +00001192#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1193
Howard Hinnant3e519522010-05-11 19:42:16 +00001194template <class _Tp, class _Alloc>
1195list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1196 : base(__a)
1197{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001198#if _LIBCPP_DEBUG_LEVEL >= 2
1199 __get_db()->__insert_c(this);
1200#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001201 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1202 __e = __il.end(); __i != __e; ++__i)
1203 push_back(*__i);
1204}
1205
1206template <class _Tp, class _Alloc>
1207list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1208{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001209#if _LIBCPP_DEBUG_LEVEL >= 2
1210 __get_db()->__insert_c(this);
1211#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001212 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1213 __e = __il.end(); __i != __e; ++__i)
1214 push_back(*__i);
1215}
1216
Howard Hinnant54976f22011-08-12 21:56:02 +00001217#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1218
Howard Hinnant3e519522010-05-11 19:42:16 +00001219template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001220inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001221list<_Tp, _Alloc>&
1222list<_Tp, _Alloc>::operator=(const list& __c)
1223{
1224 if (this != &__c)
1225 {
1226 base::__copy_assign_alloc(__c);
1227 assign(__c.begin(), __c.end());
1228 }
1229 return *this;
1230}
1231
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001232#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001233
1234template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001235inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001236list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnant45900102011-06-03 17:30:28 +00001237 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnantce48a112011-06-30 21:18:19 +00001238 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnant3e519522010-05-11 19:42:16 +00001239{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001240#if _LIBCPP_DEBUG_LEVEL >= 2
1241 __get_db()->__insert_c(this);
1242#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001243 splice(end(), __c);
1244}
1245
1246template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001247inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001248list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1249 : base(__a)
1250{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001251#if _LIBCPP_DEBUG_LEVEL >= 2
1252 __get_db()->__insert_c(this);
1253#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001254 if (__a == __c.get_allocator())
1255 splice(end(), __c);
1256 else
1257 {
Howard Hinnantc003db12011-11-29 18:15:50 +00001258 typedef move_iterator<iterator> _Ip;
1259 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +00001260 }
1261}
1262
1263template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001264inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001265list<_Tp, _Alloc>&
1266list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnant45900102011-06-03 17:30:28 +00001267 _NOEXCEPT_(
1268 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1269 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001270{
1271 __move_assign(__c, integral_constant<bool,
1272 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1273 return *this;
1274}
1275
1276template <class _Tp, class _Alloc>
1277void
1278list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1279{
1280 if (base::__node_alloc() != __c.__node_alloc())
1281 {
Howard Hinnantc003db12011-11-29 18:15:50 +00001282 typedef move_iterator<iterator> _Ip;
1283 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnant3e519522010-05-11 19:42:16 +00001284 }
1285 else
1286 __move_assign(__c, true_type());
1287}
1288
1289template <class _Tp, class _Alloc>
1290void
1291list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnant45900102011-06-03 17:30:28 +00001292 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnant3e519522010-05-11 19:42:16 +00001293{
1294 clear();
1295 base::__move_assign_alloc(__c);
1296 splice(end(), __c);
1297}
1298
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001299#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001300
1301template <class _Tp, class _Alloc>
1302template <class _InpIter>
1303void
1304list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1305 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1306{
1307 iterator __i = begin();
1308 iterator __e = end();
1309 for (; __f != __l && __i != __e; ++__f, ++__i)
1310 *__i = *__f;
1311 if (__i == __e)
1312 insert(__e, __f, __l);
1313 else
1314 erase(__i, __e);
1315}
1316
1317template <class _Tp, class _Alloc>
1318void
1319list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1320{
1321 iterator __i = begin();
1322 iterator __e = end();
1323 for (; __n > 0 && __i != __e; --__n, ++__i)
1324 *__i = __x;
1325 if (__i == __e)
1326 insert(__e, __n, __x);
1327 else
1328 erase(__i, __e);
1329}
1330
1331template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00001332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00001333_Alloc
Howard Hinnant45900102011-06-03 17:30:28 +00001334list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00001335{
1336 return allocator_type(base::__node_alloc());
1337}
1338
1339template <class _Tp, class _Alloc>
1340typename list<_Tp, _Alloc>::iterator
1341list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1342{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001343#if _LIBCPP_DEBUG_LEVEL >= 2
1344 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1345 "list::insert(iterator, x) called with an iterator not"
1346 " referring to this list");
1347#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001348 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001349 typedef __allocator_destructor<__node_allocator> _Dp;
1350 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001351 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001352 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001353 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001354 ++base::__sz();
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001355#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001356 return iterator(__hold.release()->__as_link(), this);
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001357#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001358 return iterator(__hold.release()->__as_link());
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001359#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001360}
1361
1362template <class _Tp, class _Alloc>
1363typename list<_Tp, _Alloc>::iterator
1364list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1365{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001366#if _LIBCPP_DEBUG_LEVEL >= 2
1367 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1368 "list::insert(iterator, n, x) called with an iterator not"
1369 " referring to this list");
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001370 iterator __r(__p.__ptr_, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001371#else
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001372 iterator __r(__p.__ptr_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001373#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001374 if (__n > 0)
1375 {
1376 size_type __ds = 0;
1377 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001378 typedef __allocator_destructor<__node_allocator> _Dp;
1379 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001380 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001381 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant3e519522010-05-11 19:42:16 +00001382 ++__ds;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001383#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001384 __r = iterator(__hold->__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001385#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001386 __r = iterator(__hold->__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +00001387#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001388 __hold.release();
1389 iterator __e = __r;
1390#ifndef _LIBCPP_NO_EXCEPTIONS
1391 try
1392 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001393#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001394 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1395 {
1396 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001397 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001398 __e.__ptr_->__next_ = __hold->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001399 __hold->__prev_ = __e.__ptr_;
1400 __hold.release();
1401 }
1402#ifndef _LIBCPP_NO_EXCEPTIONS
1403 }
1404 catch (...)
1405 {
1406 while (true)
1407 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001408 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001409 __link_pointer __prev = __e.__ptr_->__prev_;
1410 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001411 if (__prev == 0)
1412 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001413#if _LIBCPP_DEBUG_LEVEL >= 2
1414 __e = iterator(__prev, this);
1415#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001416 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001417#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001418 }
1419 throw;
1420 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001421#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001422 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001423 base::__sz() += __ds;
1424 }
1425 return __r;
1426}
1427
1428template <class _Tp, class _Alloc>
1429template <class _InpIter>
1430typename list<_Tp, _Alloc>::iterator
1431list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1432 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1433{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001434#if _LIBCPP_DEBUG_LEVEL >= 2
1435 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1436 "list::insert(iterator, range) called with an iterator not"
1437 " referring to this list");
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001438 iterator __r(__p.__ptr_, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001439#else
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001440 iterator __r(__p.__ptr_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001441#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001442 if (__f != __l)
1443 {
1444 size_type __ds = 0;
1445 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001446 typedef __allocator_destructor<__node_allocator> _Dp;
1447 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001448 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001449 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001450 ++__ds;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001451#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001452 __r = iterator(__hold.get()->__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001453#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001454 __r = iterator(__hold.get()->__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +00001455#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001456 __hold.release();
1457 iterator __e = __r;
1458#ifndef _LIBCPP_NO_EXCEPTIONS
1459 try
1460 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001461#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier61bff612015-03-19 03:20:02 +00001462 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnant3e519522010-05-11 19:42:16 +00001463 {
1464 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001465 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001466 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001467 __hold->__prev_ = __e.__ptr_;
1468 __hold.release();
1469 }
1470#ifndef _LIBCPP_NO_EXCEPTIONS
1471 }
1472 catch (...)
1473 {
1474 while (true)
1475 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001476 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001477 __link_pointer __prev = __e.__ptr_->__prev_;
1478 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001479 if (__prev == 0)
1480 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001481#if _LIBCPP_DEBUG_LEVEL >= 2
1482 __e = iterator(__prev, this);
1483#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001484 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001485#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001486 }
1487 throw;
1488 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001489#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001490 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001491 base::__sz() += __ds;
1492 }
1493 return __r;
1494}
1495
1496template <class _Tp, class _Alloc>
1497void
1498list<_Tp, _Alloc>::push_front(const value_type& __x)
1499{
1500 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001501 typedef __allocator_destructor<__node_allocator> _Dp;
1502 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001503 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001504 __link_pointer __nl = __hold->__as_link();
1505 __link_nodes_at_front(__nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001506 ++base::__sz();
1507 __hold.release();
1508}
1509
1510template <class _Tp, class _Alloc>
1511void
1512list<_Tp, _Alloc>::push_back(const value_type& __x)
1513{
1514 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001515 typedef __allocator_destructor<__node_allocator> _Dp;
1516 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001517 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001518 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001519 ++base::__sz();
1520 __hold.release();
1521}
1522
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001523#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001524
1525template <class _Tp, class _Alloc>
1526void
1527list<_Tp, _Alloc>::push_front(value_type&& __x)
1528{
1529 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001530 typedef __allocator_destructor<__node_allocator> _Dp;
1531 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001532 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001533 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001534 ++base::__sz();
1535 __hold.release();
1536}
1537
1538template <class _Tp, class _Alloc>
1539void
1540list<_Tp, _Alloc>::push_back(value_type&& __x)
1541{
1542 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001543 typedef __allocator_destructor<__node_allocator> _Dp;
1544 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001545 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001546 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001547 ++base::__sz();
1548 __hold.release();
1549}
1550
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001551#ifndef _LIBCPP_HAS_NO_VARIADICS
1552
Howard Hinnant3e519522010-05-11 19:42:16 +00001553template <class _Tp, class _Alloc>
1554template <class... _Args>
1555void
1556list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1557{
1558 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001559 typedef __allocator_destructor<__node_allocator> _Dp;
1560 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001561 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001562 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnant3e519522010-05-11 19:42:16 +00001563 ++base::__sz();
1564 __hold.release();
1565}
1566
1567template <class _Tp, class _Alloc>
1568template <class... _Args>
1569void
1570list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1571{
1572 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001573 typedef __allocator_destructor<__node_allocator> _Dp;
1574 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001575 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001576 __link_pointer __nl = __hold->__as_link();
1577 __link_nodes_at_back(__nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001578 ++base::__sz();
1579 __hold.release();
1580}
1581
1582template <class _Tp, class _Alloc>
1583template <class... _Args>
1584typename list<_Tp, _Alloc>::iterator
1585list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1586{
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001587#if _LIBCPP_DEBUG_LEVEL >= 2
1588 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1589 "list::emplace(iterator, args...) called with an iterator not"
1590 " referring to this list");
1591#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001592 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001593 typedef __allocator_destructor<__node_allocator> _Dp;
1594 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001595 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001596 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001597 __link_pointer __nl = __hold.get()->__as_link();
1598 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001599 ++base::__sz();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001600 __hold.release();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001601#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001602 return iterator(__nl, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001603#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001604 return iterator(__nl);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001605#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001606}
1607
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001608#endif // _LIBCPP_HAS_NO_VARIADICS
1609
Howard Hinnant3e519522010-05-11 19:42:16 +00001610template <class _Tp, class _Alloc>
1611typename list<_Tp, _Alloc>::iterator
1612list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1613{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001614#if _LIBCPP_DEBUG_LEVEL >= 2
1615 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1616 "list::insert(iterator, x) called with an iterator not"
1617 " referring to this list");
1618#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001619 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001620 typedef __allocator_destructor<__node_allocator> _Dp;
1621 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001622 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001623 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001624 __link_pointer __nl = __hold->__as_link();
1625 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnant3e519522010-05-11 19:42:16 +00001626 ++base::__sz();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001627 __hold.release();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001628#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001629 return iterator(__nl, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001630#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001631 return iterator(__nl);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001632#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001633}
1634
Howard Hinnant7609c9b2010-09-04 23:28:19 +00001635#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant3e519522010-05-11 19:42:16 +00001636
1637template <class _Tp, class _Alloc>
1638void
1639list<_Tp, _Alloc>::pop_front()
1640{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001641 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnant3e519522010-05-11 19:42:16 +00001642 __node_allocator& __na = base::__node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001643 __link_pointer __n = base::__end_.__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001644 base::__unlink_nodes(__n, __n);
1645 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001646#if _LIBCPP_DEBUG_LEVEL >= 2
1647 __c_node* __c = __get_db()->__find_c_and_lock(this);
1648 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1649 {
1650 --__p;
1651 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001652 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001653 {
1654 (*__p)->__c_ = nullptr;
1655 if (--__c->end_ != __p)
1656 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1657 }
1658 }
1659 __get_db()->unlock();
1660#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001661 __node_pointer __np = __n->__as_node();
1662 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1663 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001664}
1665
1666template <class _Tp, class _Alloc>
1667void
1668list<_Tp, _Alloc>::pop_back()
1669{
Dmitri Gribenkoc3f9c802013-06-24 06:15:57 +00001670 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnant3e519522010-05-11 19:42:16 +00001671 __node_allocator& __na = base::__node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001672 __link_pointer __n = base::__end_.__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001673 base::__unlink_nodes(__n, __n);
1674 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001675#if _LIBCPP_DEBUG_LEVEL >= 2
1676 __c_node* __c = __get_db()->__find_c_and_lock(this);
1677 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1678 {
1679 --__p;
1680 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001681 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001682 {
1683 (*__p)->__c_ = nullptr;
1684 if (--__c->end_ != __p)
1685 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1686 }
1687 }
1688 __get_db()->unlock();
1689#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001690 __node_pointer __np = __n->__as_node();
1691 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1692 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001693}
1694
1695template <class _Tp, class _Alloc>
1696typename list<_Tp, _Alloc>::iterator
1697list<_Tp, _Alloc>::erase(const_iterator __p)
1698{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001699#if _LIBCPP_DEBUG_LEVEL >= 2
1700 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1701 "list::erase(iterator) called with an iterator not"
1702 " referring to this list");
1703#endif
Howard Hinnantb0e4c9d2013-04-05 00:18:49 +00001704 _LIBCPP_ASSERT(__p != end(),
1705 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnant3e519522010-05-11 19:42:16 +00001706 __node_allocator& __na = base::__node_alloc();
Eric Fiselierb88ea352015-12-30 20:57:59 +00001707 __link_pointer __n = __p.__ptr_;
1708 __link_pointer __r = __n->__next_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001709 base::__unlink_nodes(__n, __n);
1710 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001711#if _LIBCPP_DEBUG_LEVEL >= 2
1712 __c_node* __c = __get_db()->__find_c_and_lock(this);
1713 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1714 {
1715 --__p;
1716 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001717 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001718 {
1719 (*__p)->__c_ = nullptr;
1720 if (--__c->end_ != __p)
1721 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1722 }
1723 }
1724 __get_db()->unlock();
1725#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001726 __node_pointer __np = __n->__as_node();
1727 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1728 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001729#if _LIBCPP_DEBUG_LEVEL >= 2
1730 return iterator(__r, this);
1731#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001732 return iterator(__r);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001733#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001734}
1735
1736template <class _Tp, class _Alloc>
1737typename list<_Tp, _Alloc>::iterator
1738list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1739{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001740#if _LIBCPP_DEBUG_LEVEL >= 2
1741 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1742 "list::erase(iterator, iterator) called with an iterator not"
1743 " referring to this list");
1744#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001745 if (__f != __l)
1746 {
1747 __node_allocator& __na = base::__node_alloc();
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001748 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001749 while (__f != __l)
1750 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00001751 __link_pointer __n = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001752 ++__f;
1753 --base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001754#if _LIBCPP_DEBUG_LEVEL >= 2
1755 __c_node* __c = __get_db()->__find_c_and_lock(this);
1756 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1757 {
1758 --__p;
1759 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001760 if (__i->__ptr_ == __n)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001761 {
1762 (*__p)->__c_ = nullptr;
1763 if (--__c->end_ != __p)
1764 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1765 }
1766 }
1767 __get_db()->unlock();
1768#endif
Eric Fiselierb88ea352015-12-30 20:57:59 +00001769 __node_pointer __np = __n->__as_node();
1770 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1771 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001772 }
1773 }
Howard Hinnant920b56c2011-09-27 23:55:03 +00001774#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001775 return iterator(__l.__ptr_, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001776#else
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001777 return iterator(__l.__ptr_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001778#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001779}
1780
1781template <class _Tp, class _Alloc>
1782void
1783list<_Tp, _Alloc>::resize(size_type __n)
1784{
1785 if (__n < base::__sz())
1786 erase(__iterator(__n), end());
1787 else if (__n > base::__sz())
1788 {
1789 __n -= base::__sz();
1790 size_type __ds = 0;
1791 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001792 typedef __allocator_destructor<__node_allocator> _Dp;
1793 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001794 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001795 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnant3e519522010-05-11 19:42:16 +00001796 ++__ds;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001797#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001798 iterator __r = iterator(__hold.release()->__as_link(), this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001799#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001800 iterator __r = iterator(__hold.release()->__as_link());
Howard Hinnant920b56c2011-09-27 23:55:03 +00001801#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001802 iterator __e = __r;
1803#ifndef _LIBCPP_NO_EXCEPTIONS
1804 try
1805 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001806#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001807 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1808 {
1809 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001810 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001811 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001812 __hold->__prev_ = __e.__ptr_;
1813 __hold.release();
1814 }
1815#ifndef _LIBCPP_NO_EXCEPTIONS
1816 }
1817 catch (...)
1818 {
1819 while (true)
1820 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001821 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001822 __link_pointer __prev = __e.__ptr_->__prev_;
1823 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001824 if (__prev == 0)
1825 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001826#if _LIBCPP_DEBUG_LEVEL >= 2
1827 __e = iterator(__prev, this);
1828#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001829 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001830#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001831 }
1832 throw;
1833 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001834#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clow28d65da2014-08-05 01:34:12 +00001835 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001836 base::__sz() += __ds;
1837 }
1838}
1839
1840template <class _Tp, class _Alloc>
1841void
1842list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1843{
1844 if (__n < base::__sz())
1845 erase(__iterator(__n), end());
1846 else if (__n > base::__sz())
1847 {
1848 __n -= base::__sz();
1849 size_type __ds = 0;
1850 __node_allocator& __na = base::__node_alloc();
Howard Hinnantc003db12011-11-29 18:15:50 +00001851 typedef __allocator_destructor<__node_allocator> _Dp;
1852 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant3e519522010-05-11 19:42:16 +00001853 __hold->__prev_ = 0;
Howard Hinnantce48a112011-06-30 21:18:19 +00001854 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant3e519522010-05-11 19:42:16 +00001855 ++__ds;
Eric Fiselierb88ea352015-12-30 20:57:59 +00001856 __link_pointer __nl = __hold.release()->__as_link();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001857#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselierb88ea352015-12-30 20:57:59 +00001858 iterator __r = iterator(__nl, this);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001859#else
Eric Fiselierb88ea352015-12-30 20:57:59 +00001860 iterator __r = iterator(__nl);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001861#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001862 iterator __e = __r;
1863#ifndef _LIBCPP_NO_EXCEPTIONS
1864 try
1865 {
Howard Hinnantb3371f62010-08-22 00:02:43 +00001866#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant3e519522010-05-11 19:42:16 +00001867 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1868 {
1869 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnantce48a112011-06-30 21:18:19 +00001870 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001871 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnant3e519522010-05-11 19:42:16 +00001872 __hold->__prev_ = __e.__ptr_;
1873 __hold.release();
1874 }
1875#ifndef _LIBCPP_NO_EXCEPTIONS
1876 }
1877 catch (...)
1878 {
1879 while (true)
1880 {
Howard Hinnantce48a112011-06-30 21:18:19 +00001881 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselierb88ea352015-12-30 20:57:59 +00001882 __link_pointer __prev = __e.__ptr_->__prev_;
1883 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnant3e519522010-05-11 19:42:16 +00001884 if (__prev == 0)
1885 break;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001886#if _LIBCPP_DEBUG_LEVEL >= 2
1887 __e = iterator(__prev, this);
1888#else
Howard Hinnant3e519522010-05-11 19:42:16 +00001889 __e = iterator(__prev);
Howard Hinnant920b56c2011-09-27 23:55:03 +00001890#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001891 }
1892 throw;
1893 }
Howard Hinnantb3371f62010-08-22 00:02:43 +00001894#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselierb88ea352015-12-30 20:57:59 +00001895 __link_nodes(base::__end_.__as_link(), __r.__ptr_, __e.__ptr_);
Howard Hinnant3e519522010-05-11 19:42:16 +00001896 base::__sz() += __ds;
Howard Hinnantb3371f62010-08-22 00:02:43 +00001897 }
Howard Hinnant3e519522010-05-11 19:42:16 +00001898}
1899
1900template <class _Tp, class _Alloc>
1901void
1902list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1903{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001904 _LIBCPP_ASSERT(this != &__c,
1905 "list::splice(iterator, list) called with this == &list");
1906#if _LIBCPP_DEBUG_LEVEL >= 2
1907 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1908 "list::splice(iterator, list) called with an iterator not"
1909 " referring to this list");
1910#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001911 if (!__c.empty())
1912 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00001913 __link_pointer __f = __c.__end_.__next_;
1914 __link_pointer __l = __c.__end_.__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001915 base::__unlink_nodes(__f, __l);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001916 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00001917 base::__sz() += __c.__sz();
1918 __c.__sz() = 0;
Howard Hinnant920b56c2011-09-27 23:55:03 +00001919#if _LIBCPP_DEBUG_LEVEL >= 2
1920 __libcpp_db* __db = __get_db();
1921 __c_node* __cn1 = __db->__find_c_and_lock(this);
1922 __c_node* __cn2 = __db->__find_c(&__c);
1923 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1924 {
1925 --__p;
1926 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Eric Fiselierb88ea352015-12-30 20:57:59 +00001927 if (__i->__ptr_ != __c.__end_.__as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +00001928 {
1929 __cn1->__add(*__p);
1930 (*__p)->__c_ = __cn1;
1931 if (--__cn2->end_ != __p)
1932 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1933 }
1934 }
1935 __db->unlock();
1936#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001937 }
1938}
1939
1940template <class _Tp, class _Alloc>
1941void
1942list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1943{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001944#if _LIBCPP_DEBUG_LEVEL >= 2
1945 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1946 "list::splice(iterator, list, iterator) called with first iterator not"
1947 " referring to this list");
1948 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1949 "list::splice(iterator, list, iterator) called with second iterator not"
1950 " referring to list argument");
1951 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
1952 "list::splice(iterator, list, iterator) called with second iterator not"
1953 " derefereceable");
1954#endif
1955 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnant3e519522010-05-11 19:42:16 +00001956 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00001957 __link_pointer __f = __i.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00001958 base::__unlink_nodes(__f, __f);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001959 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnant3e519522010-05-11 19:42:16 +00001960 --__c.__sz();
1961 ++base::__sz();
Howard Hinnant920b56c2011-09-27 23:55:03 +00001962#if _LIBCPP_DEBUG_LEVEL >= 2
1963 __libcpp_db* __db = __get_db();
1964 __c_node* __cn1 = __db->__find_c_and_lock(this);
1965 __c_node* __cn2 = __db->__find_c(&__c);
1966 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1967 {
1968 --__p;
1969 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00001970 if (__j->__ptr_ == __f)
Howard Hinnant920b56c2011-09-27 23:55:03 +00001971 {
1972 __cn1->__add(*__p);
1973 (*__p)->__c_ = __cn1;
1974 if (--__cn2->end_ != __p)
1975 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1976 }
1977 }
1978 __db->unlock();
1979#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00001980 }
1981}
1982
1983template <class _Tp, class _Alloc>
1984void
1985list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
1986{
Howard Hinnant920b56c2011-09-27 23:55:03 +00001987#if _LIBCPP_DEBUG_LEVEL >= 2
1988 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1989 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
1990 " referring to this list");
1991 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
1992 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
1993 " referring to list argument");
1994 if (this == &__c)
1995 {
1996 for (const_iterator __i = __f; __i != __l; ++__i)
1997 _LIBCPP_ASSERT(__i != __p,
1998 "list::splice(iterator, list, iterator, iterator)"
1999 " called with the first iterator within the range"
2000 " of the second and third iterators");
2001 }
2002#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002003 if (__f != __l)
2004 {
2005 if (this != &__c)
2006 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002007 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002008 __c.__sz() -= __s;
2009 base::__sz() += __s;
2010 }
Eric Fiselierb88ea352015-12-30 20:57:59 +00002011 __link_pointer __first = __f.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002012 --__l;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002013 __link_pointer __last = __l.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002014 base::__unlink_nodes(__first, __last);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002015 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant920b56c2011-09-27 23:55:03 +00002016#if _LIBCPP_DEBUG_LEVEL >= 2
2017 __libcpp_db* __db = __get_db();
2018 __c_node* __cn1 = __db->__find_c_and_lock(this);
2019 __c_node* __cn2 = __db->__find_c(&__c);
2020 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2021 {
2022 --__p;
2023 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Eric Fiselierb88ea352015-12-30 20:57:59 +00002024 for (__link_pointer __k = __f.__ptr_;
Howard Hinnant920b56c2011-09-27 23:55:03 +00002025 __k != __l.__ptr_; __k = __k->__next_)
2026 {
2027 if (__j->__ptr_ == __k)
2028 {
2029 __cn1->__add(*__p);
2030 (*__p)->__c_ = __cn1;
2031 if (--__cn2->end_ != __p)
2032 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2033 }
2034 }
2035 }
2036 __db->unlock();
2037#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002038 }
2039}
2040
2041template <class _Tp, class _Alloc>
2042void
2043list<_Tp, _Alloc>::remove(const value_type& __x)
2044{
Marshall Clowced70062014-08-08 15:35:52 +00002045 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2046 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnant3e519522010-05-11 19:42:16 +00002047 {
2048 if (*__i == __x)
2049 {
Marshall Clowced70062014-08-08 15:35:52 +00002050 const_iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00002051 for (; __j != __e && *__j == __x; ++__j)
2052 ;
Marshall Clowced70062014-08-08 15:35:52 +00002053 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2054 __i = __j;
Marshall Clow90ba05332014-08-04 17:32:25 +00002055 if (__i != __e)
Marshall Clow28d65da2014-08-05 01:34:12 +00002056 ++__i;
Howard Hinnant3e519522010-05-11 19:42:16 +00002057 }
2058 else
2059 ++__i;
2060 }
2061}
2062
2063template <class _Tp, class _Alloc>
2064template <class _Pred>
2065void
2066list<_Tp, _Alloc>::remove_if(_Pred __pred)
2067{
2068 for (iterator __i = begin(), __e = end(); __i != __e;)
2069 {
2070 if (__pred(*__i))
2071 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002072 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00002073 for (; __j != __e && __pred(*__j); ++__j)
2074 ;
2075 __i = erase(__i, __j);
Marshall Clow90ba05332014-08-04 17:32:25 +00002076 if (__i != __e)
Marshall Clow28d65da2014-08-05 01:34:12 +00002077 ++__i;
Howard Hinnant3e519522010-05-11 19:42:16 +00002078 }
2079 else
2080 ++__i;
2081 }
2082}
2083
2084template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002086void
2087list<_Tp, _Alloc>::unique()
2088{
2089 unique(__equal_to<value_type>());
2090}
2091
2092template <class _Tp, class _Alloc>
2093template <class _BinaryPred>
2094void
2095list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2096{
2097 for (iterator __i = begin(), __e = end(); __i != __e;)
2098 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002099 iterator __j = _VSTD::next(__i);
Howard Hinnant3e519522010-05-11 19:42:16 +00002100 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2101 ;
2102 if (++__i != __j)
2103 __i = erase(__i, __j);
2104 }
2105}
2106
2107template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002109void
2110list<_Tp, _Alloc>::merge(list& __c)
2111{
2112 merge(__c, __less<value_type>());
2113}
2114
2115template <class _Tp, class _Alloc>
2116template <class _Comp>
2117void
2118list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2119{
2120 if (this != &__c)
2121 {
2122 iterator __f1 = begin();
2123 iterator __e1 = end();
2124 iterator __f2 = __c.begin();
2125 iterator __e2 = __c.end();
2126 while (__f1 != __e1 && __f2 != __e2)
2127 {
2128 if (__comp(*__f2, *__f1))
2129 {
2130 size_type __ds = 1;
Howard Hinnantce48a112011-06-30 21:18:19 +00002131 iterator __m2 = _VSTD::next(__f2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002132 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2133 ;
2134 base::__sz() += __ds;
2135 __c.__sz() -= __ds;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002136 __link_pointer __f = __f2.__ptr_;
2137 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002138 __f2 = __m2;
2139 base::__unlink_nodes(__f, __l);
Howard Hinnantce48a112011-06-30 21:18:19 +00002140 __m2 = _VSTD::next(__f1);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002141 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002142 __f1 = __m2;
2143 }
2144 else
2145 ++__f1;
2146 }
2147 splice(__e1, __c);
Howard Hinnant920b56c2011-09-27 23:55:03 +00002148#if _LIBCPP_DEBUG_LEVEL >= 2
2149 __libcpp_db* __db = __get_db();
2150 __c_node* __cn1 = __db->__find_c_and_lock(this);
2151 __c_node* __cn2 = __db->__find_c(&__c);
2152 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2153 {
2154 --__p;
2155 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Eric Fiselierb88ea352015-12-30 20:57:59 +00002156 if (__i->__ptr_ != __c.__end_.__as_link())
Howard Hinnant920b56c2011-09-27 23:55:03 +00002157 {
2158 __cn1->__add(*__p);
2159 (*__p)->__c_ = __cn1;
2160 if (--__cn2->end_ != __p)
2161 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2162 }
2163 }
2164 __db->unlock();
2165#endif
Howard Hinnant3e519522010-05-11 19:42:16 +00002166 }
2167}
2168
2169template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002170inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002171void
2172list<_Tp, _Alloc>::sort()
2173{
2174 sort(__less<value_type>());
2175}
2176
2177template <class _Tp, class _Alloc>
2178template <class _Comp>
Howard Hinnant848a5372010-09-22 16:48:34 +00002179inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002180void
2181list<_Tp, _Alloc>::sort(_Comp __comp)
2182{
2183 __sort(begin(), end(), base::__sz(), __comp);
2184}
2185
2186template <class _Tp, class _Alloc>
2187template <class _Comp>
Howard Hinnant3e519522010-05-11 19:42:16 +00002188typename list<_Tp, _Alloc>::iterator
2189list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2190{
2191 switch (__n)
2192 {
2193 case 0:
2194 case 1:
2195 return __f1;
2196 case 2:
2197 if (__comp(*--__e2, *__f1))
2198 {
Eric Fiselierb88ea352015-12-30 20:57:59 +00002199 __link_pointer __f = __e2.__ptr_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002200 base::__unlink_nodes(__f, __f);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002201 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnant3e519522010-05-11 19:42:16 +00002202 return __e2;
2203 }
2204 return __f1;
2205 }
2206 size_type __n2 = __n / 2;
Howard Hinnantce48a112011-06-30 21:18:19 +00002207 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002208 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2209 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2210 if (__comp(*__f2, *__f1))
2211 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002212 iterator __m2 = _VSTD::next(__f2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002213 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2214 ;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002215 __link_pointer __f = __f2.__ptr_;
2216 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002217 __r = __f2;
2218 __e1 = __f2 = __m2;
2219 base::__unlink_nodes(__f, __l);
Howard Hinnantce48a112011-06-30 21:18:19 +00002220 __m2 = _VSTD::next(__f1);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002221 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002222 __f1 = __m2;
2223 }
2224 else
2225 ++__f1;
2226 while (__f1 != __e1 && __f2 != __e2)
2227 {
2228 if (__comp(*__f2, *__f1))
2229 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002230 iterator __m2 = _VSTD::next(__f2);
Howard Hinnant3e519522010-05-11 19:42:16 +00002231 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2232 ;
Eric Fiselierb88ea352015-12-30 20:57:59 +00002233 __link_pointer __f = __f2.__ptr_;
2234 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnant3e519522010-05-11 19:42:16 +00002235 if (__e1 == __f2)
2236 __e1 = __m2;
2237 __f2 = __m2;
2238 base::__unlink_nodes(__f, __l);
Howard Hinnantce48a112011-06-30 21:18:19 +00002239 __m2 = _VSTD::next(__f1);
Howard Hinnant866d4ef2013-06-25 16:08:47 +00002240 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnant3e519522010-05-11 19:42:16 +00002241 __f1 = __m2;
2242 }
2243 else
2244 ++__f1;
2245 }
2246 return __r;
2247}
2248
2249template <class _Tp, class _Alloc>
2250void
Howard Hinnant45900102011-06-03 17:30:28 +00002251list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnant3e519522010-05-11 19:42:16 +00002252{
2253 if (base::__sz() > 1)
2254 {
2255 iterator __e = end();
Howard Hinnant920b56c2011-09-27 23:55:03 +00002256 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2257 {
Howard Hinnantce48a112011-06-30 21:18:19 +00002258 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant920b56c2011-09-27 23:55:03 +00002259 __i.__ptr_ = __i.__ptr_->__prev_;
2260 }
Howard Hinnantce48a112011-06-30 21:18:19 +00002261 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnant3e519522010-05-11 19:42:16 +00002262 }
2263}
2264
2265template <class _Tp, class _Alloc>
Howard Hinnant920b56c2011-09-27 23:55:03 +00002266bool
2267list<_Tp, _Alloc>::__invariants() const
2268{
2269 return size() == _VSTD::distance(begin(), end());
2270}
2271
2272#if _LIBCPP_DEBUG_LEVEL >= 2
2273
2274template <class _Tp, class _Alloc>
2275bool
2276list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2277{
Eric Fiselierb88ea352015-12-30 20:57:59 +00002278 return __i->__ptr_ != const_cast<__node_base&>(this->__end_).__as_link();
Howard Hinnant920b56c2011-09-27 23:55:03 +00002279}
2280
2281template <class _Tp, class _Alloc>
2282bool
2283list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2284{
2285 return !empty() && __i->__ptr_ != base::__end_.__next_;
2286}
2287
2288template <class _Tp, class _Alloc>
2289bool
2290list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2291{
2292 return false;
2293}
2294
2295template <class _Tp, class _Alloc>
2296bool
2297list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2298{
2299 return false;
2300}
2301
2302#endif // _LIBCPP_DEBUG_LEVEL >= 2
2303
2304template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002305inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002306bool
2307operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2308{
Howard Hinnantce48a112011-06-30 21:18:19 +00002309 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnant3e519522010-05-11 19:42:16 +00002310}
2311
2312template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002313inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002314bool
2315operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2316{
Howard Hinnantce48a112011-06-30 21:18:19 +00002317 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnant3e519522010-05-11 19:42:16 +00002318}
2319
2320template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002321inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002322bool
2323operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2324{
2325 return !(__x == __y);
2326}
2327
2328template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002329inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002330bool
2331operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2332{
2333 return __y < __x;
2334}
2335
2336template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002337inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002338bool
2339operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2340{
2341 return !(__x < __y);
2342}
2343
2344template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002345inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002346bool
2347operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2348{
2349 return !(__y < __x);
2350}
2351
2352template <class _Tp, class _Alloc>
Howard Hinnant848a5372010-09-22 16:48:34 +00002353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnant3e519522010-05-11 19:42:16 +00002354void
2355swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnant45900102011-06-03 17:30:28 +00002356 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnant3e519522010-05-11 19:42:16 +00002357{
2358 __x.swap(__y);
2359}
2360
2361_LIBCPP_END_NAMESPACE_STD
2362
2363#endif // _LIBCPP_LIST