blob: 13e1199df5ea41b2e40c6917683e7ab12422899d [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- list ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-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 Hinnantbc8d3f92010-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 Hinnantc5607272011-06-03 17:30:28 +000039 list()
40 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041 explicit list(const allocator_type& a);
42 explicit list(size_type n);
Marshall Clowe00f53b2013-09-09 18:19:45 +000043 explicit list(size_type n, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-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 Hinnantc5607272011-06-03 17:30:28 +000052 list(list&& x)
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-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 Hinnantc5607272011-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 Hinnantbc8d3f92010-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 Hinnantc5607272011-06-03 17:30:28 +000071 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072
Howard Hinnantc5607272011-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 Hinnantbc8d3f92010-05-11 19:42:16 +000085
86 reference front();
87 const_reference front() const;
88 reference back();
89 const_reference back() const;
90
Howard Hinnantc5607272011-06-03 17:30:28 +000091 bool empty() const noexcept;
92 size_type size() const noexcept;
93 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-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 Hinnantc5607272011-06-03 17:30:28 +0000120 void swap(list&)
121 noexcept(!allocator_type::propagate_on_container_swap::value ||
122 __is_nothrow_swappable<allocator_type>::value);
123 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000124
125 void splice(const_iterator position, list& x);
126 void splice(const_iterator position, list&& x);
127 void splice(const_iterator position, list& x, const_iterator i);
128 void splice(const_iterator position, list&& x, const_iterator i);
129 void splice(const_iterator position, list& x, const_iterator first,
130 const_iterator last);
131 void splice(const_iterator position, list&& x, const_iterator first,
132 const_iterator last);
133
134 void remove(const value_type& value);
135 template <class Pred> void remove_if(Pred pred);
136 void unique();
137 template <class BinaryPredicate>
138 void unique(BinaryPredicate binary_pred);
139 void merge(list& x);
140 void merge(list&& x);
141 template <class Compare>
142 void merge(list& x, Compare comp);
143 template <class Compare>
144 void merge(list&& x, Compare comp);
145 void sort();
146 template <class Compare>
147 void sort(Compare comp);
Howard Hinnantc5607272011-06-03 17:30:28 +0000148 void reverse() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000149};
150
151template <class T, class Alloc>
152 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
153template <class T, class Alloc>
154 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
155template <class T, class Alloc>
156 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
157template <class T, class Alloc>
158 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
159template <class T, class Alloc>
160 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
161template <class T, class Alloc>
162 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
163
164template <class T, class Alloc>
Howard Hinnantc5607272011-06-03 17:30:28 +0000165 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
166 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000167
168} // std
169
170*/
171
172#include <__config>
173
174#include <memory>
175#include <limits>
176#include <initializer_list>
177#include <iterator>
178#include <algorithm>
179
Howard Hinnant66c6f972011-11-29 16:45:27 +0000180#include <__undef_min_max>
181
Eric Fiselierb9536102014-08-10 23:53:08 +0000182#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000183
Howard Hinnant08e17472011-10-17 20:05:10 +0000184#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000185#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000187
188_LIBCPP_BEGIN_NAMESPACE_STD
189
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000190template <class _Tp, class _VoidPtr> struct __list_node;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000191
192template <class _Tp, class _VoidPtr>
193struct __list_node_base
194{
195 typedef typename pointer_traits<_VoidPtr>::template
196#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
197 rebind<__list_node<_Tp, _VoidPtr> > pointer;
198#else
199 rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
200#endif
201
Howard Hinnant29f74322013-06-25 16:08:47 +0000202 typedef typename pointer_traits<_VoidPtr>::template
203#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
204 rebind<__list_node_base> __base_pointer;
205#else
206 rebind<__list_node_base>::other __base_pointer;
207#endif
208
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000209 pointer __prev_;
210 pointer __next_;
211
Howard Hinnant82894812010-09-22 16:48:34 +0000212 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea8ed832014-08-05 01:34:12 +0000213 __list_node_base() : __prev_(__self()), __next_(__self()) {}
214
215 _LIBCPP_INLINE_VISIBILITY
216 pointer __self()
217 {
Marshall Clowfca038e2014-08-08 15:35:52 +0000218 return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
Marshall Clowea8ed832014-08-05 01:34:12 +0000219 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000220};
221
222template <class _Tp, class _VoidPtr>
223struct __list_node
224 : public __list_node_base<_Tp, _VoidPtr>
225{
226 _Tp __value_;
227};
228
Marshall Clowceead9c2015-02-18 17:24:08 +0000229template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000230template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000231template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000232
233template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000234class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000235{
236 typedef typename pointer_traits<_VoidPtr>::template
237#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
238 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
239#else
240 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
241#endif
242
243 __node_pointer __ptr_;
244
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000245#if _LIBCPP_DEBUG_LEVEL >= 2
246 _LIBCPP_INLINE_VISIBILITY
247 explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
248 : __ptr_(__p)
249 {
250 __get_db()->__insert_ic(this, __c);
251 }
252#else
Howard Hinnant82894812010-09-22 16:48:34 +0000253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000254 explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000255#endif
256
257
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000258
259 template<class, class> friend class list;
260 template<class, class> friend class __list_imp;
261 template<class, class> friend class __list_const_iterator;
262public:
263 typedef bidirectional_iterator_tag iterator_category;
264 typedef _Tp value_type;
265 typedef value_type& reference;
266 typedef typename pointer_traits<_VoidPtr>::template
267#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
268 rebind<value_type>
269#else
270 rebind<value_type>::other
271#endif
272 pointer;
273 typedef typename pointer_traits<pointer>::difference_type difference_type;
274
Howard Hinnant82894812010-09-22 16:48:34 +0000275 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28 +0000276 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000277 {
278#if _LIBCPP_DEBUG_LEVEL >= 2
279 __get_db()->__insert_i(this);
280#endif
281 }
282
283#if _LIBCPP_DEBUG_LEVEL >= 2
284
Howard Hinnant211f0ee2011-01-28 23:46:28 +0000285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000286 __list_iterator(const __list_iterator& __p)
287 : __ptr_(__p.__ptr_)
288 {
289 __get_db()->__iterator_copy(this, &__p);
290 }
291
292 _LIBCPP_INLINE_VISIBILITY
293 ~__list_iterator()
294 {
295 __get_db()->__erase_i(this);
296 }
297
298 _LIBCPP_INLINE_VISIBILITY
299 __list_iterator& operator=(const __list_iterator& __p)
300 {
301 if (this != &__p)
302 {
303 __get_db()->__iterator_copy(this, &__p);
304 __ptr_ = __p.__ptr_;
305 }
306 return *this;
307 }
308
309#endif // _LIBCPP_DEBUG_LEVEL >= 2
310
311 _LIBCPP_INLINE_VISIBILITY
312 reference operator*() const
313 {
314#if _LIBCPP_DEBUG_LEVEL >= 2
315 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
316 "Attempted to dereference a non-dereferenceable list::iterator");
317#endif
318 return __ptr_->__value_;
319 }
Howard Hinnant82894812010-09-22 16:48:34 +0000320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47 +0000321 pointer operator->() const
322 {
323#if _LIBCPP_DEBUG_LEVEL >= 2
324 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
325 "Attempted to dereference a non-dereferenceable list::iterator");
326#endif
327 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
328 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000329
Howard Hinnant82894812010-09-22 16:48:34 +0000330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000331 __list_iterator& operator++()
332 {
333#if _LIBCPP_DEBUG_LEVEL >= 2
334 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
335 "Attempted to increment non-incrementable list::iterator");
336#endif
337 __ptr_ = __ptr_->__next_;
338 return *this;
339 }
Howard Hinnant82894812010-09-22 16:48:34 +0000340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000341 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
342
Howard Hinnant82894812010-09-22 16:48:34 +0000343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000344 __list_iterator& operator--()
345 {
346#if _LIBCPP_DEBUG_LEVEL >= 2
347 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
348 "Attempted to decrement non-decrementable list::iterator");
349#endif
350 __ptr_ = __ptr_->__prev_;
351 return *this;
352 }
Howard Hinnant82894812010-09-22 16:48:34 +0000353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000354 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
355
Howard Hinnant82894812010-09-22 16:48:34 +0000356 friend _LIBCPP_INLINE_VISIBILITY
357 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000358 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000359 return __x.__ptr_ == __y.__ptr_;
360 }
Howard Hinnant82894812010-09-22 16:48:34 +0000361 friend _LIBCPP_INLINE_VISIBILITY
362 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000363 {return !(__x == __y);}
364};
365
366template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000367class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000368{
369 typedef typename pointer_traits<_VoidPtr>::template
370#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant29f74322013-06-25 16:08:47 +0000371 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000372#else
Howard Hinnant29f74322013-06-25 16:08:47 +0000373 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374#endif
375
376 __node_pointer __ptr_;
377
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000378#if _LIBCPP_DEBUG_LEVEL >= 2
379 _LIBCPP_INLINE_VISIBILITY
380 explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
381 : __ptr_(__p)
382 {
383 __get_db()->__insert_ic(this, __c);
384 }
385#else
Howard Hinnant82894812010-09-22 16:48:34 +0000386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000387 explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000388#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000389
390 template<class, class> friend class list;
391 template<class, class> friend class __list_imp;
392public:
393 typedef bidirectional_iterator_tag iterator_category;
394 typedef _Tp value_type;
395 typedef const value_type& reference;
396 typedef typename pointer_traits<_VoidPtr>::template
397#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
398 rebind<const value_type>
399#else
400 rebind<const value_type>::other
401#endif
402 pointer;
403 typedef typename pointer_traits<pointer>::difference_type difference_type;
404
Howard Hinnant82894812010-09-22 16:48:34 +0000405 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28 +0000406 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000407 {
408#if _LIBCPP_DEBUG_LEVEL >= 2
409 __get_db()->__insert_i(this);
410#endif
411 }
Howard Hinnant211f0ee2011-01-28 23:46:28 +0000412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6dcaf3e2013-04-05 17:58:52 +0000413 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000414 : __ptr_(__p.__ptr_)
415 {
416#if _LIBCPP_DEBUG_LEVEL >= 2
417 __get_db()->__iterator_copy(this, &__p);
418#endif
419 }
420
421#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000422
Howard Hinnant82894812010-09-22 16:48:34 +0000423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000424 __list_const_iterator(const __list_const_iterator& __p)
425 : __ptr_(__p.__ptr_)
426 {
427 __get_db()->__iterator_copy(this, &__p);
428 }
429
430 _LIBCPP_INLINE_VISIBILITY
431 ~__list_const_iterator()
432 {
433 __get_db()->__erase_i(this);
434 }
435
436 _LIBCPP_INLINE_VISIBILITY
437 __list_const_iterator& operator=(const __list_const_iterator& __p)
438 {
439 if (this != &__p)
440 {
441 __get_db()->__iterator_copy(this, &__p);
442 __ptr_ = __p.__ptr_;
443 }
444 return *this;
445 }
446
447#endif // _LIBCPP_DEBUG_LEVEL >= 2
448 _LIBCPP_INLINE_VISIBILITY
449 reference operator*() const
450 {
451#if _LIBCPP_DEBUG_LEVEL >= 2
452 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
453 "Attempted to dereference a non-dereferenceable list::const_iterator");
454#endif
455 return __ptr_->__value_;
456 }
Howard Hinnant82894812010-09-22 16:48:34 +0000457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47 +0000458 pointer operator->() const
459 {
460#if _LIBCPP_DEBUG_LEVEL >= 2
461 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
462 "Attempted to dereference a non-dereferenceable list::iterator");
463#endif
464 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
465 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000466
Howard Hinnant82894812010-09-22 16:48:34 +0000467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000468 __list_const_iterator& operator++()
469 {
470#if _LIBCPP_DEBUG_LEVEL >= 2
471 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
472 "Attempted to increment non-incrementable list::const_iterator");
473#endif
474 __ptr_ = __ptr_->__next_;
475 return *this;
476 }
Howard Hinnant82894812010-09-22 16:48:34 +0000477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000478 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
479
Howard Hinnant82894812010-09-22 16:48:34 +0000480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000481 __list_const_iterator& operator--()
482 {
483#if _LIBCPP_DEBUG_LEVEL >= 2
484 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
485 "Attempted to decrement non-decrementable list::const_iterator");
486#endif
487 __ptr_ = __ptr_->__prev_;
488 return *this;
489 }
Howard Hinnant82894812010-09-22 16:48:34 +0000490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000491 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
492
Howard Hinnant82894812010-09-22 16:48:34 +0000493 friend _LIBCPP_INLINE_VISIBILITY
494 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000495 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000496 return __x.__ptr_ == __y.__ptr_;
497 }
Howard Hinnant82894812010-09-22 16:48:34 +0000498 friend _LIBCPP_INLINE_VISIBILITY
499 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000500 {return !(__x == __y);}
501};
502
503template <class _Tp, class _Alloc>
504class __list_imp
505{
506 __list_imp(const __list_imp&);
507 __list_imp& operator=(const __list_imp&);
508protected:
509 typedef _Tp value_type;
510 typedef _Alloc allocator_type;
511 typedef allocator_traits<allocator_type> __alloc_traits;
512 typedef typename __alloc_traits::size_type size_type;
513 typedef typename __alloc_traits::void_pointer __void_pointer;
514 typedef __list_iterator<value_type, __void_pointer> iterator;
515 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
516 typedef __list_node_base<value_type, __void_pointer> __node_base;
517 typedef __list_node<value_type, __void_pointer> __node;
518 typedef typename __alloc_traits::template
519#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
520 rebind_alloc<__node>
521#else
522 rebind_alloc<__node>::other
523#endif
524 __node_allocator;
525 typedef allocator_traits<__node_allocator> __node_alloc_traits;
526 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant29f74322013-06-25 16:08:47 +0000527 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 typedef typename __alloc_traits::pointer pointer;
529 typedef typename __alloc_traits::const_pointer const_pointer;
530 typedef typename __alloc_traits::difference_type difference_type;
531
Howard Hinnant29f74322013-06-25 16:08:47 +0000532 typedef typename __alloc_traits::template
533#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
534 rebind_alloc<__node_base>
535#else
536 rebind_alloc<__node_base>::other
537#endif
538 __node_base_allocator;
539 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
540
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000541 __node_base __end_;
542 __compressed_pair<size_type, __node_allocator> __size_alloc_;
543
Howard Hinnant82894812010-09-22 16:48:34 +0000544 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000545 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34 +0000546 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000547 const size_type& __sz() const _NOEXCEPT
548 {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34 +0000549 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000550 __node_allocator& __node_alloc() _NOEXCEPT
551 {return __size_alloc_.second();}
Howard Hinnant82894812010-09-22 16:48:34 +0000552 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000553 const __node_allocator& __node_alloc() const _NOEXCEPT
554 {return __size_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000555
Howard Hinnant29f74322013-06-25 16:08:47 +0000556 static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000557
Howard Hinnantc5607272011-06-03 17:30:28 +0000558 __list_imp()
559 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000560 __list_imp(const allocator_type& __a);
561 ~__list_imp();
Howard Hinnantc5607272011-06-03 17:30:28 +0000562 void clear() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +0000563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000564 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000565
Howard Hinnant82894812010-09-22 16:48:34 +0000566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000567 iterator begin() _NOEXCEPT
568 {
569#if _LIBCPP_DEBUG_LEVEL >= 2
570 return iterator(__end_.__next_, this);
571#else
572 return iterator(__end_.__next_);
573#endif
574 }
Howard Hinnant82894812010-09-22 16:48:34 +0000575 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000576 const_iterator begin() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000577 {
578#if _LIBCPP_DEBUG_LEVEL >= 2
579 return const_iterator(__end_.__next_, this);
580#else
581 return const_iterator(__end_.__next_);
582#endif
583 }
Howard Hinnant82894812010-09-22 16:48:34 +0000584 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000585 iterator end() _NOEXCEPT
586 {
587#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47 +0000588 return iterator(static_cast<__node_pointer>(
589 pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000590#else
Howard Hinnant29f74322013-06-25 16:08:47 +0000591 return iterator(static_cast<__node_pointer>(
592 pointer_traits<__node_base_pointer>::pointer_to(__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000593#endif
594 }
Howard Hinnant82894812010-09-22 16:48:34 +0000595 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000596 const_iterator end() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000597 {
598#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47 +0000599 return const_iterator(static_cast<__node_const_pointer>(
600 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000601#else
Howard Hinnant29f74322013-06-25 16:08:47 +0000602 return const_iterator(static_cast<__node_const_pointer>(
603 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000604#endif
605 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000606
Howard Hinnantc5607272011-06-03 17:30:28 +0000607 void swap(__list_imp& __c)
608 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
609 __is_nothrow_swappable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000610
Howard Hinnant82894812010-09-22 16:48:34 +0000611 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612 void __copy_assign_alloc(const __list_imp& __c)
613 {__copy_assign_alloc(__c, integral_constant<bool,
614 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
615
Howard Hinnant82894812010-09-22 16:48:34 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 void __move_assign_alloc(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +0000618 _NOEXCEPT_(
619 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
620 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000621 {__move_assign_alloc(__c, integral_constant<bool,
622 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
623
624private:
Howard Hinnant82894812010-09-22 16:48:34 +0000625 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000626 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
Howard Hinnantc5607272011-06-03 17:30:28 +0000627 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
628 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000629 {__swap_alloc(__x, __y, integral_constant<bool,
630 __node_alloc_traits::propagate_on_container_swap::value>());}
Howard Hinnant82894812010-09-22 16:48:34 +0000631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000632 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
Howard Hinnantc5607272011-06-03 17:30:28 +0000633 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000634 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000635 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000636 swap(__x, __y);
637 }
Howard Hinnant82894812010-09-22 16:48:34 +0000638 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000639 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
Howard Hinnantc5607272011-06-03 17:30:28 +0000640 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000641 {}
642
Howard Hinnant82894812010-09-22 16:48:34 +0000643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644 void __copy_assign_alloc(const __list_imp& __c, true_type)
645 {
646 if (__node_alloc() != __c.__node_alloc())
647 clear();
648 __node_alloc() = __c.__node_alloc();
649 }
650
Howard Hinnant82894812010-09-22 16:48:34 +0000651 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000652 void __copy_assign_alloc(const __list_imp& __c, false_type)
653 {}
654
Howard Hinnant82894812010-09-22 16:48:34 +0000655 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000656 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:28 +0000657 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000658 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000659 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000660 }
661
Howard Hinnant82894812010-09-22 16:48:34 +0000662 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000663 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnantc5607272011-06-03 17:30:28 +0000664 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000665 {}
666};
667
668// Unlink nodes [__f, __l]
669template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +0000670inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000671void
Howard Hinnant29f74322013-06-25 16:08:47 +0000672__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
Howard Hinnantc5607272011-06-03 17:30:28 +0000673 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674{
Howard Hinnant29f74322013-06-25 16:08:47 +0000675 __f->__prev_->__next_ = __l->__next_;
676 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000677}
678
679template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +0000680inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000681__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnantc5607272011-06-03 17:30:28 +0000682 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000683 : __size_alloc_(0)
684{
685}
686
687template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +0000688inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000689__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
690 : __size_alloc_(0, __node_allocator(__a))
691{
692}
693
694template <class _Tp, class _Alloc>
695__list_imp<_Tp, _Alloc>::~__list_imp()
696{
697 clear();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000698#if _LIBCPP_DEBUG_LEVEL >= 2
699 __get_db()->__erase_c(this);
700#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000701}
702
703template <class _Tp, class _Alloc>
704void
Howard Hinnantc5607272011-06-03 17:30:28 +0000705__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000706{
707 if (!empty())
708 {
709 __node_allocator& __na = __node_alloc();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000710 __node_pointer __f = __end_.__next_;
Howard Hinnant29f74322013-06-25 16:08:47 +0000711 __node_pointer __l = static_cast<__node_pointer>(
712 pointer_traits<__node_base_pointer>::pointer_to(__end_));
713 __unlink_nodes(__f, __l->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000714 __sz() = 0;
715 while (__f != __l)
716 {
Howard Hinnant29f74322013-06-25 16:08:47 +0000717 __node_pointer __n = __f;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000718 __f = __f->__next_;
Howard Hinnant29f74322013-06-25 16:08:47 +0000719 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
720 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000721 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000722#if _LIBCPP_DEBUG_LEVEL >= 2
723 __c_node* __c = __get_db()->__find_c_and_lock(this);
724 for (__i_node** __p = __c->end_; __p != __c->beg_; )
725 {
726 --__p;
727 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
728 if (__i->__ptr_ != __l)
729 {
730 (*__p)->__c_ = nullptr;
731 if (--__c->end_ != __p)
732 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
733 }
734 }
735 __get_db()->unlock();
736#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 }
738}
739
740template <class _Tp, class _Alloc>
741void
742__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +0000743 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
744 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000745{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000746 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
747 this->__node_alloc() == __c.__node_alloc(),
748 "list::swap: Either propagate_on_container_swap must be true"
749 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19 +0000750 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000751 __swap_alloc(__node_alloc(), __c.__node_alloc());
752 swap(__sz(), __c.__sz());
753 swap(__end_, __c.__end_);
754 if (__sz() == 0)
Marshall Clowea8ed832014-08-05 01:34:12 +0000755 __end_.__next_ = __end_.__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000756 else
Marshall Clowea8ed832014-08-05 01:34:12 +0000757 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000758 if (__c.__sz() == 0)
Marshall Clowea8ed832014-08-05 01:34:12 +0000759 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000760 else
Marshall Clowea8ed832014-08-05 01:34:12 +0000761 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
762
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000763#if _LIBCPP_DEBUG_LEVEL >= 2
764 __libcpp_db* __db = __get_db();
765 __c_node* __cn1 = __db->__find_c_and_lock(this);
766 __c_node* __cn2 = __db->__find_c(&__c);
767 std::swap(__cn1->beg_, __cn2->beg_);
768 std::swap(__cn1->end_, __cn2->end_);
769 std::swap(__cn1->cap_, __cn2->cap_);
770 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
771 {
772 --__p;
773 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +0000774 if (__i->__ptr_ == static_cast<__node_pointer>(
775 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000776 {
777 __cn2->__add(*__p);
778 if (--__cn1->end_ != __p)
779 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
780 }
781 else
782 (*__p)->__c_ = __cn1;
783 }
784 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
785 {
786 --__p;
787 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +0000788 if (__i->__ptr_ == static_cast<__node_pointer>(
789 pointer_traits<__node_base_pointer>::pointer_to(__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000790 {
791 __cn1->__add(*__p);
792 if (--__cn2->end_ != __p)
793 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
794 }
795 else
796 (*__p)->__c_ = __cn2;
797 }
798 __db->unlock();
799#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000800}
801
Marshall Clowceead9c2015-02-18 17:24:08 +0000802template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000803class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000804 : private __list_imp<_Tp, _Alloc>
805{
806 typedef __list_imp<_Tp, _Alloc> base;
807 typedef typename base::__node __node;
808 typedef typename base::__node_allocator __node_allocator;
809 typedef typename base::__node_pointer __node_pointer;
810 typedef typename base::__node_alloc_traits __node_alloc_traits;
Howard Hinnant29f74322013-06-25 16:08:47 +0000811 typedef typename base::__node_base __node_base;
812 typedef typename base::__node_base_pointer __node_base_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000813
814public:
815 typedef _Tp value_type;
816 typedef _Alloc allocator_type;
817 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
818 "Invalid allocator::value_type");
819 typedef value_type& reference;
820 typedef const value_type& const_reference;
821 typedef typename base::pointer pointer;
822 typedef typename base::const_pointer const_pointer;
823 typedef typename base::size_type size_type;
824 typedef typename base::difference_type difference_type;
825 typedef typename base::iterator iterator;
826 typedef typename base::const_iterator const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19 +0000827 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
828 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000829
Howard Hinnant82894812010-09-22 16:48:34 +0000830 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000831 list()
832 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000833 {
834#if _LIBCPP_DEBUG_LEVEL >= 2
835 __get_db()->__insert_c(this);
836#endif
837 }
Howard Hinnant82894812010-09-22 16:48:34 +0000838 _LIBCPP_INLINE_VISIBILITY
Marshall Clow955f2c82013-09-08 19:11:51 +0000839 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000840 {
841#if _LIBCPP_DEBUG_LEVEL >= 2
842 __get_db()->__insert_c(this);
843#endif
844 }
Marshall Clow955f2c82013-09-08 19:11:51 +0000845 explicit list(size_type __n);
846#if _LIBCPP_STD_VER > 11
847 explicit list(size_type __n, const allocator_type& __a);
848#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000849 list(size_type __n, const value_type& __x);
850 list(size_type __n, const value_type& __x, const allocator_type& __a);
851 template <class _InpIter>
852 list(_InpIter __f, _InpIter __l,
853 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
854 template <class _InpIter>
855 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
856 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
857
858 list(const list& __c);
859 list(const list& __c, const allocator_type& __a);
860 list& operator=(const list& __c);
Howard Hinnante3e32912011-08-12 21:56:02 +0000861#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000862 list(initializer_list<value_type> __il);
863 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000864#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant73d21a42010-09-04 23:28:19 +0000865#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc5607272011-06-03 17:30:28 +0000866 list(list&& __c)
867 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868 list(list&& __c, const allocator_type& __a);
Howard Hinnantc5607272011-06-03 17:30:28 +0000869 list& operator=(list&& __c)
870 _NOEXCEPT_(
871 __node_alloc_traits::propagate_on_container_move_assignment::value &&
872 is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000873#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000874#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34 +0000875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876 list& operator=(initializer_list<value_type> __il)
877 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000878#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000879
880 template <class _InpIter>
881 void assign(_InpIter __f, _InpIter __l,
882 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
883 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02 +0000884#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000886 void assign(initializer_list<value_type> __il)
887 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000888#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889
Howard Hinnantc5607272011-06-03 17:30:28 +0000890 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000891
Howard Hinnant82894812010-09-22 16:48:34 +0000892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000893 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant82894812010-09-22 16:48:34 +0000894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000895 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant82894812010-09-22 16:48:34 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000897 size_type max_size() const _NOEXCEPT
898 {return numeric_limits<difference_type>::max();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000899
Howard Hinnant82894812010-09-22 16:48:34 +0000900 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000901 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000903 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34 +0000904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000905 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34 +0000906 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000907 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34 +0000908 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000909 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34 +0000910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000911 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000912
Howard Hinnant82894812010-09-22 16:48:34 +0000913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000914 reverse_iterator rbegin() _NOEXCEPT
915 {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34 +0000916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000917 const_reverse_iterator rbegin() const _NOEXCEPT
918 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34 +0000919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000920 reverse_iterator rend() _NOEXCEPT
921 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34 +0000922 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000923 const_reverse_iterator rend() const _NOEXCEPT
924 {return const_reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34 +0000925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000926 const_reverse_iterator crbegin() const _NOEXCEPT
927 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34 +0000928 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000929 const_reverse_iterator crend() const _NOEXCEPT
930 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000931
Howard Hinnant82894812010-09-22 16:48:34 +0000932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000933 reference front()
934 {
935 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
936 return base::__end_.__next_->__value_;
937 }
Howard Hinnant82894812010-09-22 16:48:34 +0000938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000939 const_reference front() const
940 {
941 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
942 return base::__end_.__next_->__value_;
943 }
Howard Hinnant82894812010-09-22 16:48:34 +0000944 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000945 reference back()
946 {
947 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
948 return base::__end_.__prev_->__value_;
949 }
Howard Hinnant82894812010-09-22 16:48:34 +0000950 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000951 const_reference back() const
952 {
953 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
954 return base::__end_.__prev_->__value_;
955 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000956
Howard Hinnant73d21a42010-09-04 23:28:19 +0000957#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 void push_front(value_type&& __x);
959 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000960#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961 template <class... _Args>
962 void emplace_front(_Args&&... __args);
963 template <class... _Args>
964 void emplace_back(_Args&&... __args);
965 template <class... _Args>
966 iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000967#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000968 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000969#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000970
971 void push_front(const value_type& __x);
972 void push_back(const value_type& __x);
973
974 iterator insert(const_iterator __p, const value_type& __x);
975 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
976 template <class _InpIter>
977 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
978 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02 +0000979#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34 +0000980 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000981 iterator insert(const_iterator __p, initializer_list<value_type> __il)
982 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000983#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000984
Howard Hinnant82894812010-09-22 16:48:34 +0000985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000986 void swap(list& __c)
987 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
988 __is_nothrow_swappable<__node_allocator>::value)
989 {base::swap(__c);}
Howard Hinnant82894812010-09-22 16:48:34 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000991 void clear() _NOEXCEPT {base::clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000992
993 void pop_front();
994 void pop_back();
995
996 iterator erase(const_iterator __p);
997 iterator erase(const_iterator __f, const_iterator __l);
998
999 void resize(size_type __n);
1000 void resize(size_type __n, const value_type& __x);
1001
1002 void splice(const_iterator __p, list& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001003#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +00001004 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001005 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1006#endif
1007 void splice(const_iterator __p, list& __c, const_iterator __i);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001008#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +00001009 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001010 void splice(const_iterator __p, list&& __c, const_iterator __i)
1011 {splice(__p, __c, __i);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001012#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001013 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001014#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1017 {splice(__p, __c, __f, __l);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001018#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001019
1020 void remove(const value_type& __x);
1021 template <class _Pred> void remove_if(_Pred __pred);
1022 void unique();
1023 template <class _BinaryPred>
1024 void unique(_BinaryPred __binary_pred);
1025 void merge(list& __c);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001026#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +00001027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001028 void merge(list&& __c) {merge(__c);}
1029#endif
1030 template <class _Comp>
1031 void merge(list& __c, _Comp __comp);
Howard Hinnant73d21a42010-09-04 23:28:19 +00001032#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001033 template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:34 +00001034 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001035 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001036#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001037 void sort();
1038 template <class _Comp>
1039 void sort(_Comp __comp);
1040
Howard Hinnantc5607272011-06-03 17:30:28 +00001041 void reverse() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001042
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001043 bool __invariants() const;
1044
1045#if _LIBCPP_DEBUG_LEVEL >= 2
1046
1047 bool __dereferenceable(const const_iterator* __i) const;
1048 bool __decrementable(const const_iterator* __i) const;
1049 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1050 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1051
1052#endif // _LIBCPP_DEBUG_LEVEL >= 2
1053
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001054private:
Marshall Clowea8ed832014-08-05 01:34:12 +00001055 static void __link_nodes (__node_pointer __p, __node_pointer __f, __node_pointer __l);
1056 void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
1057 void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058 iterator __iterator(size_type __n);
1059 template <class _Comp>
1060 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1061
Howard Hinnantc5607272011-06-03 17:30:28 +00001062 void __move_assign(list& __c, true_type)
1063 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001064 void __move_assign(list& __c, false_type);
1065};
1066
1067// Link in nodes [__f, __l] just prior to __p
1068template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001069inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001070void
Howard Hinnant29f74322013-06-25 16:08:47 +00001071list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001072{
Howard Hinnant29f74322013-06-25 16:08:47 +00001073 __p->__prev_->__next_ = __f;
1074 __f->__prev_ = __p->__prev_;
1075 __p->__prev_ = __l;
1076 __l->__next_ = __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001077}
1078
Marshall Clowea8ed832014-08-05 01:34:12 +00001079// Link in nodes [__f, __l] at the front of the list
1080template <class _Tp, class _Alloc>
1081inline _LIBCPP_INLINE_VISIBILITY
1082void
1083list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
1084{
Marshall Clowfca038e2014-08-08 15:35:52 +00001085 __f->__prev_ = base::__end_.__self();
1086 __l->__next_ = base::__end_.__next_;
1087 __l->__next_->__prev_ = __l;
1088 base::__end_.__next_ = __f;
Marshall Clowea8ed832014-08-05 01:34:12 +00001089}
1090
1091// Link in nodes [__f, __l] at the front of the list
1092template <class _Tp, class _Alloc>
1093inline _LIBCPP_INLINE_VISIBILITY
1094void
1095list<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
1096{
Marshall Clowfca038e2014-08-08 15:35:52 +00001097 __l->__next_ = base::__end_.__self();
1098 __f->__prev_ = base::__end_.__prev_;
1099 __f->__prev_->__next_ = __f;
1100 base::__end_.__prev_ = __l;
Marshall Clowea8ed832014-08-05 01:34:12 +00001101}
1102
1103
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001104template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001105inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001106typename list<_Tp, _Alloc>::iterator
1107list<_Tp, _Alloc>::__iterator(size_type __n)
1108{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001109 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1110 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001111}
1112
1113template <class _Tp, class _Alloc>
1114list<_Tp, _Alloc>::list(size_type __n)
1115{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001116#if _LIBCPP_DEBUG_LEVEL >= 2
1117 __get_db()->__insert_c(this);
1118#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001119 for (; __n > 0; --__n)
Howard Hinnant73d21a42010-09-04 23:28:19 +00001120#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001121 emplace_back();
1122#else
1123 push_back(value_type());
1124#endif
1125}
1126
Marshall Clow955f2c82013-09-08 19:11:51 +00001127#if _LIBCPP_STD_VER > 11
1128template <class _Tp, class _Alloc>
1129list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1130{
1131#if _LIBCPP_DEBUG_LEVEL >= 2
1132 __get_db()->__insert_c(this);
1133#endif
1134 for (; __n > 0; --__n)
1135#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1136 emplace_back();
1137#else
1138 push_back(value_type());
1139#endif
1140}
1141#endif
1142
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001143template <class _Tp, class _Alloc>
1144list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1145{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001146#if _LIBCPP_DEBUG_LEVEL >= 2
1147 __get_db()->__insert_c(this);
1148#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001149 for (; __n > 0; --__n)
1150 push_back(__x);
1151}
1152
1153template <class _Tp, class _Alloc>
1154list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1155 : base(__a)
1156{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001157#if _LIBCPP_DEBUG_LEVEL >= 2
1158 __get_db()->__insert_c(this);
1159#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001160 for (; __n > 0; --__n)
1161 push_back(__x);
1162}
1163
1164template <class _Tp, class _Alloc>
1165template <class _InpIter>
1166list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1167 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1168{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001169#if _LIBCPP_DEBUG_LEVEL >= 2
1170 __get_db()->__insert_c(this);
1171#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001172 for (; __f != __l; ++__f)
1173 push_back(*__f);
1174}
1175
1176template <class _Tp, class _Alloc>
1177template <class _InpIter>
1178list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1179 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1180 : base(__a)
1181{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001182#if _LIBCPP_DEBUG_LEVEL >= 2
1183 __get_db()->__insert_c(this);
1184#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001185 for (; __f != __l; ++__f)
1186 push_back(*__f);
1187}
1188
1189template <class _Tp, class _Alloc>
1190list<_Tp, _Alloc>::list(const list& __c)
1191 : base(allocator_type(
1192 __node_alloc_traits::select_on_container_copy_construction(
1193 __c.__node_alloc())))
1194{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001195#if _LIBCPP_DEBUG_LEVEL >= 2
1196 __get_db()->__insert_c(this);
1197#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001198 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1199 push_back(*__i);
1200}
1201
1202template <class _Tp, class _Alloc>
1203list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1204 : base(__a)
1205{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001206#if _LIBCPP_DEBUG_LEVEL >= 2
1207 __get_db()->__insert_c(this);
1208#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001209 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1210 push_back(*__i);
1211}
1212
Howard Hinnante3e32912011-08-12 21:56:02 +00001213#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1214
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001215template <class _Tp, class _Alloc>
1216list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1217 : base(__a)
1218{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001219#if _LIBCPP_DEBUG_LEVEL >= 2
1220 __get_db()->__insert_c(this);
1221#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001222 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1223 __e = __il.end(); __i != __e; ++__i)
1224 push_back(*__i);
1225}
1226
1227template <class _Tp, class _Alloc>
1228list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1229{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001230#if _LIBCPP_DEBUG_LEVEL >= 2
1231 __get_db()->__insert_c(this);
1232#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001233 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1234 __e = __il.end(); __i != __e; ++__i)
1235 push_back(*__i);
1236}
1237
Howard Hinnante3e32912011-08-12 21:56:02 +00001238#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1239
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001240template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001241inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001242list<_Tp, _Alloc>&
1243list<_Tp, _Alloc>::operator=(const list& __c)
1244{
1245 if (this != &__c)
1246 {
1247 base::__copy_assign_alloc(__c);
1248 assign(__c.begin(), __c.end());
1249 }
1250 return *this;
1251}
1252
Howard Hinnant73d21a42010-09-04 23:28:19 +00001253#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001254
1255template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001256inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001257list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +00001258 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001259 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001260{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001261#if _LIBCPP_DEBUG_LEVEL >= 2
1262 __get_db()->__insert_c(this);
1263#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001264 splice(end(), __c);
1265}
1266
1267template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001268inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001269list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1270 : base(__a)
1271{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001272#if _LIBCPP_DEBUG_LEVEL >= 2
1273 __get_db()->__insert_c(this);
1274#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001275 if (__a == __c.get_allocator())
1276 splice(end(), __c);
1277 else
1278 {
Howard Hinnant99968442011-11-29 18:15:50 +00001279 typedef move_iterator<iterator> _Ip;
1280 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001281 }
1282}
1283
1284template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001285inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286list<_Tp, _Alloc>&
1287list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +00001288 _NOEXCEPT_(
1289 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1290 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001291{
1292 __move_assign(__c, integral_constant<bool,
1293 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1294 return *this;
1295}
1296
1297template <class _Tp, class _Alloc>
1298void
1299list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1300{
1301 if (base::__node_alloc() != __c.__node_alloc())
1302 {
Howard Hinnant99968442011-11-29 18:15:50 +00001303 typedef move_iterator<iterator> _Ip;
1304 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001305 }
1306 else
1307 __move_assign(__c, true_type());
1308}
1309
1310template <class _Tp, class _Alloc>
1311void
1312list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:28 +00001313 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001314{
1315 clear();
1316 base::__move_assign_alloc(__c);
1317 splice(end(), __c);
1318}
1319
Howard Hinnant73d21a42010-09-04 23:28:19 +00001320#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001321
1322template <class _Tp, class _Alloc>
1323template <class _InpIter>
1324void
1325list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1326 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1327{
1328 iterator __i = begin();
1329 iterator __e = end();
1330 for (; __f != __l && __i != __e; ++__f, ++__i)
1331 *__i = *__f;
1332 if (__i == __e)
1333 insert(__e, __f, __l);
1334 else
1335 erase(__i, __e);
1336}
1337
1338template <class _Tp, class _Alloc>
1339void
1340list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1341{
1342 iterator __i = begin();
1343 iterator __e = end();
1344 for (; __n > 0 && __i != __e; --__n, ++__i)
1345 *__i = __x;
1346 if (__i == __e)
1347 insert(__e, __n, __x);
1348 else
1349 erase(__i, __e);
1350}
1351
1352template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00001353inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001354_Alloc
Howard Hinnantc5607272011-06-03 17:30:28 +00001355list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356{
1357 return allocator_type(base::__node_alloc());
1358}
1359
1360template <class _Tp, class _Alloc>
1361typename list<_Tp, _Alloc>::iterator
1362list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1363{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001364#if _LIBCPP_DEBUG_LEVEL >= 2
1365 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1366 "list::insert(iterator, x) called with an iterator not"
1367 " referring to this list");
1368#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001369 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001370 typedef __allocator_destructor<__node_allocator> _Dp;
1371 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001372 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001373 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant29f74322013-06-25 16:08:47 +00001374 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001375 ++base::__sz();
Howard Hinnant79a35572013-04-05 00:18:49 +00001376#if _LIBCPP_DEBUG_LEVEL >= 2
1377 return iterator(__hold.release(), this);
1378#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001379 return iterator(__hold.release());
Howard Hinnant79a35572013-04-05 00:18:49 +00001380#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001381}
1382
1383template <class _Tp, class _Alloc>
1384typename list<_Tp, _Alloc>::iterator
1385list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1386{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001387#if _LIBCPP_DEBUG_LEVEL >= 2
1388 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1389 "list::insert(iterator, n, x) called with an iterator not"
1390 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:47 +00001391 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001392#else
Howard Hinnant29f74322013-06-25 16:08:47 +00001393 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001394#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001395 if (__n > 0)
1396 {
1397 size_type __ds = 0;
1398 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001399 typedef __allocator_destructor<__node_allocator> _Dp;
1400 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001402 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001403 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001404#if _LIBCPP_DEBUG_LEVEL >= 2
1405 __r = iterator(__hold.get(), this);
1406#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001407 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001408#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001409 __hold.release();
1410 iterator __e = __r;
1411#ifndef _LIBCPP_NO_EXCEPTIONS
1412 try
1413 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001414#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001415 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1416 {
1417 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001418 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001419 __e.__ptr_->__next_ = __hold.get();
1420 __hold->__prev_ = __e.__ptr_;
1421 __hold.release();
1422 }
1423#ifndef _LIBCPP_NO_EXCEPTIONS
1424 }
1425 catch (...)
1426 {
1427 while (true)
1428 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001429 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001430 __node_pointer __prev = __e.__ptr_->__prev_;
1431 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1432 if (__prev == 0)
1433 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001434#if _LIBCPP_DEBUG_LEVEL >= 2
1435 __e = iterator(__prev, this);
1436#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001437 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001438#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001439 }
1440 throw;
1441 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001442#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:47 +00001443 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444 base::__sz() += __ds;
1445 }
1446 return __r;
1447}
1448
1449template <class _Tp, class _Alloc>
1450template <class _InpIter>
1451typename list<_Tp, _Alloc>::iterator
1452list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1453 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1454{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001455#if _LIBCPP_DEBUG_LEVEL >= 2
1456 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1457 "list::insert(iterator, range) called with an iterator not"
1458 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:47 +00001459 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001460#else
Howard Hinnant29f74322013-06-25 16:08:47 +00001461 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001462#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001463 if (__f != __l)
1464 {
1465 size_type __ds = 0;
1466 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001467 typedef __allocator_destructor<__node_allocator> _Dp;
1468 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001470 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001471 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001472#if _LIBCPP_DEBUG_LEVEL >= 2
1473 __r = iterator(__hold.get(), this);
1474#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001475 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001476#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001477 __hold.release();
1478 iterator __e = __r;
1479#ifndef _LIBCPP_NO_EXCEPTIONS
1480 try
1481 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001482#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001483 for (++__f; __f != __l; ++__f, ++__e, ++__ds)
1484 {
1485 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001486 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001487 __e.__ptr_->__next_ = __hold.get();
1488 __hold->__prev_ = __e.__ptr_;
1489 __hold.release();
1490 }
1491#ifndef _LIBCPP_NO_EXCEPTIONS
1492 }
1493 catch (...)
1494 {
1495 while (true)
1496 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001497 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001498 __node_pointer __prev = __e.__ptr_->__prev_;
1499 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1500 if (__prev == 0)
1501 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001502#if _LIBCPP_DEBUG_LEVEL >= 2
1503 __e = iterator(__prev, this);
1504#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001505 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001506#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507 }
1508 throw;
1509 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001510#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:47 +00001511 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001512 base::__sz() += __ds;
1513 }
1514 return __r;
1515}
1516
1517template <class _Tp, class _Alloc>
1518void
1519list<_Tp, _Alloc>::push_front(const value_type& __x)
1520{
1521 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001522 typedef __allocator_destructor<__node_allocator> _Dp;
1523 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001524 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Marshall Clowea8ed832014-08-05 01:34:12 +00001525 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001526 ++base::__sz();
1527 __hold.release();
1528}
1529
1530template <class _Tp, class _Alloc>
1531void
1532list<_Tp, _Alloc>::push_back(const value_type& __x)
1533{
1534 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001535 typedef __allocator_destructor<__node_allocator> _Dp;
1536 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001537 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Marshall Clowea8ed832014-08-05 01:34:12 +00001538 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001539 ++base::__sz();
1540 __hold.release();
1541}
1542
Howard Hinnant73d21a42010-09-04 23:28:19 +00001543#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001544
1545template <class _Tp, class _Alloc>
1546void
1547list<_Tp, _Alloc>::push_front(value_type&& __x)
1548{
1549 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001550 typedef __allocator_destructor<__node_allocator> _Dp;
1551 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001552 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Marshall Clowea8ed832014-08-05 01:34:12 +00001553 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554 ++base::__sz();
1555 __hold.release();
1556}
1557
1558template <class _Tp, class _Alloc>
1559void
1560list<_Tp, _Alloc>::push_back(value_type&& __x)
1561{
1562 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001563 typedef __allocator_destructor<__node_allocator> _Dp;
1564 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001565 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Marshall Clowea8ed832014-08-05 01:34:12 +00001566 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001567 ++base::__sz();
1568 __hold.release();
1569}
1570
Howard Hinnant73d21a42010-09-04 23:28:19 +00001571#ifndef _LIBCPP_HAS_NO_VARIADICS
1572
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001573template <class _Tp, class _Alloc>
1574template <class... _Args>
1575void
1576list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1577{
1578 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001579 typedef __allocator_destructor<__node_allocator> _Dp;
1580 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001581 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Marshall Clowea8ed832014-08-05 01:34:12 +00001582 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001583 ++base::__sz();
1584 __hold.release();
1585}
1586
1587template <class _Tp, class _Alloc>
1588template <class... _Args>
1589void
1590list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1591{
1592 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-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 Hinnant0949eed2011-06-30 21:18:19 +00001595 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Marshall Clowea8ed832014-08-05 01:34:12 +00001596 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001597 ++base::__sz();
1598 __hold.release();
1599}
1600
1601template <class _Tp, class _Alloc>
1602template <class... _Args>
1603typename list<_Tp, _Alloc>::iterator
1604list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1605{
Howard Hinnant79a35572013-04-05 00:18:49 +00001606#if _LIBCPP_DEBUG_LEVEL >= 2
1607 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1608 "list::emplace(iterator, args...) called with an iterator not"
1609 " referring to this list");
1610#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001611 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001612 typedef __allocator_destructor<__node_allocator> _Dp;
1613 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001614 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001615 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnant29f74322013-06-25 16:08:47 +00001616 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001617 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001618#if _LIBCPP_DEBUG_LEVEL >= 2
1619 return iterator(__hold.release(), this);
1620#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001621 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001622#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623}
1624
Howard Hinnant73d21a42010-09-04 23:28:19 +00001625#endif // _LIBCPP_HAS_NO_VARIADICS
1626
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001627template <class _Tp, class _Alloc>
1628typename list<_Tp, _Alloc>::iterator
1629list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1630{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001631#if _LIBCPP_DEBUG_LEVEL >= 2
1632 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1633 "list::insert(iterator, x) called with an iterator not"
1634 " referring to this list");
1635#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001636 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001637 typedef __allocator_destructor<__node_allocator> _Dp;
1638 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001639 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001640 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Howard Hinnant29f74322013-06-25 16:08:47 +00001641 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001642 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001643#if _LIBCPP_DEBUG_LEVEL >= 2
1644 return iterator(__hold.release(), this);
1645#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001646 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001647#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001648}
1649
Howard Hinnant73d21a42010-09-04 23:28:19 +00001650#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001651
1652template <class _Tp, class _Alloc>
1653void
1654list<_Tp, _Alloc>::pop_front()
1655{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001656 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001657 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:47 +00001658 __node_pointer __n = base::__end_.__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659 base::__unlink_nodes(__n, __n);
1660 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001661#if _LIBCPP_DEBUG_LEVEL >= 2
1662 __c_node* __c = __get_db()->__find_c_and_lock(this);
1663 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1664 {
1665 --__p;
1666 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00001667 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001668 {
1669 (*__p)->__c_ = nullptr;
1670 if (--__c->end_ != __p)
1671 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1672 }
1673 }
1674 __get_db()->unlock();
1675#endif
Howard Hinnant29f74322013-06-25 16:08:47 +00001676 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1677 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001678}
1679
1680template <class _Tp, class _Alloc>
1681void
1682list<_Tp, _Alloc>::pop_back()
1683{
Dmitri Gribenkoc7a39cf2013-06-24 06:15:57 +00001684 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001685 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:47 +00001686 __node_pointer __n = base::__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687 base::__unlink_nodes(__n, __n);
1688 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001689#if _LIBCPP_DEBUG_LEVEL >= 2
1690 __c_node* __c = __get_db()->__find_c_and_lock(this);
1691 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1692 {
1693 --__p;
1694 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00001695 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001696 {
1697 (*__p)->__c_ = nullptr;
1698 if (--__c->end_ != __p)
1699 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1700 }
1701 }
1702 __get_db()->unlock();
1703#endif
Howard Hinnant29f74322013-06-25 16:08:47 +00001704 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1705 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001706}
1707
1708template <class _Tp, class _Alloc>
1709typename list<_Tp, _Alloc>::iterator
1710list<_Tp, _Alloc>::erase(const_iterator __p)
1711{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001712#if _LIBCPP_DEBUG_LEVEL >= 2
1713 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1714 "list::erase(iterator) called with an iterator not"
1715 " referring to this list");
1716#endif
Howard Hinnant79a35572013-04-05 00:18:49 +00001717 _LIBCPP_ASSERT(__p != end(),
1718 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001719 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:47 +00001720 __node_pointer __n = __p.__ptr_;
1721 __node_pointer __r = __n->__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001722 base::__unlink_nodes(__n, __n);
1723 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001724#if _LIBCPP_DEBUG_LEVEL >= 2
1725 __c_node* __c = __get_db()->__find_c_and_lock(this);
1726 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1727 {
1728 --__p;
1729 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00001730 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001731 {
1732 (*__p)->__c_ = nullptr;
1733 if (--__c->end_ != __p)
1734 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1735 }
1736 }
1737 __get_db()->unlock();
1738#endif
Howard Hinnant29f74322013-06-25 16:08:47 +00001739 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1740 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001741#if _LIBCPP_DEBUG_LEVEL >= 2
1742 return iterator(__r, this);
1743#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001744 return iterator(__r);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001745#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001746}
1747
1748template <class _Tp, class _Alloc>
1749typename list<_Tp, _Alloc>::iterator
1750list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1751{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001752#if _LIBCPP_DEBUG_LEVEL >= 2
1753 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1754 "list::erase(iterator, iterator) called with an iterator not"
1755 " referring to this list");
1756#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001757 if (__f != __l)
1758 {
1759 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:47 +00001760 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001761 while (__f != __l)
1762 {
Howard Hinnant29f74322013-06-25 16:08:47 +00001763 __node_pointer __n = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764 ++__f;
1765 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001766#if _LIBCPP_DEBUG_LEVEL >= 2
1767 __c_node* __c = __get_db()->__find_c_and_lock(this);
1768 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1769 {
1770 --__p;
1771 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00001772 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001773 {
1774 (*__p)->__c_ = nullptr;
1775 if (--__c->end_ != __p)
1776 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1777 }
1778 }
1779 __get_db()->unlock();
1780#endif
Howard Hinnant29f74322013-06-25 16:08:47 +00001781 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1782 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001783 }
1784 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001785#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47 +00001786 return iterator(__l.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001787#else
Howard Hinnant29f74322013-06-25 16:08:47 +00001788 return iterator(__l.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001789#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001790}
1791
1792template <class _Tp, class _Alloc>
1793void
1794list<_Tp, _Alloc>::resize(size_type __n)
1795{
1796 if (__n < base::__sz())
1797 erase(__iterator(__n), end());
1798 else if (__n > base::__sz())
1799 {
1800 __n -= base::__sz();
1801 size_type __ds = 0;
1802 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001803 typedef __allocator_destructor<__node_allocator> _Dp;
1804 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001805 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001806 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001807 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001808#if _LIBCPP_DEBUG_LEVEL >= 2
1809 iterator __r = iterator(__hold.release(), this);
1810#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001811 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001812#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001813 iterator __e = __r;
1814#ifndef _LIBCPP_NO_EXCEPTIONS
1815 try
1816 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001817#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001818 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1819 {
1820 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001821 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001822 __e.__ptr_->__next_ = __hold.get();
1823 __hold->__prev_ = __e.__ptr_;
1824 __hold.release();
1825 }
1826#ifndef _LIBCPP_NO_EXCEPTIONS
1827 }
1828 catch (...)
1829 {
1830 while (true)
1831 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001832 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001833 __node_pointer __prev = __e.__ptr_->__prev_;
1834 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1835 if (__prev == 0)
1836 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001837#if _LIBCPP_DEBUG_LEVEL >= 2
1838 __e = iterator(__prev, this);
1839#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001840 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001841#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001842 }
1843 throw;
1844 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001845#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clowea8ed832014-08-05 01:34:12 +00001846 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 base::__sz() += __ds;
1848 }
1849}
1850
1851template <class _Tp, class _Alloc>
1852void
1853list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1854{
1855 if (__n < base::__sz())
1856 erase(__iterator(__n), end());
1857 else if (__n > base::__sz())
1858 {
1859 __n -= base::__sz();
1860 size_type __ds = 0;
1861 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001862 typedef __allocator_destructor<__node_allocator> _Dp;
1863 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001864 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001865 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001866 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001867#if _LIBCPP_DEBUG_LEVEL >= 2
1868 iterator __r = iterator(__hold.release(), this);
1869#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001870 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001871#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001872 iterator __e = __r;
1873#ifndef _LIBCPP_NO_EXCEPTIONS
1874 try
1875 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001876#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001877 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1878 {
1879 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001880 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001881 __e.__ptr_->__next_ = __hold.get();
1882 __hold->__prev_ = __e.__ptr_;
1883 __hold.release();
1884 }
1885#ifndef _LIBCPP_NO_EXCEPTIONS
1886 }
1887 catch (...)
1888 {
1889 while (true)
1890 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00001891 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001892 __node_pointer __prev = __e.__ptr_->__prev_;
1893 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1894 if (__prev == 0)
1895 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001896#if _LIBCPP_DEBUG_LEVEL >= 2
1897 __e = iterator(__prev, this);
1898#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001899 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001900#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001901 }
1902 throw;
1903 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001904#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:47 +00001905 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
1906 pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907 base::__sz() += __ds;
Howard Hinnant324bb032010-08-22 00:02:43 +00001908 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001909}
1910
1911template <class _Tp, class _Alloc>
1912void
1913list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1914{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001915 _LIBCPP_ASSERT(this != &__c,
1916 "list::splice(iterator, list) called with this == &list");
1917#if _LIBCPP_DEBUG_LEVEL >= 2
1918 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1919 "list::splice(iterator, list) called with an iterator not"
1920 " referring to this list");
1921#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001922 if (!__c.empty())
1923 {
Howard Hinnant29f74322013-06-25 16:08:47 +00001924 __node_pointer __f = __c.__end_.__next_;
1925 __node_pointer __l = __c.__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001926 base::__unlink_nodes(__f, __l);
Howard Hinnant29f74322013-06-25 16:08:47 +00001927 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001928 base::__sz() += __c.__sz();
1929 __c.__sz() = 0;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001930#if _LIBCPP_DEBUG_LEVEL >= 2
1931 __libcpp_db* __db = __get_db();
1932 __c_node* __cn1 = __db->__find_c_and_lock(this);
1933 __c_node* __cn2 = __db->__find_c(&__c);
1934 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1935 {
1936 --__p;
1937 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00001938 if (__i->__ptr_ != static_cast<__node_pointer>(
1939 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001940 {
1941 __cn1->__add(*__p);
1942 (*__p)->__c_ = __cn1;
1943 if (--__cn2->end_ != __p)
1944 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1945 }
1946 }
1947 __db->unlock();
1948#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001949 }
1950}
1951
1952template <class _Tp, class _Alloc>
1953void
1954list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1955{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001956#if _LIBCPP_DEBUG_LEVEL >= 2
1957 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1958 "list::splice(iterator, list, iterator) called with first iterator not"
1959 " referring to this list");
1960 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1961 "list::splice(iterator, list, iterator) called with second iterator not"
1962 " referring to list argument");
1963 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
1964 "list::splice(iterator, list, iterator) called with second iterator not"
1965 " derefereceable");
1966#endif
1967 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001968 {
Howard Hinnant29f74322013-06-25 16:08:47 +00001969 __node_pointer __f = __i.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001970 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:47 +00001971 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001972 --__c.__sz();
1973 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001974#if _LIBCPP_DEBUG_LEVEL >= 2
1975 __libcpp_db* __db = __get_db();
1976 __c_node* __cn1 = __db->__find_c_and_lock(this);
1977 __c_node* __cn2 = __db->__find_c(&__c);
1978 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1979 {
1980 --__p;
1981 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00001982 if (__j->__ptr_ == __f)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001983 {
1984 __cn1->__add(*__p);
1985 (*__p)->__c_ = __cn1;
1986 if (--__cn2->end_ != __p)
1987 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1988 }
1989 }
1990 __db->unlock();
1991#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001992 }
1993}
1994
1995template <class _Tp, class _Alloc>
1996void
1997list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
1998{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001999#if _LIBCPP_DEBUG_LEVEL >= 2
2000 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2001 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2002 " referring to this list");
2003 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2004 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2005 " referring to list argument");
2006 if (this == &__c)
2007 {
2008 for (const_iterator __i = __f; __i != __l; ++__i)
2009 _LIBCPP_ASSERT(__i != __p,
2010 "list::splice(iterator, list, iterator, iterator)"
2011 " called with the first iterator within the range"
2012 " of the second and third iterators");
2013 }
2014#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002015 if (__f != __l)
2016 {
2017 if (this != &__c)
2018 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002019 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002020 __c.__sz() -= __s;
2021 base::__sz() += __s;
2022 }
Howard Hinnant29f74322013-06-25 16:08:47 +00002023 __node_pointer __first = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002024 --__l;
Howard Hinnant29f74322013-06-25 16:08:47 +00002025 __node_pointer __last = __l.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002026 base::__unlink_nodes(__first, __last);
Howard Hinnant29f74322013-06-25 16:08:47 +00002027 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002028#if _LIBCPP_DEBUG_LEVEL >= 2
2029 __libcpp_db* __db = __get_db();
2030 __c_node* __cn1 = __db->__find_c_and_lock(this);
2031 __c_node* __cn2 = __db->__find_c(&__c);
2032 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2033 {
2034 --__p;
2035 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00002036 for (__node_pointer __k = __f.__ptr_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002037 __k != __l.__ptr_; __k = __k->__next_)
2038 {
2039 if (__j->__ptr_ == __k)
2040 {
2041 __cn1->__add(*__p);
2042 (*__p)->__c_ = __cn1;
2043 if (--__cn2->end_ != __p)
2044 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2045 }
2046 }
2047 }
2048 __db->unlock();
2049#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050 }
2051}
2052
2053template <class _Tp, class _Alloc>
2054void
2055list<_Tp, _Alloc>::remove(const value_type& __x)
2056{
Marshall Clowfca038e2014-08-08 15:35:52 +00002057 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2058 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002059 {
2060 if (*__i == __x)
2061 {
Marshall Clowfca038e2014-08-08 15:35:52 +00002062 const_iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002063 for (; __j != __e && *__j == __x; ++__j)
2064 ;
Marshall Clowfca038e2014-08-08 15:35:52 +00002065 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2066 __i = __j;
Marshall Clowf0f1bca2014-08-04 17:32:25 +00002067 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:12 +00002068 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002069 }
2070 else
2071 ++__i;
2072 }
2073}
2074
2075template <class _Tp, class _Alloc>
2076template <class _Pred>
2077void
2078list<_Tp, _Alloc>::remove_if(_Pred __pred)
2079{
2080 for (iterator __i = begin(), __e = end(); __i != __e;)
2081 {
2082 if (__pred(*__i))
2083 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002084 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002085 for (; __j != __e && __pred(*__j); ++__j)
2086 ;
2087 __i = erase(__i, __j);
Marshall Clowf0f1bca2014-08-04 17:32:25 +00002088 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:12 +00002089 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002090 }
2091 else
2092 ++__i;
2093 }
2094}
2095
2096template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002097inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002098void
2099list<_Tp, _Alloc>::unique()
2100{
2101 unique(__equal_to<value_type>());
2102}
2103
2104template <class _Tp, class _Alloc>
2105template <class _BinaryPred>
2106void
2107list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2108{
2109 for (iterator __i = begin(), __e = end(); __i != __e;)
2110 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002111 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002112 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2113 ;
2114 if (++__i != __j)
2115 __i = erase(__i, __j);
2116 }
2117}
2118
2119template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002120inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002121void
2122list<_Tp, _Alloc>::merge(list& __c)
2123{
2124 merge(__c, __less<value_type>());
2125}
2126
2127template <class _Tp, class _Alloc>
2128template <class _Comp>
2129void
2130list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2131{
2132 if (this != &__c)
2133 {
2134 iterator __f1 = begin();
2135 iterator __e1 = end();
2136 iterator __f2 = __c.begin();
2137 iterator __e2 = __c.end();
2138 while (__f1 != __e1 && __f2 != __e2)
2139 {
2140 if (__comp(*__f2, *__f1))
2141 {
2142 size_type __ds = 1;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002143 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002144 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2145 ;
2146 base::__sz() += __ds;
2147 __c.__sz() -= __ds;
Howard Hinnant29f74322013-06-25 16:08:47 +00002148 __node_pointer __f = __f2.__ptr_;
2149 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002150 __f2 = __m2;
2151 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002152 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:47 +00002153 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002154 __f1 = __m2;
2155 }
2156 else
2157 ++__f1;
2158 }
2159 splice(__e1, __c);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002160#if _LIBCPP_DEBUG_LEVEL >= 2
2161 __libcpp_db* __db = __get_db();
2162 __c_node* __cn1 = __db->__find_c_and_lock(this);
2163 __c_node* __cn2 = __db->__find_c(&__c);
2164 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2165 {
2166 --__p;
2167 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47 +00002168 if (__i->__ptr_ != static_cast<__node_pointer>(
2169 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002170 {
2171 __cn1->__add(*__p);
2172 (*__p)->__c_ = __cn1;
2173 if (--__cn2->end_ != __p)
2174 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2175 }
2176 }
2177 __db->unlock();
2178#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002179 }
2180}
2181
2182template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002183inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002184void
2185list<_Tp, _Alloc>::sort()
2186{
2187 sort(__less<value_type>());
2188}
2189
2190template <class _Tp, class _Alloc>
2191template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:34 +00002192inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002193void
2194list<_Tp, _Alloc>::sort(_Comp __comp)
2195{
2196 __sort(begin(), end(), base::__sz(), __comp);
2197}
2198
2199template <class _Tp, class _Alloc>
2200template <class _Comp>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002201typename list<_Tp, _Alloc>::iterator
2202list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2203{
2204 switch (__n)
2205 {
2206 case 0:
2207 case 1:
2208 return __f1;
2209 case 2:
2210 if (__comp(*--__e2, *__f1))
2211 {
Howard Hinnant29f74322013-06-25 16:08:47 +00002212 __node_pointer __f = __e2.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002213 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:47 +00002214 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002215 return __e2;
2216 }
2217 return __f1;
2218 }
2219 size_type __n2 = __n / 2;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002220 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002221 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2222 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2223 if (__comp(*__f2, *__f1))
2224 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002225 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002226 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2227 ;
Howard Hinnant29f74322013-06-25 16:08:47 +00002228 __node_pointer __f = __f2.__ptr_;
2229 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002230 __r = __f2;
2231 __e1 = __f2 = __m2;
2232 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002233 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:47 +00002234 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002235 __f1 = __m2;
2236 }
2237 else
2238 ++__f1;
2239 while (__f1 != __e1 && __f2 != __e2)
2240 {
2241 if (__comp(*__f2, *__f1))
2242 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002243 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002244 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2245 ;
Howard Hinnant29f74322013-06-25 16:08:47 +00002246 __node_pointer __f = __f2.__ptr_;
2247 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002248 if (__e1 == __f2)
2249 __e1 = __m2;
2250 __f2 = __m2;
2251 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002252 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:47 +00002253 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002254 __f1 = __m2;
2255 }
2256 else
2257 ++__f1;
2258 }
2259 return __r;
2260}
2261
2262template <class _Tp, class _Alloc>
2263void
Howard Hinnantc5607272011-06-03 17:30:28 +00002264list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002265{
2266 if (base::__sz() > 1)
2267 {
2268 iterator __e = end();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002269 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2270 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002271 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002272 __i.__ptr_ = __i.__ptr_->__prev_;
2273 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002274 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002275 }
2276}
2277
2278template <class _Tp, class _Alloc>
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002279bool
2280list<_Tp, _Alloc>::__invariants() const
2281{
2282 return size() == _VSTD::distance(begin(), end());
2283}
2284
2285#if _LIBCPP_DEBUG_LEVEL >= 2
2286
2287template <class _Tp, class _Alloc>
2288bool
2289list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2290{
Howard Hinnant29f74322013-06-25 16:08:47 +00002291 return __i->__ptr_ != static_cast<__node_pointer>(
2292 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002293}
2294
2295template <class _Tp, class _Alloc>
2296bool
2297list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2298{
2299 return !empty() && __i->__ptr_ != base::__end_.__next_;
2300}
2301
2302template <class _Tp, class _Alloc>
2303bool
2304list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2305{
2306 return false;
2307}
2308
2309template <class _Tp, class _Alloc>
2310bool
2311list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2312{
2313 return false;
2314}
2315
2316#endif // _LIBCPP_DEBUG_LEVEL >= 2
2317
2318template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002319inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002320bool
2321operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2322{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002323 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002324}
2325
2326template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002327inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002328bool
2329operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2330{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002331 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002332}
2333
2334template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002335inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002336bool
2337operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2338{
2339 return !(__x == __y);
2340}
2341
2342template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002343inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002344bool
2345operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2346{
2347 return __y < __x;
2348}
2349
2350template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002351inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352bool
2353operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2354{
2355 return !(__x < __y);
2356}
2357
2358template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002359inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002360bool
2361operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2362{
2363 return !(__y < __x);
2364}
2365
2366template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002367inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002368void
2369swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnantc5607272011-06-03 17:30:28 +00002370 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002371{
2372 __x.swap(__y);
2373}
2374
2375_LIBCPP_END_NAMESPACE_STD
2376
2377#endif // _LIBCPP_LIST