blob: d39f076711d94c68c376a450e96b559e3ce75aac [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===---------------------------- list ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// 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:168//
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:2839 list()
40 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1641 explicit list(const allocator_type& a);
42 explicit list(size_type n);
Marshall Clowe00f53b2013-09-09 18:19:4543 explicit list(size_type n, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1644 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:2852 list(list&& x)
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1654 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:2861 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:1665 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:2871 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1672
Howard Hinnantc5607272011-06-03 17:30:2873 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:1685
86 reference front();
87 const_reference front() const;
88 reference back();
89 const_reference back() const;
90
Howard Hinnantc5607272011-06-03 17:30:2891 bool empty() const noexcept;
92 size_type size() const noexcept;
93 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1694
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:28120 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:16124
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:28148 void reverse() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16149};
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:28165 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
166 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16167
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:27180#include <__undef_min_max>
181
Eric Fiselierb9536102014-08-10 23:53:08182#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35183
Howard Hinnant08e17472011-10-17 20:05:10184#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16185#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16187
188_LIBCPP_BEGIN_NAMESPACE_STD
189
Howard Hinnant2b1b2d42011-06-14 19:58:17190template <class _Tp, class _VoidPtr> struct __list_node;
Howard Hinnantbc8d3f92010-05-11 19:42:16191
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:47202 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:16209 pointer __prev_;
210 pointer __next_;
211
Howard Hinnant82894812010-09-22 16:48:34212 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea8ed832014-08-05 01:34:12213 __list_node_base() : __prev_(__self()), __next_(__self()) {}
214
215 _LIBCPP_INLINE_VISIBILITY
216 pointer __self()
217 {
Marshall Clowfca038e2014-08-08 15:35:52218 return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
Marshall Clowea8ed832014-08-05 01:34:12219 }
Howard Hinnantbc8d3f92010-05-11 19:42:16220};
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:08229template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnant2b1b2d42011-06-14 19:58:17230template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnant0f678bd2013-08-12 18:38:34231template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16232
233template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34234class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16235{
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:03245#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:34253 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28254 explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03255#endif
256
257
Howard Hinnantbc8d3f92010-05-11 19:42:16258
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:34275 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28276 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03277 {
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:28285 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03286 __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:34320 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47321 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:16329
Howard Hinnant82894812010-09-22 16:48:34330 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03331 __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:34340 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16341 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
342
Howard Hinnant82894812010-09-22 16:48:34343 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03344 __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:34353 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16354 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
355
Howard Hinnant82894812010-09-22 16:48:34356 friend _LIBCPP_INLINE_VISIBILITY
357 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03358 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03359 return __x.__ptr_ == __y.__ptr_;
360 }
Howard Hinnant82894812010-09-22 16:48:34361 friend _LIBCPP_INLINE_VISIBILITY
362 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16363 {return !(__x == __y);}
364};
365
366template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34367class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16368{
369 typedef typename pointer_traits<_VoidPtr>::template
370#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant29f74322013-06-25 16:08:47371 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16372#else
Howard Hinnant29f74322013-06-25 16:08:47373 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16374#endif
375
376 __node_pointer __ptr_;
377
Howard Hinnant1c3ec6d2011-09-27 23:55:03378#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:34386 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28387 explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03388#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16389
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:34405 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28406 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03407 {
408#if _LIBCPP_DEBUG_LEVEL >= 2
409 __get_db()->__insert_i(this);
410#endif
411 }
Howard Hinnant211f0ee2011-01-28 23:46:28412 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6dcaf3e2013-04-05 17:58:52413 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03414 : __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:16422
Howard Hinnant82894812010-09-22 16:48:34423 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03424 __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:34457 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47458 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:16466
Howard Hinnant82894812010-09-22 16:48:34467 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03468 __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:34477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16478 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
479
Howard Hinnant82894812010-09-22 16:48:34480 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03481 __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:34490 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16491 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
492
Howard Hinnant82894812010-09-22 16:48:34493 friend _LIBCPP_INLINE_VISIBILITY
494 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03495 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03496 return __x.__ptr_ == __y.__ptr_;
497 }
Howard Hinnant82894812010-09-22 16:48:34498 friend _LIBCPP_INLINE_VISIBILITY
499 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16500 {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;
Marshall Clow66302c62015-04-07 05:21:38518 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16519 typedef allocator_traits<__node_allocator> __node_alloc_traits;
520 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant29f74322013-06-25 16:08:47521 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16522 typedef typename __alloc_traits::pointer pointer;
523 typedef typename __alloc_traits::const_pointer const_pointer;
524 typedef typename __alloc_traits::difference_type difference_type;
525
Marshall Clow66302c62015-04-07 05:21:38526 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
Howard Hinnant29f74322013-06-25 16:08:47527 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
528
Howard Hinnantbc8d3f92010-05-11 19:42:16529 __node_base __end_;
530 __compressed_pair<size_type, __node_allocator> __size_alloc_;
531
Howard Hinnant82894812010-09-22 16:48:34532 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28533 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34534 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28535 const size_type& __sz() const _NOEXCEPT
536 {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34537 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28538 __node_allocator& __node_alloc() _NOEXCEPT
539 {return __size_alloc_.second();}
Howard Hinnant82894812010-09-22 16:48:34540 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28541 const __node_allocator& __node_alloc() const _NOEXCEPT
542 {return __size_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16543
Howard Hinnant29f74322013-06-25 16:08:47544 static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16545
Howard Hinnantc5607272011-06-03 17:30:28546 __list_imp()
547 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16548 __list_imp(const allocator_type& __a);
549 ~__list_imp();
Howard Hinnantc5607272011-06-03 17:30:28550 void clear() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34551 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28552 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16553
Howard Hinnant82894812010-09-22 16:48:34554 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03555 iterator begin() _NOEXCEPT
556 {
557#if _LIBCPP_DEBUG_LEVEL >= 2
558 return iterator(__end_.__next_, this);
559#else
560 return iterator(__end_.__next_);
561#endif
562 }
Howard Hinnant82894812010-09-22 16:48:34563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28564 const_iterator begin() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03565 {
566#if _LIBCPP_DEBUG_LEVEL >= 2
567 return const_iterator(__end_.__next_, this);
568#else
569 return const_iterator(__end_.__next_);
570#endif
571 }
Howard Hinnant82894812010-09-22 16:48:34572 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03573 iterator end() _NOEXCEPT
574 {
575#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47576 return iterator(static_cast<__node_pointer>(
577 pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03578#else
Howard Hinnant29f74322013-06-25 16:08:47579 return iterator(static_cast<__node_pointer>(
580 pointer_traits<__node_base_pointer>::pointer_to(__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:03581#endif
582 }
Howard Hinnant82894812010-09-22 16:48:34583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28584 const_iterator end() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03585 {
586#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47587 return const_iterator(static_cast<__node_const_pointer>(
588 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03589#else
Howard Hinnant29f74322013-06-25 16:08:47590 return const_iterator(static_cast<__node_const_pointer>(
591 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
Howard Hinnant1c3ec6d2011-09-27 23:55:03592#endif
593 }
Howard Hinnantbc8d3f92010-05-11 19:42:16594
Howard Hinnantc5607272011-06-03 17:30:28595 void swap(__list_imp& __c)
596 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
597 __is_nothrow_swappable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16598
Howard Hinnant82894812010-09-22 16:48:34599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16600 void __copy_assign_alloc(const __list_imp& __c)
601 {__copy_assign_alloc(__c, integral_constant<bool,
602 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
603
Howard Hinnant82894812010-09-22 16:48:34604 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16605 void __move_assign_alloc(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28606 _NOEXCEPT_(
607 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
608 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16609 {__move_assign_alloc(__c, integral_constant<bool,
610 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
611
612private:
Howard Hinnant82894812010-09-22 16:48:34613 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16614 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y)
Howard Hinnantc5607272011-06-03 17:30:28615 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
616 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16617 {__swap_alloc(__x, __y, integral_constant<bool,
618 __node_alloc_traits::propagate_on_container_swap::value>());}
Howard Hinnant82894812010-09-22 16:48:34619 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16620 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type)
Howard Hinnantc5607272011-06-03 17:30:28621 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16622 {
Howard Hinnant0949eed2011-06-30 21:18:19623 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16624 swap(__x, __y);
625 }
Howard Hinnant82894812010-09-22 16:48:34626 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16627 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type)
Howard Hinnantc5607272011-06-03 17:30:28628 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16629 {}
630
Howard Hinnant82894812010-09-22 16:48:34631 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16632 void __copy_assign_alloc(const __list_imp& __c, true_type)
633 {
634 if (__node_alloc() != __c.__node_alloc())
635 clear();
636 __node_alloc() = __c.__node_alloc();
637 }
638
Howard Hinnant82894812010-09-22 16:48:34639 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16640 void __copy_assign_alloc(const __list_imp& __c, false_type)
641 {}
642
Howard Hinnant82894812010-09-22 16:48:34643 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31644 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:28645 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16646 {
Howard Hinnant0949eed2011-06-30 21:18:19647 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16648 }
649
Howard Hinnant82894812010-09-22 16:48:34650 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31651 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnantc5607272011-06-03 17:30:28652 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16653 {}
654};
655
656// Unlink nodes [__f, __l]
657template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34658inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16659void
Howard Hinnant29f74322013-06-25 16:08:47660__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
Howard Hinnantc5607272011-06-03 17:30:28661 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16662{
Howard Hinnant29f74322013-06-25 16:08:47663 __f->__prev_->__next_ = __l->__next_;
664 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16665}
666
667template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34668inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16669__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnantc5607272011-06-03 17:30:28670 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16671 : __size_alloc_(0)
672{
673}
674
675template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34676inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16677__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
678 : __size_alloc_(0, __node_allocator(__a))
679{
680}
681
682template <class _Tp, class _Alloc>
683__list_imp<_Tp, _Alloc>::~__list_imp()
684{
685 clear();
Howard Hinnant1c3ec6d2011-09-27 23:55:03686#if _LIBCPP_DEBUG_LEVEL >= 2
687 __get_db()->__erase_c(this);
688#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16689}
690
691template <class _Tp, class _Alloc>
692void
Howard Hinnantc5607272011-06-03 17:30:28693__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16694{
695 if (!empty())
696 {
697 __node_allocator& __na = __node_alloc();
Howard Hinnant1c3ec6d2011-09-27 23:55:03698 __node_pointer __f = __end_.__next_;
Howard Hinnant29f74322013-06-25 16:08:47699 __node_pointer __l = static_cast<__node_pointer>(
700 pointer_traits<__node_base_pointer>::pointer_to(__end_));
701 __unlink_nodes(__f, __l->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16702 __sz() = 0;
703 while (__f != __l)
704 {
Howard Hinnant29f74322013-06-25 16:08:47705 __node_pointer __n = __f;
Howard Hinnant1c3ec6d2011-09-27 23:55:03706 __f = __f->__next_;
Howard Hinnant29f74322013-06-25 16:08:47707 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
708 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16709 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03710#if _LIBCPP_DEBUG_LEVEL >= 2
711 __c_node* __c = __get_db()->__find_c_and_lock(this);
712 for (__i_node** __p = __c->end_; __p != __c->beg_; )
713 {
714 --__p;
715 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
716 if (__i->__ptr_ != __l)
717 {
718 (*__p)->__c_ = nullptr;
719 if (--__c->end_ != __p)
720 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
721 }
722 }
723 __get_db()->unlock();
724#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16725 }
726}
727
728template <class _Tp, class _Alloc>
729void
730__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28731 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
732 __is_nothrow_swappable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16733{
Howard Hinnant1c3ec6d2011-09-27 23:55:03734 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
735 this->__node_alloc() == __c.__node_alloc(),
736 "list::swap: Either propagate_on_container_swap must be true"
737 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19738 using _VSTD::swap;
Howard Hinnantbc8d3f92010-05-11 19:42:16739 __swap_alloc(__node_alloc(), __c.__node_alloc());
740 swap(__sz(), __c.__sz());
741 swap(__end_, __c.__end_);
742 if (__sz() == 0)
Marshall Clowea8ed832014-08-05 01:34:12743 __end_.__next_ = __end_.__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16744 else
Marshall Clowea8ed832014-08-05 01:34:12745 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16746 if (__c.__sz() == 0)
Marshall Clowea8ed832014-08-05 01:34:12747 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16748 else
Marshall Clowea8ed832014-08-05 01:34:12749 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
750
Howard Hinnant1c3ec6d2011-09-27 23:55:03751#if _LIBCPP_DEBUG_LEVEL >= 2
752 __libcpp_db* __db = __get_db();
753 __c_node* __cn1 = __db->__find_c_and_lock(this);
754 __c_node* __cn2 = __db->__find_c(&__c);
755 std::swap(__cn1->beg_, __cn2->beg_);
756 std::swap(__cn1->end_, __cn2->end_);
757 std::swap(__cn1->cap_, __cn2->cap_);
758 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
759 {
760 --__p;
761 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47762 if (__i->__ptr_ == static_cast<__node_pointer>(
763 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03764 {
765 __cn2->__add(*__p);
766 if (--__cn1->end_ != __p)
767 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
768 }
769 else
770 (*__p)->__c_ = __cn1;
771 }
772 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
773 {
774 --__p;
775 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47776 if (__i->__ptr_ == static_cast<__node_pointer>(
777 pointer_traits<__node_base_pointer>::pointer_to(__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03778 {
779 __cn1->__add(*__p);
780 if (--__cn2->end_ != __p)
781 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
782 }
783 else
784 (*__p)->__c_ = __cn2;
785 }
786 __db->unlock();
787#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16788}
789
Marshall Clowceead9c2015-02-18 17:24:08790template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34791class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnantbc8d3f92010-05-11 19:42:16792 : private __list_imp<_Tp, _Alloc>
793{
794 typedef __list_imp<_Tp, _Alloc> base;
795 typedef typename base::__node __node;
796 typedef typename base::__node_allocator __node_allocator;
797 typedef typename base::__node_pointer __node_pointer;
798 typedef typename base::__node_alloc_traits __node_alloc_traits;
Howard Hinnant29f74322013-06-25 16:08:47799 typedef typename base::__node_base __node_base;
800 typedef typename base::__node_base_pointer __node_base_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16801
802public:
803 typedef _Tp value_type;
804 typedef _Alloc allocator_type;
805 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
806 "Invalid allocator::value_type");
807 typedef value_type& reference;
808 typedef const value_type& const_reference;
809 typedef typename base::pointer pointer;
810 typedef typename base::const_pointer const_pointer;
811 typedef typename base::size_type size_type;
812 typedef typename base::difference_type difference_type;
813 typedef typename base::iterator iterator;
814 typedef typename base::const_iterator const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19815 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
816 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16817
Howard Hinnant82894812010-09-22 16:48:34818 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28819 list()
820 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant1c3ec6d2011-09-27 23:55:03821 {
822#if _LIBCPP_DEBUG_LEVEL >= 2
823 __get_db()->__insert_c(this);
824#endif
825 }
Howard Hinnant82894812010-09-22 16:48:34826 _LIBCPP_INLINE_VISIBILITY
Marshall Clow955f2c82013-09-08 19:11:51827 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant1c3ec6d2011-09-27 23:55:03828 {
829#if _LIBCPP_DEBUG_LEVEL >= 2
830 __get_db()->__insert_c(this);
831#endif
832 }
Marshall Clow955f2c82013-09-08 19:11:51833 explicit list(size_type __n);
834#if _LIBCPP_STD_VER > 11
835 explicit list(size_type __n, const allocator_type& __a);
836#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16837 list(size_type __n, const value_type& __x);
838 list(size_type __n, const value_type& __x, const allocator_type& __a);
839 template <class _InpIter>
840 list(_InpIter __f, _InpIter __l,
841 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
842 template <class _InpIter>
843 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
844 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
845
846 list(const list& __c);
847 list(const list& __c, const allocator_type& __a);
848 list& operator=(const list& __c);
Howard Hinnante3e32912011-08-12 21:56:02849#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16850 list(initializer_list<value_type> __il);
851 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02852#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant73d21a42010-09-04 23:28:19853#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc5607272011-06-03 17:30:28854 list(list&& __c)
855 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16856 list(list&& __c, const allocator_type& __a);
Howard Hinnantc5607272011-06-03 17:30:28857 list& operator=(list&& __c)
858 _NOEXCEPT_(
859 __node_alloc_traits::propagate_on_container_move_assignment::value &&
860 is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant73d21a42010-09-04 23:28:19861#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02862#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34863 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16864 list& operator=(initializer_list<value_type> __il)
865 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02866#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16867
868 template <class _InpIter>
869 void assign(_InpIter __f, _InpIter __l,
870 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
871 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02872#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16874 void assign(initializer_list<value_type> __il)
875 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02876#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16877
Howard Hinnantc5607272011-06-03 17:30:28878 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16879
Howard Hinnant82894812010-09-22 16:48:34880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28881 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant82894812010-09-22 16:48:34882 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28883 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant82894812010-09-22 16:48:34884 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28885 size_type max_size() const _NOEXCEPT
886 {return numeric_limits<difference_type>::max();}
Howard Hinnantbc8d3f92010-05-11 19:42:16887
Howard Hinnant82894812010-09-22 16:48:34888 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28889 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28891 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28893 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34894 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28895 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28897 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34898 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28899 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16900
Howard Hinnant82894812010-09-22 16:48:34901 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28902 reverse_iterator rbegin() _NOEXCEPT
903 {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34904 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28905 const_reverse_iterator rbegin() const _NOEXCEPT
906 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28908 reverse_iterator rend() _NOEXCEPT
909 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34910 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28911 const_reverse_iterator rend() const _NOEXCEPT
912 {return const_reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28914 const_reverse_iterator crbegin() const _NOEXCEPT
915 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34916 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28917 const_reverse_iterator crend() const _NOEXCEPT
918 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16919
Howard Hinnant82894812010-09-22 16:48:34920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03921 reference front()
922 {
923 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
924 return base::__end_.__next_->__value_;
925 }
Howard Hinnant82894812010-09-22 16:48:34926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03927 const_reference front() const
928 {
929 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
930 return base::__end_.__next_->__value_;
931 }
Howard Hinnant82894812010-09-22 16:48:34932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03933 reference back()
934 {
935 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
936 return base::__end_.__prev_->__value_;
937 }
Howard Hinnant82894812010-09-22 16:48:34938 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03939 const_reference back() const
940 {
941 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
942 return base::__end_.__prev_->__value_;
943 }
Howard Hinnantbc8d3f92010-05-11 19:42:16944
Howard Hinnant73d21a42010-09-04 23:28:19945#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16946 void push_front(value_type&& __x);
947 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19948#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16949 template <class... _Args>
950 void emplace_front(_Args&&... __args);
951 template <class... _Args>
952 void emplace_back(_Args&&... __args);
953 template <class... _Args>
954 iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19955#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16956 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19957#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16958
959 void push_front(const value_type& __x);
960 void push_back(const value_type& __x);
961
962 iterator insert(const_iterator __p, const value_type& __x);
963 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
964 template <class _InpIter>
965 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
966 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02967#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34968 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16969 iterator insert(const_iterator __p, initializer_list<value_type> __il)
970 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02971#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16972
Howard Hinnant82894812010-09-22 16:48:34973 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28974 void swap(list& __c)
975 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
976 __is_nothrow_swappable<__node_allocator>::value)
977 {base::swap(__c);}
Howard Hinnant82894812010-09-22 16:48:34978 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28979 void clear() _NOEXCEPT {base::clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16980
981 void pop_front();
982 void pop_back();
983
984 iterator erase(const_iterator __p);
985 iterator erase(const_iterator __f, const_iterator __l);
986
987 void resize(size_type __n);
988 void resize(size_type __n, const value_type& __x);
989
990 void splice(const_iterator __p, list& __c);
Howard Hinnant73d21a42010-09-04 23:28:19991#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34992 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16993 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
994#endif
995 void splice(const_iterator __p, list& __c, const_iterator __i);
Howard Hinnant73d21a42010-09-04 23:28:19996#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16998 void splice(const_iterator __p, list&& __c, const_iterator __i)
999 {splice(__p, __c, __i);}
Howard Hinnant73d21a42010-09-04 23:28:191000#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161001 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant73d21a42010-09-04 23:28:191002#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341003 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161004 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1005 {splice(__p, __c, __f, __l);}
Howard Hinnant73d21a42010-09-04 23:28:191006#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161007
1008 void remove(const value_type& __x);
1009 template <class _Pred> void remove_if(_Pred __pred);
1010 void unique();
1011 template <class _BinaryPred>
1012 void unique(_BinaryPred __binary_pred);
1013 void merge(list& __c);
Howard Hinnant73d21a42010-09-04 23:28:191014#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161016 void merge(list&& __c) {merge(__c);}
1017#endif
1018 template <class _Comp>
1019 void merge(list& __c, _Comp __comp);
Howard Hinnant73d21a42010-09-04 23:28:191020#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161021 template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:341022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161023 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant73d21a42010-09-04 23:28:191024#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161025 void sort();
1026 template <class _Comp>
1027 void sort(_Comp __comp);
1028
Howard Hinnantc5607272011-06-03 17:30:281029 void reverse() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161030
Howard Hinnant1c3ec6d2011-09-27 23:55:031031 bool __invariants() const;
1032
1033#if _LIBCPP_DEBUG_LEVEL >= 2
1034
1035 bool __dereferenceable(const const_iterator* __i) const;
1036 bool __decrementable(const const_iterator* __i) const;
1037 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1038 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1039
1040#endif // _LIBCPP_DEBUG_LEVEL >= 2
1041
Howard Hinnantbc8d3f92010-05-11 19:42:161042private:
Marshall Clowea8ed832014-08-05 01:34:121043 static void __link_nodes (__node_pointer __p, __node_pointer __f, __node_pointer __l);
1044 void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
1045 void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161046 iterator __iterator(size_type __n);
1047 template <class _Comp>
1048 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1049
Howard Hinnantc5607272011-06-03 17:30:281050 void __move_assign(list& __c, true_type)
1051 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:161052 void __move_assign(list& __c, false_type);
1053};
1054
1055// Link in nodes [__f, __l] just prior to __p
1056template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341057inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161058void
Howard Hinnant29f74322013-06-25 16:08:471059list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
Howard Hinnantbc8d3f92010-05-11 19:42:161060{
Howard Hinnant29f74322013-06-25 16:08:471061 __p->__prev_->__next_ = __f;
1062 __f->__prev_ = __p->__prev_;
1063 __p->__prev_ = __l;
1064 __l->__next_ = __p;
Howard Hinnantbc8d3f92010-05-11 19:42:161065}
1066
Marshall Clowea8ed832014-08-05 01:34:121067// Link in nodes [__f, __l] at the front of the list
1068template <class _Tp, class _Alloc>
1069inline _LIBCPP_INLINE_VISIBILITY
1070void
1071list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
1072{
Marshall Clowfca038e2014-08-08 15:35:521073 __f->__prev_ = base::__end_.__self();
1074 __l->__next_ = base::__end_.__next_;
1075 __l->__next_->__prev_ = __l;
1076 base::__end_.__next_ = __f;
Marshall Clowea8ed832014-08-05 01:34:121077}
1078
1079// 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_back(__node_pointer __f, __node_pointer __l)
1084{
Marshall Clowfca038e2014-08-08 15:35:521085 __l->__next_ = base::__end_.__self();
1086 __f->__prev_ = base::__end_.__prev_;
1087 __f->__prev_->__next_ = __f;
1088 base::__end_.__prev_ = __l;
Marshall Clowea8ed832014-08-05 01:34:121089}
1090
1091
Howard Hinnantbc8d3f92010-05-11 19:42:161092template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341093inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161094typename list<_Tp, _Alloc>::iterator
1095list<_Tp, _Alloc>::__iterator(size_type __n)
1096{
Howard Hinnant0949eed2011-06-30 21:18:191097 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1098 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161099}
1100
1101template <class _Tp, class _Alloc>
1102list<_Tp, _Alloc>::list(size_type __n)
1103{
Howard Hinnant1c3ec6d2011-09-27 23:55:031104#if _LIBCPP_DEBUG_LEVEL >= 2
1105 __get_db()->__insert_c(this);
1106#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161107 for (; __n > 0; --__n)
Howard Hinnant73d21a42010-09-04 23:28:191108#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161109 emplace_back();
1110#else
1111 push_back(value_type());
1112#endif
1113}
1114
Marshall Clow955f2c82013-09-08 19:11:511115#if _LIBCPP_STD_VER > 11
1116template <class _Tp, class _Alloc>
1117list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1118{
1119#if _LIBCPP_DEBUG_LEVEL >= 2
1120 __get_db()->__insert_c(this);
1121#endif
1122 for (; __n > 0; --__n)
1123#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1124 emplace_back();
1125#else
1126 push_back(value_type());
1127#endif
1128}
1129#endif
1130
Howard Hinnantbc8d3f92010-05-11 19:42:161131template <class _Tp, class _Alloc>
1132list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1133{
Howard Hinnant1c3ec6d2011-09-27 23:55:031134#if _LIBCPP_DEBUG_LEVEL >= 2
1135 __get_db()->__insert_c(this);
1136#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161137 for (; __n > 0; --__n)
1138 push_back(__x);
1139}
1140
1141template <class _Tp, class _Alloc>
1142list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1143 : base(__a)
1144{
Howard Hinnant1c3ec6d2011-09-27 23:55:031145#if _LIBCPP_DEBUG_LEVEL >= 2
1146 __get_db()->__insert_c(this);
1147#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161148 for (; __n > 0; --__n)
1149 push_back(__x);
1150}
1151
1152template <class _Tp, class _Alloc>
1153template <class _InpIter>
1154list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1155 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1156{
Howard Hinnant1c3ec6d2011-09-27 23:55:031157#if _LIBCPP_DEBUG_LEVEL >= 2
1158 __get_db()->__insert_c(this);
1159#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161160 for (; __f != __l; ++__f)
1161 push_back(*__f);
1162}
1163
1164template <class _Tp, class _Alloc>
1165template <class _InpIter>
1166list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1167 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1168 : base(__a)
1169{
Howard Hinnant1c3ec6d2011-09-27 23:55:031170#if _LIBCPP_DEBUG_LEVEL >= 2
1171 __get_db()->__insert_c(this);
1172#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161173 for (; __f != __l; ++__f)
1174 push_back(*__f);
1175}
1176
1177template <class _Tp, class _Alloc>
1178list<_Tp, _Alloc>::list(const list& __c)
1179 : base(allocator_type(
1180 __node_alloc_traits::select_on_container_copy_construction(
1181 __c.__node_alloc())))
1182{
Howard Hinnant1c3ec6d2011-09-27 23:55:031183#if _LIBCPP_DEBUG_LEVEL >= 2
1184 __get_db()->__insert_c(this);
1185#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161186 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1187 push_back(*__i);
1188}
1189
1190template <class _Tp, class _Alloc>
1191list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1192 : base(__a)
1193{
Howard Hinnant1c3ec6d2011-09-27 23:55:031194#if _LIBCPP_DEBUG_LEVEL >= 2
1195 __get_db()->__insert_c(this);
1196#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161197 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1198 push_back(*__i);
1199}
1200
Howard Hinnante3e32912011-08-12 21:56:021201#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1202
Howard Hinnantbc8d3f92010-05-11 19:42:161203template <class _Tp, class _Alloc>
1204list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1205 : base(__a)
1206{
Howard Hinnant1c3ec6d2011-09-27 23:55:031207#if _LIBCPP_DEBUG_LEVEL >= 2
1208 __get_db()->__insert_c(this);
1209#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161210 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1211 __e = __il.end(); __i != __e; ++__i)
1212 push_back(*__i);
1213}
1214
1215template <class _Tp, class _Alloc>
1216list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1217{
Howard Hinnant1c3ec6d2011-09-27 23:55:031218#if _LIBCPP_DEBUG_LEVEL >= 2
1219 __get_db()->__insert_c(this);
1220#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161221 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1222 __e = __il.end(); __i != __e; ++__i)
1223 push_back(*__i);
1224}
1225
Howard Hinnante3e32912011-08-12 21:56:021226#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1227
Howard Hinnantbc8d3f92010-05-11 19:42:161228template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341229inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161230list<_Tp, _Alloc>&
1231list<_Tp, _Alloc>::operator=(const list& __c)
1232{
1233 if (this != &__c)
1234 {
1235 base::__copy_assign_alloc(__c);
1236 assign(__c.begin(), __c.end());
1237 }
1238 return *this;
1239}
1240
Howard Hinnant73d21a42010-09-04 23:28:191241#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161242
1243template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341244inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161245list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281246 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnant0949eed2011-06-30 21:18:191247 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnantbc8d3f92010-05-11 19:42:161248{
Howard Hinnant1c3ec6d2011-09-27 23:55:031249#if _LIBCPP_DEBUG_LEVEL >= 2
1250 __get_db()->__insert_c(this);
1251#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161252 splice(end(), __c);
1253}
1254
1255template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341256inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161257list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1258 : base(__a)
1259{
Howard Hinnant1c3ec6d2011-09-27 23:55:031260#if _LIBCPP_DEBUG_LEVEL >= 2
1261 __get_db()->__insert_c(this);
1262#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161263 if (__a == __c.get_allocator())
1264 splice(end(), __c);
1265 else
1266 {
Howard Hinnant99968442011-11-29 18:15:501267 typedef move_iterator<iterator> _Ip;
1268 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161269 }
1270}
1271
1272template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341273inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161274list<_Tp, _Alloc>&
1275list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281276 _NOEXCEPT_(
1277 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1278 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161279{
1280 __move_assign(__c, integral_constant<bool,
1281 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1282 return *this;
1283}
1284
1285template <class _Tp, class _Alloc>
1286void
1287list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1288{
1289 if (base::__node_alloc() != __c.__node_alloc())
1290 {
Howard Hinnant99968442011-11-29 18:15:501291 typedef move_iterator<iterator> _Ip;
1292 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161293 }
1294 else
1295 __move_assign(__c, true_type());
1296}
1297
1298template <class _Tp, class _Alloc>
1299void
1300list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:281301 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161302{
1303 clear();
1304 base::__move_assign_alloc(__c);
1305 splice(end(), __c);
1306}
1307
Howard Hinnant73d21a42010-09-04 23:28:191308#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161309
1310template <class _Tp, class _Alloc>
1311template <class _InpIter>
1312void
1313list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1314 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1315{
1316 iterator __i = begin();
1317 iterator __e = end();
1318 for (; __f != __l && __i != __e; ++__f, ++__i)
1319 *__i = *__f;
1320 if (__i == __e)
1321 insert(__e, __f, __l);
1322 else
1323 erase(__i, __e);
1324}
1325
1326template <class _Tp, class _Alloc>
1327void
1328list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1329{
1330 iterator __i = begin();
1331 iterator __e = end();
1332 for (; __n > 0 && __i != __e; --__n, ++__i)
1333 *__i = __x;
1334 if (__i == __e)
1335 insert(__e, __n, __x);
1336 else
1337 erase(__i, __e);
1338}
1339
1340template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341341inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161342_Alloc
Howard Hinnantc5607272011-06-03 17:30:281343list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161344{
1345 return allocator_type(base::__node_alloc());
1346}
1347
1348template <class _Tp, class _Alloc>
1349typename list<_Tp, _Alloc>::iterator
1350list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1351{
Howard Hinnant1c3ec6d2011-09-27 23:55:031352#if _LIBCPP_DEBUG_LEVEL >= 2
1353 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1354 "list::insert(iterator, x) called with an iterator not"
1355 " referring to this list");
1356#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161357 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501358 typedef __allocator_destructor<__node_allocator> _Dp;
1359 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161360 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191361 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant29f74322013-06-25 16:08:471362 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161363 ++base::__sz();
Howard Hinnant79a35572013-04-05 00:18:491364#if _LIBCPP_DEBUG_LEVEL >= 2
1365 return iterator(__hold.release(), this);
1366#else
Howard Hinnantbc8d3f92010-05-11 19:42:161367 return iterator(__hold.release());
Howard Hinnant79a35572013-04-05 00:18:491368#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161369}
1370
1371template <class _Tp, class _Alloc>
1372typename list<_Tp, _Alloc>::iterator
1373list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1374{
Howard Hinnant1c3ec6d2011-09-27 23:55:031375#if _LIBCPP_DEBUG_LEVEL >= 2
1376 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1377 "list::insert(iterator, n, x) called with an iterator not"
1378 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471379 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031380#else
Howard Hinnant29f74322013-06-25 16:08:471381 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031382#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161383 if (__n > 0)
1384 {
1385 size_type __ds = 0;
1386 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501387 typedef __allocator_destructor<__node_allocator> _Dp;
1388 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161389 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191390 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161391 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031392#if _LIBCPP_DEBUG_LEVEL >= 2
1393 __r = iterator(__hold.get(), this);
1394#else
Howard Hinnantbc8d3f92010-05-11 19:42:161395 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:031396#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161397 __hold.release();
1398 iterator __e = __r;
1399#ifndef _LIBCPP_NO_EXCEPTIONS
1400 try
1401 {
Howard Hinnant324bb032010-08-22 00:02:431402#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161403 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1404 {
1405 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191406 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161407 __e.__ptr_->__next_ = __hold.get();
1408 __hold->__prev_ = __e.__ptr_;
1409 __hold.release();
1410 }
1411#ifndef _LIBCPP_NO_EXCEPTIONS
1412 }
1413 catch (...)
1414 {
1415 while (true)
1416 {
Howard Hinnant0949eed2011-06-30 21:18:191417 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161418 __node_pointer __prev = __e.__ptr_->__prev_;
1419 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1420 if (__prev == 0)
1421 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031422#if _LIBCPP_DEBUG_LEVEL >= 2
1423 __e = iterator(__prev, this);
1424#else
Howard Hinnantbc8d3f92010-05-11 19:42:161425 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031426#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161427 }
1428 throw;
1429 }
Howard Hinnant324bb032010-08-22 00:02:431430#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471431 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161432 base::__sz() += __ds;
1433 }
1434 return __r;
1435}
1436
1437template <class _Tp, class _Alloc>
1438template <class _InpIter>
1439typename list<_Tp, _Alloc>::iterator
1440list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1441 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1442{
Howard Hinnant1c3ec6d2011-09-27 23:55:031443#if _LIBCPP_DEBUG_LEVEL >= 2
1444 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1445 "list::insert(iterator, range) called with an iterator not"
1446 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471447 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031448#else
Howard Hinnant29f74322013-06-25 16:08:471449 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031450#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161451 if (__f != __l)
1452 {
1453 size_type __ds = 0;
1454 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501455 typedef __allocator_destructor<__node_allocator> _Dp;
1456 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161457 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191458 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:161459 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031460#if _LIBCPP_DEBUG_LEVEL >= 2
1461 __r = iterator(__hold.get(), this);
1462#else
Howard Hinnantbc8d3f92010-05-11 19:42:161463 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:031464#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161465 __hold.release();
1466 iterator __e = __r;
1467#ifndef _LIBCPP_NO_EXCEPTIONS
1468 try
1469 {
Howard Hinnant324bb032010-08-22 00:02:431470#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier537876b2015-03-19 03:20:021471 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnantbc8d3f92010-05-11 19:42:161472 {
1473 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191474 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:161475 __e.__ptr_->__next_ = __hold.get();
1476 __hold->__prev_ = __e.__ptr_;
1477 __hold.release();
1478 }
1479#ifndef _LIBCPP_NO_EXCEPTIONS
1480 }
1481 catch (...)
1482 {
1483 while (true)
1484 {
Howard Hinnant0949eed2011-06-30 21:18:191485 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161486 __node_pointer __prev = __e.__ptr_->__prev_;
1487 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1488 if (__prev == 0)
1489 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031490#if _LIBCPP_DEBUG_LEVEL >= 2
1491 __e = iterator(__prev, this);
1492#else
Howard Hinnantbc8d3f92010-05-11 19:42:161493 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031494#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161495 }
1496 throw;
1497 }
Howard Hinnant324bb032010-08-22 00:02:431498#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471499 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161500 base::__sz() += __ds;
1501 }
1502 return __r;
1503}
1504
1505template <class _Tp, class _Alloc>
1506void
1507list<_Tp, _Alloc>::push_front(const value_type& __x)
1508{
1509 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501510 typedef __allocator_destructor<__node_allocator> _Dp;
1511 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191512 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Marshall Clowea8ed832014-08-05 01:34:121513 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161514 ++base::__sz();
1515 __hold.release();
1516}
1517
1518template <class _Tp, class _Alloc>
1519void
1520list<_Tp, _Alloc>::push_back(const value_type& __x)
1521{
1522 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501523 typedef __allocator_destructor<__node_allocator> _Dp;
1524 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191525 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Marshall Clowea8ed832014-08-05 01:34:121526 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161527 ++base::__sz();
1528 __hold.release();
1529}
1530
Howard Hinnant73d21a42010-09-04 23:28:191531#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161532
1533template <class _Tp, class _Alloc>
1534void
1535list<_Tp, _Alloc>::push_front(value_type&& __x)
1536{
1537 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501538 typedef __allocator_destructor<__node_allocator> _Dp;
1539 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191540 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Marshall Clowea8ed832014-08-05 01:34:121541 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161542 ++base::__sz();
1543 __hold.release();
1544}
1545
1546template <class _Tp, class _Alloc>
1547void
1548list<_Tp, _Alloc>::push_back(value_type&& __x)
1549{
1550 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501551 typedef __allocator_destructor<__node_allocator> _Dp;
1552 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191553 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Marshall Clowea8ed832014-08-05 01:34:121554 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161555 ++base::__sz();
1556 __hold.release();
1557}
1558
Howard Hinnant73d21a42010-09-04 23:28:191559#ifndef _LIBCPP_HAS_NO_VARIADICS
1560
Howard Hinnantbc8d3f92010-05-11 19:42:161561template <class _Tp, class _Alloc>
1562template <class... _Args>
1563void
1564list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1565{
1566 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501567 typedef __allocator_destructor<__node_allocator> _Dp;
1568 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191569 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Marshall Clowea8ed832014-08-05 01:34:121570 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161571 ++base::__sz();
1572 __hold.release();
1573}
1574
1575template <class _Tp, class _Alloc>
1576template <class... _Args>
1577void
1578list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1579{
1580 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501581 typedef __allocator_destructor<__node_allocator> _Dp;
1582 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191583 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Marshall Clowea8ed832014-08-05 01:34:121584 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161585 ++base::__sz();
1586 __hold.release();
1587}
1588
1589template <class _Tp, class _Alloc>
1590template <class... _Args>
1591typename list<_Tp, _Alloc>::iterator
1592list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1593{
Howard Hinnant79a35572013-04-05 00:18:491594#if _LIBCPP_DEBUG_LEVEL >= 2
1595 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1596 "list::emplace(iterator, args...) called with an iterator not"
1597 " referring to this list");
1598#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161599 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501600 typedef __allocator_destructor<__node_allocator> _Dp;
1601 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161602 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191603 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnant29f74322013-06-25 16:08:471604 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161605 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031606#if _LIBCPP_DEBUG_LEVEL >= 2
1607 return iterator(__hold.release(), this);
1608#else
Howard Hinnantbc8d3f92010-05-11 19:42:161609 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031610#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161611}
1612
Howard Hinnant73d21a42010-09-04 23:28:191613#endif // _LIBCPP_HAS_NO_VARIADICS
1614
Howard Hinnantbc8d3f92010-05-11 19:42:161615template <class _Tp, class _Alloc>
1616typename list<_Tp, _Alloc>::iterator
1617list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1618{
Howard Hinnant1c3ec6d2011-09-27 23:55:031619#if _LIBCPP_DEBUG_LEVEL >= 2
1620 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1621 "list::insert(iterator, x) called with an iterator not"
1622 " referring to this list");
1623#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161624 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501625 typedef __allocator_destructor<__node_allocator> _Dp;
1626 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161627 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191628 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Howard Hinnant29f74322013-06-25 16:08:471629 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161630 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031631#if _LIBCPP_DEBUG_LEVEL >= 2
1632 return iterator(__hold.release(), this);
1633#else
Howard Hinnantbc8d3f92010-05-11 19:42:161634 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031635#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161636}
1637
Howard Hinnant73d21a42010-09-04 23:28:191638#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161639
1640template <class _Tp, class _Alloc>
1641void
1642list<_Tp, _Alloc>::pop_front()
1643{
Howard Hinnant1c3ec6d2011-09-27 23:55:031644 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161645 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471646 __node_pointer __n = base::__end_.__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161647 base::__unlink_nodes(__n, __n);
1648 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031649#if _LIBCPP_DEBUG_LEVEL >= 2
1650 __c_node* __c = __get_db()->__find_c_and_lock(this);
1651 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1652 {
1653 --__p;
1654 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471655 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031656 {
1657 (*__p)->__c_ = nullptr;
1658 if (--__c->end_ != __p)
1659 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1660 }
1661 }
1662 __get_db()->unlock();
1663#endif
Howard Hinnant29f74322013-06-25 16:08:471664 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1665 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161666}
1667
1668template <class _Tp, class _Alloc>
1669void
1670list<_Tp, _Alloc>::pop_back()
1671{
Dmitri Gribenkoc7a39cf2013-06-24 06:15:571672 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161673 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471674 __node_pointer __n = base::__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161675 base::__unlink_nodes(__n, __n);
1676 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031677#if _LIBCPP_DEBUG_LEVEL >= 2
1678 __c_node* __c = __get_db()->__find_c_and_lock(this);
1679 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1680 {
1681 --__p;
1682 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471683 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031684 {
1685 (*__p)->__c_ = nullptr;
1686 if (--__c->end_ != __p)
1687 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1688 }
1689 }
1690 __get_db()->unlock();
1691#endif
Howard Hinnant29f74322013-06-25 16:08:471692 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1693 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161694}
1695
1696template <class _Tp, class _Alloc>
1697typename list<_Tp, _Alloc>::iterator
1698list<_Tp, _Alloc>::erase(const_iterator __p)
1699{
Howard Hinnant1c3ec6d2011-09-27 23:55:031700#if _LIBCPP_DEBUG_LEVEL >= 2
1701 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1702 "list::erase(iterator) called with an iterator not"
1703 " referring to this list");
1704#endif
Howard Hinnant79a35572013-04-05 00:18:491705 _LIBCPP_ASSERT(__p != end(),
1706 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:161707 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471708 __node_pointer __n = __p.__ptr_;
1709 __node_pointer __r = __n->__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161710 base::__unlink_nodes(__n, __n);
1711 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031712#if _LIBCPP_DEBUG_LEVEL >= 2
1713 __c_node* __c = __get_db()->__find_c_and_lock(this);
1714 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1715 {
1716 --__p;
1717 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471718 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031719 {
1720 (*__p)->__c_ = nullptr;
1721 if (--__c->end_ != __p)
1722 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1723 }
1724 }
1725 __get_db()->unlock();
1726#endif
Howard Hinnant29f74322013-06-25 16:08:471727 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1728 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnant1c3ec6d2011-09-27 23:55:031729#if _LIBCPP_DEBUG_LEVEL >= 2
1730 return iterator(__r, this);
1731#else
Howard Hinnantbc8d3f92010-05-11 19:42:161732 return iterator(__r);
Howard Hinnant1c3ec6d2011-09-27 23:55:031733#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161734}
1735
1736template <class _Tp, class _Alloc>
1737typename list<_Tp, _Alloc>::iterator
1738list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1739{
Howard Hinnant1c3ec6d2011-09-27 23:55:031740#if _LIBCPP_DEBUG_LEVEL >= 2
1741 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1742 "list::erase(iterator, iterator) called with an iterator not"
1743 " referring to this list");
1744#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161745 if (__f != __l)
1746 {
1747 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471748 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:161749 while (__f != __l)
1750 {
Howard Hinnant29f74322013-06-25 16:08:471751 __node_pointer __n = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:161752 ++__f;
1753 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031754#if _LIBCPP_DEBUG_LEVEL >= 2
1755 __c_node* __c = __get_db()->__find_c_and_lock(this);
1756 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1757 {
1758 --__p;
1759 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471760 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031761 {
1762 (*__p)->__c_ = nullptr;
1763 if (--__c->end_ != __p)
1764 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1765 }
1766 }
1767 __get_db()->unlock();
1768#endif
Howard Hinnant29f74322013-06-25 16:08:471769 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1770 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161771 }
1772 }
Howard Hinnant1c3ec6d2011-09-27 23:55:031773#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:471774 return iterator(__l.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031775#else
Howard Hinnant29f74322013-06-25 16:08:471776 return iterator(__l.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031777#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161778}
1779
1780template <class _Tp, class _Alloc>
1781void
1782list<_Tp, _Alloc>::resize(size_type __n)
1783{
1784 if (__n < base::__sz())
1785 erase(__iterator(__n), end());
1786 else if (__n > base::__sz())
1787 {
1788 __n -= base::__sz();
1789 size_type __ds = 0;
1790 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501791 typedef __allocator_destructor<__node_allocator> _Dp;
1792 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161793 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191794 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161795 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031796#if _LIBCPP_DEBUG_LEVEL >= 2
1797 iterator __r = iterator(__hold.release(), this);
1798#else
Howard Hinnantbc8d3f92010-05-11 19:42:161799 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031800#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161801 iterator __e = __r;
1802#ifndef _LIBCPP_NO_EXCEPTIONS
1803 try
1804 {
Howard Hinnant324bb032010-08-22 00:02:431805#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161806 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1807 {
1808 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191809 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161810 __e.__ptr_->__next_ = __hold.get();
1811 __hold->__prev_ = __e.__ptr_;
1812 __hold.release();
1813 }
1814#ifndef _LIBCPP_NO_EXCEPTIONS
1815 }
1816 catch (...)
1817 {
1818 while (true)
1819 {
Howard Hinnant0949eed2011-06-30 21:18:191820 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161821 __node_pointer __prev = __e.__ptr_->__prev_;
1822 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1823 if (__prev == 0)
1824 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031825#if _LIBCPP_DEBUG_LEVEL >= 2
1826 __e = iterator(__prev, this);
1827#else
Howard Hinnantbc8d3f92010-05-11 19:42:161828 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031829#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161830 }
1831 throw;
1832 }
Howard Hinnant324bb032010-08-22 00:02:431833#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clowea8ed832014-08-05 01:34:121834 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161835 base::__sz() += __ds;
1836 }
1837}
1838
1839template <class _Tp, class _Alloc>
1840void
1841list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1842{
1843 if (__n < base::__sz())
1844 erase(__iterator(__n), end());
1845 else if (__n > base::__sz())
1846 {
1847 __n -= base::__sz();
1848 size_type __ds = 0;
1849 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501850 typedef __allocator_destructor<__node_allocator> _Dp;
1851 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161852 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191853 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161854 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031855#if _LIBCPP_DEBUG_LEVEL >= 2
1856 iterator __r = iterator(__hold.release(), this);
1857#else
Howard Hinnantbc8d3f92010-05-11 19:42:161858 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031859#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161860 iterator __e = __r;
1861#ifndef _LIBCPP_NO_EXCEPTIONS
1862 try
1863 {
Howard Hinnant324bb032010-08-22 00:02:431864#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161865 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1866 {
1867 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191868 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161869 __e.__ptr_->__next_ = __hold.get();
1870 __hold->__prev_ = __e.__ptr_;
1871 __hold.release();
1872 }
1873#ifndef _LIBCPP_NO_EXCEPTIONS
1874 }
1875 catch (...)
1876 {
1877 while (true)
1878 {
Howard Hinnant0949eed2011-06-30 21:18:191879 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161880 __node_pointer __prev = __e.__ptr_->__prev_;
1881 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1882 if (__prev == 0)
1883 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031884#if _LIBCPP_DEBUG_LEVEL >= 2
1885 __e = iterator(__prev, this);
1886#else
Howard Hinnantbc8d3f92010-05-11 19:42:161887 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031888#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161889 }
1890 throw;
1891 }
Howard Hinnant324bb032010-08-22 00:02:431892#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471893 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
1894 pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161895 base::__sz() += __ds;
Howard Hinnant324bb032010-08-22 00:02:431896 }
Howard Hinnantbc8d3f92010-05-11 19:42:161897}
1898
1899template <class _Tp, class _Alloc>
1900void
1901list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1902{
Howard Hinnant1c3ec6d2011-09-27 23:55:031903 _LIBCPP_ASSERT(this != &__c,
1904 "list::splice(iterator, list) called with this == &list");
1905#if _LIBCPP_DEBUG_LEVEL >= 2
1906 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1907 "list::splice(iterator, list) called with an iterator not"
1908 " referring to this list");
1909#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161910 if (!__c.empty())
1911 {
Howard Hinnant29f74322013-06-25 16:08:471912 __node_pointer __f = __c.__end_.__next_;
1913 __node_pointer __l = __c.__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161914 base::__unlink_nodes(__f, __l);
Howard Hinnant29f74322013-06-25 16:08:471915 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161916 base::__sz() += __c.__sz();
1917 __c.__sz() = 0;
Howard Hinnant1c3ec6d2011-09-27 23:55:031918#if _LIBCPP_DEBUG_LEVEL >= 2
1919 __libcpp_db* __db = __get_db();
1920 __c_node* __cn1 = __db->__find_c_and_lock(this);
1921 __c_node* __cn2 = __db->__find_c(&__c);
1922 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1923 {
1924 --__p;
1925 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471926 if (__i->__ptr_ != static_cast<__node_pointer>(
1927 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:031928 {
1929 __cn1->__add(*__p);
1930 (*__p)->__c_ = __cn1;
1931 if (--__cn2->end_ != __p)
1932 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1933 }
1934 }
1935 __db->unlock();
1936#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161937 }
1938}
1939
1940template <class _Tp, class _Alloc>
1941void
1942list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1943{
Howard Hinnant1c3ec6d2011-09-27 23:55:031944#if _LIBCPP_DEBUG_LEVEL >= 2
1945 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1946 "list::splice(iterator, list, iterator) called with first iterator not"
1947 " referring to this list");
1948 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1949 "list::splice(iterator, list, iterator) called with second iterator not"
1950 " referring to list argument");
1951 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
1952 "list::splice(iterator, list, iterator) called with second iterator not"
1953 " derefereceable");
1954#endif
1955 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnantbc8d3f92010-05-11 19:42:161956 {
Howard Hinnant29f74322013-06-25 16:08:471957 __node_pointer __f = __i.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:161958 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:471959 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:161960 --__c.__sz();
1961 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031962#if _LIBCPP_DEBUG_LEVEL >= 2
1963 __libcpp_db* __db = __get_db();
1964 __c_node* __cn1 = __db->__find_c_and_lock(this);
1965 __c_node* __cn2 = __db->__find_c(&__c);
1966 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1967 {
1968 --__p;
1969 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471970 if (__j->__ptr_ == __f)
Howard Hinnant1c3ec6d2011-09-27 23:55:031971 {
1972 __cn1->__add(*__p);
1973 (*__p)->__c_ = __cn1;
1974 if (--__cn2->end_ != __p)
1975 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1976 }
1977 }
1978 __db->unlock();
1979#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161980 }
1981}
1982
1983template <class _Tp, class _Alloc>
1984void
1985list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
1986{
Howard Hinnant1c3ec6d2011-09-27 23:55:031987#if _LIBCPP_DEBUG_LEVEL >= 2
1988 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1989 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
1990 " referring to this list");
1991 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
1992 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
1993 " referring to list argument");
1994 if (this == &__c)
1995 {
1996 for (const_iterator __i = __f; __i != __l; ++__i)
1997 _LIBCPP_ASSERT(__i != __p,
1998 "list::splice(iterator, list, iterator, iterator)"
1999 " called with the first iterator within the range"
2000 " of the second and third iterators");
2001 }
2002#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162003 if (__f != __l)
2004 {
2005 if (this != &__c)
2006 {
Howard Hinnant0949eed2011-06-30 21:18:192007 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162008 __c.__sz() -= __s;
2009 base::__sz() += __s;
2010 }
Howard Hinnant29f74322013-06-25 16:08:472011 __node_pointer __first = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162012 --__l;
Howard Hinnant29f74322013-06-25 16:08:472013 __node_pointer __last = __l.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162014 base::__unlink_nodes(__first, __last);
Howard Hinnant29f74322013-06-25 16:08:472015 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant1c3ec6d2011-09-27 23:55:032016#if _LIBCPP_DEBUG_LEVEL >= 2
2017 __libcpp_db* __db = __get_db();
2018 __c_node* __cn1 = __db->__find_c_and_lock(this);
2019 __c_node* __cn2 = __db->__find_c(&__c);
2020 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2021 {
2022 --__p;
2023 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:472024 for (__node_pointer __k = __f.__ptr_;
Howard Hinnant1c3ec6d2011-09-27 23:55:032025 __k != __l.__ptr_; __k = __k->__next_)
2026 {
2027 if (__j->__ptr_ == __k)
2028 {
2029 __cn1->__add(*__p);
2030 (*__p)->__c_ = __cn1;
2031 if (--__cn2->end_ != __p)
2032 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2033 }
2034 }
2035 }
2036 __db->unlock();
2037#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162038 }
2039}
2040
2041template <class _Tp, class _Alloc>
2042void
2043list<_Tp, _Alloc>::remove(const value_type& __x)
2044{
Marshall Clowfca038e2014-08-08 15:35:522045 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2046 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnantbc8d3f92010-05-11 19:42:162047 {
2048 if (*__i == __x)
2049 {
Marshall Clowfca038e2014-08-08 15:35:522050 const_iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162051 for (; __j != __e && *__j == __x; ++__j)
2052 ;
Marshall Clowfca038e2014-08-08 15:35:522053 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2054 __i = __j;
Marshall Clowf0f1bca2014-08-04 17:32:252055 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122056 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162057 }
2058 else
2059 ++__i;
2060 }
2061}
2062
2063template <class _Tp, class _Alloc>
2064template <class _Pred>
2065void
2066list<_Tp, _Alloc>::remove_if(_Pred __pred)
2067{
2068 for (iterator __i = begin(), __e = end(); __i != __e;)
2069 {
2070 if (__pred(*__i))
2071 {
Howard Hinnant0949eed2011-06-30 21:18:192072 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162073 for (; __j != __e && __pred(*__j); ++__j)
2074 ;
2075 __i = erase(__i, __j);
Marshall Clowf0f1bca2014-08-04 17:32:252076 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122077 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162078 }
2079 else
2080 ++__i;
2081 }
2082}
2083
2084template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342085inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162086void
2087list<_Tp, _Alloc>::unique()
2088{
2089 unique(__equal_to<value_type>());
2090}
2091
2092template <class _Tp, class _Alloc>
2093template <class _BinaryPred>
2094void
2095list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2096{
2097 for (iterator __i = begin(), __e = end(); __i != __e;)
2098 {
Howard Hinnant0949eed2011-06-30 21:18:192099 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162100 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2101 ;
2102 if (++__i != __j)
2103 __i = erase(__i, __j);
2104 }
2105}
2106
2107template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342108inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162109void
2110list<_Tp, _Alloc>::merge(list& __c)
2111{
2112 merge(__c, __less<value_type>());
2113}
2114
2115template <class _Tp, class _Alloc>
2116template <class _Comp>
2117void
2118list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2119{
2120 if (this != &__c)
2121 {
2122 iterator __f1 = begin();
2123 iterator __e1 = end();
2124 iterator __f2 = __c.begin();
2125 iterator __e2 = __c.end();
2126 while (__f1 != __e1 && __f2 != __e2)
2127 {
2128 if (__comp(*__f2, *__f1))
2129 {
2130 size_type __ds = 1;
Howard Hinnant0949eed2011-06-30 21:18:192131 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162132 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2133 ;
2134 base::__sz() += __ds;
2135 __c.__sz() -= __ds;
Howard Hinnant29f74322013-06-25 16:08:472136 __node_pointer __f = __f2.__ptr_;
2137 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162138 __f2 = __m2;
2139 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192140 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472141 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162142 __f1 = __m2;
2143 }
2144 else
2145 ++__f1;
2146 }
2147 splice(__e1, __c);
Howard Hinnant1c3ec6d2011-09-27 23:55:032148#if _LIBCPP_DEBUG_LEVEL >= 2
2149 __libcpp_db* __db = __get_db();
2150 __c_node* __cn1 = __db->__find_c_and_lock(this);
2151 __c_node* __cn2 = __db->__find_c(&__c);
2152 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2153 {
2154 --__p;
2155 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:472156 if (__i->__ptr_ != static_cast<__node_pointer>(
2157 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:032158 {
2159 __cn1->__add(*__p);
2160 (*__p)->__c_ = __cn1;
2161 if (--__cn2->end_ != __p)
2162 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2163 }
2164 }
2165 __db->unlock();
2166#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162167 }
2168}
2169
2170template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342171inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162172void
2173list<_Tp, _Alloc>::sort()
2174{
2175 sort(__less<value_type>());
2176}
2177
2178template <class _Tp, class _Alloc>
2179template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:342180inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162181void
2182list<_Tp, _Alloc>::sort(_Comp __comp)
2183{
2184 __sort(begin(), end(), base::__sz(), __comp);
2185}
2186
2187template <class _Tp, class _Alloc>
2188template <class _Comp>
Howard Hinnantbc8d3f92010-05-11 19:42:162189typename list<_Tp, _Alloc>::iterator
2190list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2191{
2192 switch (__n)
2193 {
2194 case 0:
2195 case 1:
2196 return __f1;
2197 case 2:
2198 if (__comp(*--__e2, *__f1))
2199 {
Howard Hinnant29f74322013-06-25 16:08:472200 __node_pointer __f = __e2.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162201 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:472202 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:162203 return __e2;
2204 }
2205 return __f1;
2206 }
2207 size_type __n2 = __n / 2;
Howard Hinnant0949eed2011-06-30 21:18:192208 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnantbc8d3f92010-05-11 19:42:162209 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2210 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2211 if (__comp(*__f2, *__f1))
2212 {
Howard Hinnant0949eed2011-06-30 21:18:192213 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162214 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2215 ;
Howard Hinnant29f74322013-06-25 16:08:472216 __node_pointer __f = __f2.__ptr_;
2217 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162218 __r = __f2;
2219 __e1 = __f2 = __m2;
2220 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192221 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472222 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162223 __f1 = __m2;
2224 }
2225 else
2226 ++__f1;
2227 while (__f1 != __e1 && __f2 != __e2)
2228 {
2229 if (__comp(*__f2, *__f1))
2230 {
Howard Hinnant0949eed2011-06-30 21:18:192231 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162232 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2233 ;
Howard Hinnant29f74322013-06-25 16:08:472234 __node_pointer __f = __f2.__ptr_;
2235 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162236 if (__e1 == __f2)
2237 __e1 = __m2;
2238 __f2 = __m2;
2239 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192240 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472241 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162242 __f1 = __m2;
2243 }
2244 else
2245 ++__f1;
2246 }
2247 return __r;
2248}
2249
2250template <class _Tp, class _Alloc>
2251void
Howard Hinnantc5607272011-06-03 17:30:282252list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162253{
2254 if (base::__sz() > 1)
2255 {
2256 iterator __e = end();
Howard Hinnant1c3ec6d2011-09-27 23:55:032257 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2258 {
Howard Hinnant0949eed2011-06-30 21:18:192259 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant1c3ec6d2011-09-27 23:55:032260 __i.__ptr_ = __i.__ptr_->__prev_;
2261 }
Howard Hinnant0949eed2011-06-30 21:18:192262 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:162263 }
2264}
2265
2266template <class _Tp, class _Alloc>
Howard Hinnant1c3ec6d2011-09-27 23:55:032267bool
2268list<_Tp, _Alloc>::__invariants() const
2269{
2270 return size() == _VSTD::distance(begin(), end());
2271}
2272
2273#if _LIBCPP_DEBUG_LEVEL >= 2
2274
2275template <class _Tp, class _Alloc>
2276bool
2277list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2278{
Howard Hinnant29f74322013-06-25 16:08:472279 return __i->__ptr_ != static_cast<__node_pointer>(
2280 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:032281}
2282
2283template <class _Tp, class _Alloc>
2284bool
2285list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2286{
2287 return !empty() && __i->__ptr_ != base::__end_.__next_;
2288}
2289
2290template <class _Tp, class _Alloc>
2291bool
2292list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2293{
2294 return false;
2295}
2296
2297template <class _Tp, class _Alloc>
2298bool
2299list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2300{
2301 return false;
2302}
2303
2304#endif // _LIBCPP_DEBUG_LEVEL >= 2
2305
2306template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342307inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162308bool
2309operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2310{
Howard Hinnant0949eed2011-06-30 21:18:192311 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:162312}
2313
2314template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342315inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162316bool
2317operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2318{
Howard Hinnant0949eed2011-06-30 21:18:192319 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162320}
2321
2322template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342323inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162324bool
2325operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2326{
2327 return !(__x == __y);
2328}
2329
2330template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342331inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162332bool
2333operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2334{
2335 return __y < __x;
2336}
2337
2338template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342339inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162340bool
2341operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2342{
2343 return !(__x < __y);
2344}
2345
2346template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342347inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162348bool
2349operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2350{
2351 return !(__y < __x);
2352}
2353
2354template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342355inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162356void
2357swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnantc5607272011-06-03 17:30:282358 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162359{
2360 __x.swap(__y);
2361}
2362
2363_LIBCPP_END_NAMESPACE_STD
2364
2365#endif // _LIBCPP_LIST