blob: 14201a80e3488f9f782a703e6fa17963525fa67c [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&)
Marshall Clow7d914d12015-07-13 20:04:56121 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantc5607272011-06-03 17:30:28122 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16123
124 void splice(const_iterator position, list& x);
125 void splice(const_iterator position, list&& x);
126 void splice(const_iterator position, list& x, const_iterator i);
127 void splice(const_iterator position, list&& x, const_iterator i);
128 void splice(const_iterator position, list& x, const_iterator first,
129 const_iterator last);
130 void splice(const_iterator position, list&& x, const_iterator first,
131 const_iterator last);
132
133 void remove(const value_type& value);
134 template <class Pred> void remove_if(Pred pred);
135 void unique();
136 template <class BinaryPredicate>
137 void unique(BinaryPredicate binary_pred);
138 void merge(list& x);
139 void merge(list&& x);
140 template <class Compare>
141 void merge(list& x, Compare comp);
142 template <class Compare>
143 void merge(list&& x, Compare comp);
144 void sort();
145 template <class Compare>
146 void sort(Compare comp);
Howard Hinnantc5607272011-06-03 17:30:28147 void reverse() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16148};
149
150template <class T, class Alloc>
151 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
152template <class T, class Alloc>
153 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
154template <class T, class Alloc>
155 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
156template <class T, class Alloc>
157 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
158template <class T, class Alloc>
159 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
160template <class T, class Alloc>
161 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
162
163template <class T, class Alloc>
Howard Hinnantc5607272011-06-03 17:30:28164 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
165 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16166
167} // std
168
169*/
170
171#include <__config>
172
173#include <memory>
174#include <limits>
175#include <initializer_list>
176#include <iterator>
177#include <algorithm>
178
Howard Hinnant66c6f972011-11-29 16:45:27179#include <__undef_min_max>
180
Eric Fiselierb9536102014-08-10 23:53:08181#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35182
Howard Hinnant08e17472011-10-17 20:05:10183#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16184#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10185#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16186
187_LIBCPP_BEGIN_NAMESPACE_STD
188
Howard Hinnant2b1b2d42011-06-14 19:58:17189template <class _Tp, class _VoidPtr> struct __list_node;
Howard Hinnantbc8d3f92010-05-11 19:42:16190
191template <class _Tp, class _VoidPtr>
192struct __list_node_base
193{
194 typedef typename pointer_traits<_VoidPtr>::template
195#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
196 rebind<__list_node<_Tp, _VoidPtr> > pointer;
197#else
198 rebind<__list_node<_Tp, _VoidPtr> >::other pointer;
199#endif
200
Howard Hinnant29f74322013-06-25 16:08:47201 typedef typename pointer_traits<_VoidPtr>::template
202#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
203 rebind<__list_node_base> __base_pointer;
204#else
205 rebind<__list_node_base>::other __base_pointer;
206#endif
207
Howard Hinnantbc8d3f92010-05-11 19:42:16208 pointer __prev_;
209 pointer __next_;
210
Howard Hinnant82894812010-09-22 16:48:34211 _LIBCPP_INLINE_VISIBILITY
Marshall Clowea8ed832014-08-05 01:34:12212 __list_node_base() : __prev_(__self()), __next_(__self()) {}
213
214 _LIBCPP_INLINE_VISIBILITY
215 pointer __self()
216 {
Marshall Clowfca038e2014-08-08 15:35:52217 return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
Marshall Clowea8ed832014-08-05 01:34:12218 }
Howard Hinnantbc8d3f92010-05-11 19:42:16219};
220
221template <class _Tp, class _VoidPtr>
222struct __list_node
223 : public __list_node_base<_Tp, _VoidPtr>
224{
225 _Tp __value_;
226};
227
Marshall Clowceead9c2015-02-18 17:24:08228template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnant2b1b2d42011-06-14 19:58:17229template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnant0f678bd2013-08-12 18:38:34230template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16231
232template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34233class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16234{
235 typedef typename pointer_traits<_VoidPtr>::template
236#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
237 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
238#else
239 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
240#endif
241
242 __node_pointer __ptr_;
243
Howard Hinnant1c3ec6d2011-09-27 23:55:03244#if _LIBCPP_DEBUG_LEVEL >= 2
245 _LIBCPP_INLINE_VISIBILITY
246 explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
247 : __ptr_(__p)
248 {
249 __get_db()->__insert_ic(this, __c);
250 }
251#else
Howard Hinnant82894812010-09-22 16:48:34252 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28253 explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03254#endif
255
256
Howard Hinnantbc8d3f92010-05-11 19:42:16257
258 template<class, class> friend class list;
259 template<class, class> friend class __list_imp;
260 template<class, class> friend class __list_const_iterator;
261public:
262 typedef bidirectional_iterator_tag iterator_category;
263 typedef _Tp value_type;
264 typedef value_type& reference;
265 typedef typename pointer_traits<_VoidPtr>::template
266#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
267 rebind<value_type>
268#else
269 rebind<value_type>::other
270#endif
271 pointer;
272 typedef typename pointer_traits<pointer>::difference_type difference_type;
273
Howard Hinnant82894812010-09-22 16:48:34274 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28275 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03276 {
277#if _LIBCPP_DEBUG_LEVEL >= 2
278 __get_db()->__insert_i(this);
279#endif
280 }
281
282#if _LIBCPP_DEBUG_LEVEL >= 2
283
Howard Hinnant211f0ee2011-01-28 23:46:28284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03285 __list_iterator(const __list_iterator& __p)
286 : __ptr_(__p.__ptr_)
287 {
288 __get_db()->__iterator_copy(this, &__p);
289 }
290
291 _LIBCPP_INLINE_VISIBILITY
292 ~__list_iterator()
293 {
294 __get_db()->__erase_i(this);
295 }
296
297 _LIBCPP_INLINE_VISIBILITY
298 __list_iterator& operator=(const __list_iterator& __p)
299 {
300 if (this != &__p)
301 {
302 __get_db()->__iterator_copy(this, &__p);
303 __ptr_ = __p.__ptr_;
304 }
305 return *this;
306 }
307
308#endif // _LIBCPP_DEBUG_LEVEL >= 2
309
310 _LIBCPP_INLINE_VISIBILITY
311 reference operator*() const
312 {
313#if _LIBCPP_DEBUG_LEVEL >= 2
314 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
315 "Attempted to dereference a non-dereferenceable list::iterator");
316#endif
317 return __ptr_->__value_;
318 }
Howard Hinnant82894812010-09-22 16:48:34319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47320 pointer operator->() const
321 {
322#if _LIBCPP_DEBUG_LEVEL >= 2
323 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
324 "Attempted to dereference a non-dereferenceable list::iterator");
325#endif
326 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
327 }
Howard Hinnantbc8d3f92010-05-11 19:42:16328
Howard Hinnant82894812010-09-22 16:48:34329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03330 __list_iterator& operator++()
331 {
332#if _LIBCPP_DEBUG_LEVEL >= 2
333 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
334 "Attempted to increment non-incrementable list::iterator");
335#endif
336 __ptr_ = __ptr_->__next_;
337 return *this;
338 }
Howard Hinnant82894812010-09-22 16:48:34339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16340 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
341
Howard Hinnant82894812010-09-22 16:48:34342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03343 __list_iterator& operator--()
344 {
345#if _LIBCPP_DEBUG_LEVEL >= 2
346 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
347 "Attempted to decrement non-decrementable list::iterator");
348#endif
349 __ptr_ = __ptr_->__prev_;
350 return *this;
351 }
Howard Hinnant82894812010-09-22 16:48:34352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16353 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
354
Howard Hinnant82894812010-09-22 16:48:34355 friend _LIBCPP_INLINE_VISIBILITY
356 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03357 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03358 return __x.__ptr_ == __y.__ptr_;
359 }
Howard Hinnant82894812010-09-22 16:48:34360 friend _LIBCPP_INLINE_VISIBILITY
361 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16362 {return !(__x == __y);}
363};
364
365template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34366class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16367{
368 typedef typename pointer_traits<_VoidPtr>::template
369#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
Howard Hinnant29f74322013-06-25 16:08:47370 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16371#else
Howard Hinnant29f74322013-06-25 16:08:47372 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16373#endif
374
375 __node_pointer __ptr_;
376
Howard Hinnant1c3ec6d2011-09-27 23:55:03377#if _LIBCPP_DEBUG_LEVEL >= 2
378 _LIBCPP_INLINE_VISIBILITY
379 explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
380 : __ptr_(__p)
381 {
382 __get_db()->__insert_ic(this, __c);
383 }
384#else
Howard Hinnant82894812010-09-22 16:48:34385 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28386 explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03387#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16388
389 template<class, class> friend class list;
390 template<class, class> friend class __list_imp;
391public:
392 typedef bidirectional_iterator_tag iterator_category;
393 typedef _Tp value_type;
394 typedef const value_type& reference;
395 typedef typename pointer_traits<_VoidPtr>::template
396#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
397 rebind<const value_type>
398#else
399 rebind<const value_type>::other
400#endif
401 pointer;
402 typedef typename pointer_traits<pointer>::difference_type difference_type;
403
Howard Hinnant82894812010-09-22 16:48:34404 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28405 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03406 {
407#if _LIBCPP_DEBUG_LEVEL >= 2
408 __get_db()->__insert_i(this);
409#endif
410 }
Howard Hinnant211f0ee2011-01-28 23:46:28411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6dcaf3e2013-04-05 17:58:52412 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03413 : __ptr_(__p.__ptr_)
414 {
415#if _LIBCPP_DEBUG_LEVEL >= 2
416 __get_db()->__iterator_copy(this, &__p);
417#endif
418 }
419
420#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16421
Howard Hinnant82894812010-09-22 16:48:34422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03423 __list_const_iterator(const __list_const_iterator& __p)
424 : __ptr_(__p.__ptr_)
425 {
426 __get_db()->__iterator_copy(this, &__p);
427 }
428
429 _LIBCPP_INLINE_VISIBILITY
430 ~__list_const_iterator()
431 {
432 __get_db()->__erase_i(this);
433 }
434
435 _LIBCPP_INLINE_VISIBILITY
436 __list_const_iterator& operator=(const __list_const_iterator& __p)
437 {
438 if (this != &__p)
439 {
440 __get_db()->__iterator_copy(this, &__p);
441 __ptr_ = __p.__ptr_;
442 }
443 return *this;
444 }
445
446#endif // _LIBCPP_DEBUG_LEVEL >= 2
447 _LIBCPP_INLINE_VISIBILITY
448 reference operator*() const
449 {
450#if _LIBCPP_DEBUG_LEVEL >= 2
451 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
452 "Attempted to dereference a non-dereferenceable list::const_iterator");
453#endif
454 return __ptr_->__value_;
455 }
Howard Hinnant82894812010-09-22 16:48:34456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47457 pointer operator->() const
458 {
459#if _LIBCPP_DEBUG_LEVEL >= 2
460 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
461 "Attempted to dereference a non-dereferenceable list::iterator");
462#endif
463 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
464 }
Howard Hinnantbc8d3f92010-05-11 19:42:16465
Howard Hinnant82894812010-09-22 16:48:34466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03467 __list_const_iterator& operator++()
468 {
469#if _LIBCPP_DEBUG_LEVEL >= 2
470 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
471 "Attempted to increment non-incrementable list::const_iterator");
472#endif
473 __ptr_ = __ptr_->__next_;
474 return *this;
475 }
Howard Hinnant82894812010-09-22 16:48:34476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16477 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
478
Howard Hinnant82894812010-09-22 16:48:34479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03480 __list_const_iterator& operator--()
481 {
482#if _LIBCPP_DEBUG_LEVEL >= 2
483 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
484 "Attempted to decrement non-decrementable list::const_iterator");
485#endif
486 __ptr_ = __ptr_->__prev_;
487 return *this;
488 }
Howard Hinnant82894812010-09-22 16:48:34489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16490 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
491
Howard Hinnant82894812010-09-22 16:48:34492 friend _LIBCPP_INLINE_VISIBILITY
493 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03494 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03495 return __x.__ptr_ == __y.__ptr_;
496 }
Howard Hinnant82894812010-09-22 16:48:34497 friend _LIBCPP_INLINE_VISIBILITY
498 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16499 {return !(__x == __y);}
500};
501
502template <class _Tp, class _Alloc>
503class __list_imp
504{
505 __list_imp(const __list_imp&);
506 __list_imp& operator=(const __list_imp&);
507protected:
508 typedef _Tp value_type;
509 typedef _Alloc allocator_type;
510 typedef allocator_traits<allocator_type> __alloc_traits;
511 typedef typename __alloc_traits::size_type size_type;
512 typedef typename __alloc_traits::void_pointer __void_pointer;
513 typedef __list_iterator<value_type, __void_pointer> iterator;
514 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
515 typedef __list_node_base<value_type, __void_pointer> __node_base;
516 typedef __list_node<value_type, __void_pointer> __node;
Marshall Clow66302c62015-04-07 05:21:38517 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16518 typedef allocator_traits<__node_allocator> __node_alloc_traits;
519 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant29f74322013-06-25 16:08:47520 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16521 typedef typename __alloc_traits::pointer pointer;
522 typedef typename __alloc_traits::const_pointer const_pointer;
523 typedef typename __alloc_traits::difference_type difference_type;
524
Marshall Clow66302c62015-04-07 05:21:38525 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
Howard Hinnant29f74322013-06-25 16:08:47526 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
527
Howard Hinnantbc8d3f92010-05-11 19:42:16528 __node_base __end_;
529 __compressed_pair<size_type, __node_allocator> __size_alloc_;
530
Howard Hinnant82894812010-09-22 16:48:34531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28532 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28534 const size_type& __sz() const _NOEXCEPT
535 {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28537 __node_allocator& __node_alloc() _NOEXCEPT
538 {return __size_alloc_.second();}
Howard Hinnant82894812010-09-22 16:48:34539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28540 const __node_allocator& __node_alloc() const _NOEXCEPT
541 {return __size_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16542
Howard Hinnant29f74322013-06-25 16:08:47543 static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16544
Howard Hinnantc5607272011-06-03 17:30:28545 __list_imp()
546 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16547 __list_imp(const allocator_type& __a);
548 ~__list_imp();
Howard Hinnantc5607272011-06-03 17:30:28549 void clear() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28551 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16552
Howard Hinnant82894812010-09-22 16:48:34553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03554 iterator begin() _NOEXCEPT
555 {
556#if _LIBCPP_DEBUG_LEVEL >= 2
557 return iterator(__end_.__next_, this);
558#else
559 return iterator(__end_.__next_);
560#endif
561 }
Howard Hinnant82894812010-09-22 16:48:34562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28563 const_iterator begin() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03564 {
565#if _LIBCPP_DEBUG_LEVEL >= 2
566 return const_iterator(__end_.__next_, this);
567#else
568 return const_iterator(__end_.__next_);
569#endif
570 }
Howard Hinnant82894812010-09-22 16:48:34571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03572 iterator end() _NOEXCEPT
573 {
574#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47575 return iterator(static_cast<__node_pointer>(
576 pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03577#else
Howard Hinnant29f74322013-06-25 16:08:47578 return iterator(static_cast<__node_pointer>(
579 pointer_traits<__node_base_pointer>::pointer_to(__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:03580#endif
581 }
Howard Hinnant82894812010-09-22 16:48:34582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28583 const_iterator end() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03584 {
585#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47586 return const_iterator(static_cast<__node_const_pointer>(
587 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03588#else
Howard Hinnant29f74322013-06-25 16:08:47589 return const_iterator(static_cast<__node_const_pointer>(
590 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))));
Howard Hinnant1c3ec6d2011-09-27 23:55:03591#endif
592 }
Howard Hinnantbc8d3f92010-05-11 19:42:16593
Howard Hinnantc5607272011-06-03 17:30:28594 void swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56595#if _LIBCPP_STD_VER >= 14
596 _NOEXCEPT;
597#else
598 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
599 __is_nothrow_swappable<allocator_type>::value);
600#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16601
Howard Hinnant82894812010-09-22 16:48:34602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16603 void __copy_assign_alloc(const __list_imp& __c)
604 {__copy_assign_alloc(__c, integral_constant<bool,
605 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
606
Howard Hinnant82894812010-09-22 16:48:34607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16608 void __move_assign_alloc(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28609 _NOEXCEPT_(
610 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
611 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16612 {__move_assign_alloc(__c, integral_constant<bool,
613 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
614
615private:
Howard Hinnant82894812010-09-22 16:48:34616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16617 void __copy_assign_alloc(const __list_imp& __c, true_type)
618 {
619 if (__node_alloc() != __c.__node_alloc())
620 clear();
621 __node_alloc() = __c.__node_alloc();
622 }
623
Howard Hinnant82894812010-09-22 16:48:34624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16625 void __copy_assign_alloc(const __list_imp& __c, false_type)
626 {}
627
Howard Hinnant82894812010-09-22 16:48:34628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31629 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:28630 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16631 {
Howard Hinnant0949eed2011-06-30 21:18:19632 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16633 }
634
Howard Hinnant82894812010-09-22 16:48:34635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31636 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnantc5607272011-06-03 17:30:28637 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16638 {}
639};
640
641// Unlink nodes [__f, __l]
642template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34643inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16644void
Howard Hinnant29f74322013-06-25 16:08:47645__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
Howard Hinnantc5607272011-06-03 17:30:28646 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16647{
Howard Hinnant29f74322013-06-25 16:08:47648 __f->__prev_->__next_ = __l->__next_;
649 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16650}
651
652template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16654__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnantc5607272011-06-03 17:30:28655 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16656 : __size_alloc_(0)
657{
658}
659
660template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16662__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
663 : __size_alloc_(0, __node_allocator(__a))
664{
665}
666
667template <class _Tp, class _Alloc>
668__list_imp<_Tp, _Alloc>::~__list_imp()
669{
670 clear();
Howard Hinnant1c3ec6d2011-09-27 23:55:03671#if _LIBCPP_DEBUG_LEVEL >= 2
672 __get_db()->__erase_c(this);
673#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16674}
675
676template <class _Tp, class _Alloc>
677void
Howard Hinnantc5607272011-06-03 17:30:28678__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16679{
680 if (!empty())
681 {
682 __node_allocator& __na = __node_alloc();
Howard Hinnant1c3ec6d2011-09-27 23:55:03683 __node_pointer __f = __end_.__next_;
Howard Hinnant29f74322013-06-25 16:08:47684 __node_pointer __l = static_cast<__node_pointer>(
685 pointer_traits<__node_base_pointer>::pointer_to(__end_));
686 __unlink_nodes(__f, __l->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16687 __sz() = 0;
688 while (__f != __l)
689 {
Howard Hinnant29f74322013-06-25 16:08:47690 __node_pointer __n = __f;
Howard Hinnant1c3ec6d2011-09-27 23:55:03691 __f = __f->__next_;
Howard Hinnant29f74322013-06-25 16:08:47692 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
693 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16694 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03695#if _LIBCPP_DEBUG_LEVEL >= 2
696 __c_node* __c = __get_db()->__find_c_and_lock(this);
697 for (__i_node** __p = __c->end_; __p != __c->beg_; )
698 {
699 --__p;
700 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
701 if (__i->__ptr_ != __l)
702 {
703 (*__p)->__c_ = nullptr;
704 if (--__c->end_ != __p)
705 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
706 }
707 }
708 __get_db()->unlock();
709#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16710 }
711}
712
713template <class _Tp, class _Alloc>
714void
715__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56716#if _LIBCPP_STD_VER >= 14
717 _NOEXCEPT
718#else
719 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
720 __is_nothrow_swappable<allocator_type>::value)
721#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16722{
Howard Hinnant1c3ec6d2011-09-27 23:55:03723 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
724 this->__node_alloc() == __c.__node_alloc(),
725 "list::swap: Either propagate_on_container_swap must be true"
726 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19727 using _VSTD::swap;
Marshall Clow7d914d12015-07-13 20:04:56728 __swap_allocator(__node_alloc(), __c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16729 swap(__sz(), __c.__sz());
730 swap(__end_, __c.__end_);
731 if (__sz() == 0)
Marshall Clowea8ed832014-08-05 01:34:12732 __end_.__next_ = __end_.__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16733 else
Marshall Clowea8ed832014-08-05 01:34:12734 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16735 if (__c.__sz() == 0)
Marshall Clowea8ed832014-08-05 01:34:12736 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16737 else
Marshall Clowea8ed832014-08-05 01:34:12738 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
739
Howard Hinnant1c3ec6d2011-09-27 23:55:03740#if _LIBCPP_DEBUG_LEVEL >= 2
741 __libcpp_db* __db = __get_db();
742 __c_node* __cn1 = __db->__find_c_and_lock(this);
743 __c_node* __cn2 = __db->__find_c(&__c);
744 std::swap(__cn1->beg_, __cn2->beg_);
745 std::swap(__cn1->end_, __cn2->end_);
746 std::swap(__cn1->cap_, __cn2->cap_);
747 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
748 {
749 --__p;
750 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47751 if (__i->__ptr_ == static_cast<__node_pointer>(
752 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03753 {
754 __cn2->__add(*__p);
755 if (--__cn1->end_ != __p)
756 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
757 }
758 else
759 (*__p)->__c_ = __cn1;
760 }
761 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
762 {
763 --__p;
764 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:47765 if (__i->__ptr_ == static_cast<__node_pointer>(
766 pointer_traits<__node_base_pointer>::pointer_to(__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03767 {
768 __cn1->__add(*__p);
769 if (--__cn2->end_ != __p)
770 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
771 }
772 else
773 (*__p)->__c_ = __cn2;
774 }
775 __db->unlock();
776#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16777}
778
Marshall Clowceead9c2015-02-18 17:24:08779template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34780class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnantbc8d3f92010-05-11 19:42:16781 : private __list_imp<_Tp, _Alloc>
782{
783 typedef __list_imp<_Tp, _Alloc> base;
784 typedef typename base::__node __node;
785 typedef typename base::__node_allocator __node_allocator;
786 typedef typename base::__node_pointer __node_pointer;
787 typedef typename base::__node_alloc_traits __node_alloc_traits;
Howard Hinnant29f74322013-06-25 16:08:47788 typedef typename base::__node_base __node_base;
789 typedef typename base::__node_base_pointer __node_base_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16790
791public:
792 typedef _Tp value_type;
793 typedef _Alloc allocator_type;
794 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
795 "Invalid allocator::value_type");
796 typedef value_type& reference;
797 typedef const value_type& const_reference;
798 typedef typename base::pointer pointer;
799 typedef typename base::const_pointer const_pointer;
800 typedef typename base::size_type size_type;
801 typedef typename base::difference_type difference_type;
802 typedef typename base::iterator iterator;
803 typedef typename base::const_iterator const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19804 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
805 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16806
Howard Hinnant82894812010-09-22 16:48:34807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28808 list()
809 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant1c3ec6d2011-09-27 23:55:03810 {
811#if _LIBCPP_DEBUG_LEVEL >= 2
812 __get_db()->__insert_c(this);
813#endif
814 }
Howard Hinnant82894812010-09-22 16:48:34815 _LIBCPP_INLINE_VISIBILITY
Marshall Clow955f2c82013-09-08 19:11:51816 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant1c3ec6d2011-09-27 23:55:03817 {
818#if _LIBCPP_DEBUG_LEVEL >= 2
819 __get_db()->__insert_c(this);
820#endif
821 }
Marshall Clow955f2c82013-09-08 19:11:51822 explicit list(size_type __n);
823#if _LIBCPP_STD_VER > 11
824 explicit list(size_type __n, const allocator_type& __a);
825#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16826 list(size_type __n, const value_type& __x);
827 list(size_type __n, const value_type& __x, const allocator_type& __a);
828 template <class _InpIter>
829 list(_InpIter __f, _InpIter __l,
830 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
831 template <class _InpIter>
832 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
833 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
834
835 list(const list& __c);
836 list(const list& __c, const allocator_type& __a);
837 list& operator=(const list& __c);
Howard Hinnante3e32912011-08-12 21:56:02838#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16839 list(initializer_list<value_type> __il);
840 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02841#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant73d21a42010-09-04 23:28:19842#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc5607272011-06-03 17:30:28843 list(list&& __c)
844 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16845 list(list&& __c, const allocator_type& __a);
Howard Hinnantc5607272011-06-03 17:30:28846 list& operator=(list&& __c)
847 _NOEXCEPT_(
848 __node_alloc_traits::propagate_on_container_move_assignment::value &&
849 is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant73d21a42010-09-04 23:28:19850#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02851#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16853 list& operator=(initializer_list<value_type> __il)
854 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02855#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16856
857 template <class _InpIter>
858 void assign(_InpIter __f, _InpIter __l,
859 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
860 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02861#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16863 void assign(initializer_list<value_type> __il)
864 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02865#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16866
Howard Hinnantc5607272011-06-03 17:30:28867 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16868
Howard Hinnant82894812010-09-22 16:48:34869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28870 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant82894812010-09-22 16:48:34871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28872 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant82894812010-09-22 16:48:34873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28874 size_type max_size() const _NOEXCEPT
875 {return numeric_limits<difference_type>::max();}
Howard Hinnantbc8d3f92010-05-11 19:42:16876
Howard Hinnant82894812010-09-22 16:48:34877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28878 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28880 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28882 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28884 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28886 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28888 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16889
Howard Hinnant82894812010-09-22 16:48:34890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28891 reverse_iterator rbegin() _NOEXCEPT
892 {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28894 const_reverse_iterator rbegin() const _NOEXCEPT
895 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28897 reverse_iterator rend() _NOEXCEPT
898 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28900 const_reverse_iterator rend() const _NOEXCEPT
901 {return const_reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28903 const_reverse_iterator crbegin() const _NOEXCEPT
904 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28906 const_reverse_iterator crend() const _NOEXCEPT
907 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16908
Howard Hinnant82894812010-09-22 16:48:34909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03910 reference front()
911 {
912 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
913 return base::__end_.__next_->__value_;
914 }
Howard Hinnant82894812010-09-22 16:48:34915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03916 const_reference front() const
917 {
918 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
919 return base::__end_.__next_->__value_;
920 }
Howard Hinnant82894812010-09-22 16:48:34921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03922 reference back()
923 {
924 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
925 return base::__end_.__prev_->__value_;
926 }
Howard Hinnant82894812010-09-22 16:48:34927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03928 const_reference back() const
929 {
930 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
931 return base::__end_.__prev_->__value_;
932 }
Howard Hinnantbc8d3f92010-05-11 19:42:16933
Howard Hinnant73d21a42010-09-04 23:28:19934#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16935 void push_front(value_type&& __x);
936 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19937#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16938 template <class... _Args>
939 void emplace_front(_Args&&... __args);
940 template <class... _Args>
941 void emplace_back(_Args&&... __args);
942 template <class... _Args>
943 iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19944#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16945 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19946#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16947
948 void push_front(const value_type& __x);
949 void push_back(const value_type& __x);
950
951 iterator insert(const_iterator __p, const value_type& __x);
952 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
953 template <class _InpIter>
954 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
955 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02956#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16958 iterator insert(const_iterator __p, initializer_list<value_type> __il)
959 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02960#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16961
Howard Hinnant82894812010-09-22 16:48:34962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28963 void swap(list& __c)
Marshall Clow7d914d12015-07-13 20:04:56964#if _LIBCPP_STD_VER >= 14
965 _NOEXCEPT
966#else
Howard Hinnantc5607272011-06-03 17:30:28967 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
968 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clow7d914d12015-07-13 20:04:56969#endif
Howard Hinnantc5607272011-06-03 17:30:28970 {base::swap(__c);}
Howard Hinnant82894812010-09-22 16:48:34971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28972 void clear() _NOEXCEPT {base::clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16973
974 void pop_front();
975 void pop_back();
976
977 iterator erase(const_iterator __p);
978 iterator erase(const_iterator __f, const_iterator __l);
979
980 void resize(size_type __n);
981 void resize(size_type __n, const value_type& __x);
982
983 void splice(const_iterator __p, list& __c);
Howard Hinnant73d21a42010-09-04 23:28:19984#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16986 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
987#endif
988 void splice(const_iterator __p, list& __c, const_iterator __i);
Howard Hinnant73d21a42010-09-04 23:28:19989#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16991 void splice(const_iterator __p, list&& __c, const_iterator __i)
992 {splice(__p, __c, __i);}
Howard Hinnant73d21a42010-09-04 23:28:19993#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16994 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant73d21a42010-09-04 23:28:19995#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16997 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
998 {splice(__p, __c, __f, __l);}
Howard Hinnant73d21a42010-09-04 23:28:19999#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161000
1001 void remove(const value_type& __x);
1002 template <class _Pred> void remove_if(_Pred __pred);
1003 void unique();
1004 template <class _BinaryPred>
1005 void unique(_BinaryPred __binary_pred);
1006 void merge(list& __c);
Howard Hinnant73d21a42010-09-04 23:28:191007#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161009 void merge(list&& __c) {merge(__c);}
1010#endif
1011 template <class _Comp>
1012 void merge(list& __c, _Comp __comp);
Howard Hinnant73d21a42010-09-04 23:28:191013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161014 template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:341015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161016 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant73d21a42010-09-04 23:28:191017#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161018 void sort();
1019 template <class _Comp>
1020 void sort(_Comp __comp);
1021
Howard Hinnantc5607272011-06-03 17:30:281022 void reverse() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161023
Howard Hinnant1c3ec6d2011-09-27 23:55:031024 bool __invariants() const;
1025
1026#if _LIBCPP_DEBUG_LEVEL >= 2
1027
1028 bool __dereferenceable(const const_iterator* __i) const;
1029 bool __decrementable(const const_iterator* __i) const;
1030 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1031 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1032
1033#endif // _LIBCPP_DEBUG_LEVEL >= 2
1034
Howard Hinnantbc8d3f92010-05-11 19:42:161035private:
Marshall Clowea8ed832014-08-05 01:34:121036 static void __link_nodes (__node_pointer __p, __node_pointer __f, __node_pointer __l);
1037 void __link_nodes_at_front(__node_pointer __f, __node_pointer __l);
1038 void __link_nodes_at_back (__node_pointer __f, __node_pointer __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161039 iterator __iterator(size_type __n);
1040 template <class _Comp>
1041 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1042
Howard Hinnantc5607272011-06-03 17:30:281043 void __move_assign(list& __c, true_type)
1044 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:161045 void __move_assign(list& __c, false_type);
1046};
1047
1048// Link in nodes [__f, __l] just prior to __p
1049template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161051void
Howard Hinnant29f74322013-06-25 16:08:471052list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
Howard Hinnantbc8d3f92010-05-11 19:42:161053{
Howard Hinnant29f74322013-06-25 16:08:471054 __p->__prev_->__next_ = __f;
1055 __f->__prev_ = __p->__prev_;
1056 __p->__prev_ = __l;
1057 __l->__next_ = __p;
Howard Hinnantbc8d3f92010-05-11 19:42:161058}
1059
Marshall Clowea8ed832014-08-05 01:34:121060// Link in nodes [__f, __l] at the front of the list
1061template <class _Tp, class _Alloc>
1062inline _LIBCPP_INLINE_VISIBILITY
1063void
1064list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
1065{
Marshall Clowfca038e2014-08-08 15:35:521066 __f->__prev_ = base::__end_.__self();
1067 __l->__next_ = base::__end_.__next_;
1068 __l->__next_->__prev_ = __l;
1069 base::__end_.__next_ = __f;
Marshall Clowea8ed832014-08-05 01:34:121070}
1071
1072// Link in nodes [__f, __l] at the front of the list
1073template <class _Tp, class _Alloc>
1074inline _LIBCPP_INLINE_VISIBILITY
1075void
1076list<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
1077{
Marshall Clowfca038e2014-08-08 15:35:521078 __l->__next_ = base::__end_.__self();
1079 __f->__prev_ = base::__end_.__prev_;
1080 __f->__prev_->__next_ = __f;
1081 base::__end_.__prev_ = __l;
Marshall Clowea8ed832014-08-05 01:34:121082}
1083
1084
Howard Hinnantbc8d3f92010-05-11 19:42:161085template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161087typename list<_Tp, _Alloc>::iterator
1088list<_Tp, _Alloc>::__iterator(size_type __n)
1089{
Howard Hinnant0949eed2011-06-30 21:18:191090 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1091 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161092}
1093
1094template <class _Tp, class _Alloc>
1095list<_Tp, _Alloc>::list(size_type __n)
1096{
Howard Hinnant1c3ec6d2011-09-27 23:55:031097#if _LIBCPP_DEBUG_LEVEL >= 2
1098 __get_db()->__insert_c(this);
1099#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161100 for (; __n > 0; --__n)
Howard Hinnant73d21a42010-09-04 23:28:191101#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161102 emplace_back();
1103#else
1104 push_back(value_type());
1105#endif
1106}
1107
Marshall Clow955f2c82013-09-08 19:11:511108#if _LIBCPP_STD_VER > 11
1109template <class _Tp, class _Alloc>
1110list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1111{
1112#if _LIBCPP_DEBUG_LEVEL >= 2
1113 __get_db()->__insert_c(this);
1114#endif
1115 for (; __n > 0; --__n)
1116#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1117 emplace_back();
1118#else
1119 push_back(value_type());
1120#endif
1121}
1122#endif
1123
Howard Hinnantbc8d3f92010-05-11 19:42:161124template <class _Tp, class _Alloc>
1125list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1126{
Howard Hinnant1c3ec6d2011-09-27 23:55:031127#if _LIBCPP_DEBUG_LEVEL >= 2
1128 __get_db()->__insert_c(this);
1129#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161130 for (; __n > 0; --__n)
1131 push_back(__x);
1132}
1133
1134template <class _Tp, class _Alloc>
1135list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1136 : base(__a)
1137{
Howard Hinnant1c3ec6d2011-09-27 23:55:031138#if _LIBCPP_DEBUG_LEVEL >= 2
1139 __get_db()->__insert_c(this);
1140#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161141 for (; __n > 0; --__n)
1142 push_back(__x);
1143}
1144
1145template <class _Tp, class _Alloc>
1146template <class _InpIter>
1147list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1148 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1149{
Howard Hinnant1c3ec6d2011-09-27 23:55:031150#if _LIBCPP_DEBUG_LEVEL >= 2
1151 __get_db()->__insert_c(this);
1152#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161153 for (; __f != __l; ++__f)
1154 push_back(*__f);
1155}
1156
1157template <class _Tp, class _Alloc>
1158template <class _InpIter>
1159list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1160 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1161 : base(__a)
1162{
Howard Hinnant1c3ec6d2011-09-27 23:55:031163#if _LIBCPP_DEBUG_LEVEL >= 2
1164 __get_db()->__insert_c(this);
1165#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161166 for (; __f != __l; ++__f)
1167 push_back(*__f);
1168}
1169
1170template <class _Tp, class _Alloc>
1171list<_Tp, _Alloc>::list(const list& __c)
1172 : base(allocator_type(
1173 __node_alloc_traits::select_on_container_copy_construction(
1174 __c.__node_alloc())))
1175{
Howard Hinnant1c3ec6d2011-09-27 23:55:031176#if _LIBCPP_DEBUG_LEVEL >= 2
1177 __get_db()->__insert_c(this);
1178#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161179 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1180 push_back(*__i);
1181}
1182
1183template <class _Tp, class _Alloc>
1184list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1185 : base(__a)
1186{
Howard Hinnant1c3ec6d2011-09-27 23:55:031187#if _LIBCPP_DEBUG_LEVEL >= 2
1188 __get_db()->__insert_c(this);
1189#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161190 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1191 push_back(*__i);
1192}
1193
Howard Hinnante3e32912011-08-12 21:56:021194#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1195
Howard Hinnantbc8d3f92010-05-11 19:42:161196template <class _Tp, class _Alloc>
1197list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1198 : base(__a)
1199{
Howard Hinnant1c3ec6d2011-09-27 23:55:031200#if _LIBCPP_DEBUG_LEVEL >= 2
1201 __get_db()->__insert_c(this);
1202#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161203 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1204 __e = __il.end(); __i != __e; ++__i)
1205 push_back(*__i);
1206}
1207
1208template <class _Tp, class _Alloc>
1209list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1210{
Howard Hinnant1c3ec6d2011-09-27 23:55:031211#if _LIBCPP_DEBUG_LEVEL >= 2
1212 __get_db()->__insert_c(this);
1213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161214 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1215 __e = __il.end(); __i != __e; ++__i)
1216 push_back(*__i);
1217}
1218
Howard Hinnante3e32912011-08-12 21:56:021219#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1220
Howard Hinnantbc8d3f92010-05-11 19:42:161221template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161223list<_Tp, _Alloc>&
1224list<_Tp, _Alloc>::operator=(const list& __c)
1225{
1226 if (this != &__c)
1227 {
1228 base::__copy_assign_alloc(__c);
1229 assign(__c.begin(), __c.end());
1230 }
1231 return *this;
1232}
1233
Howard Hinnant73d21a42010-09-04 23:28:191234#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161235
1236template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161238list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281239 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnant0949eed2011-06-30 21:18:191240 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnantbc8d3f92010-05-11 19:42:161241{
Howard Hinnant1c3ec6d2011-09-27 23:55:031242#if _LIBCPP_DEBUG_LEVEL >= 2
1243 __get_db()->__insert_c(this);
1244#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161245 splice(end(), __c);
1246}
1247
1248template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341249inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161250list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1251 : base(__a)
1252{
Howard Hinnant1c3ec6d2011-09-27 23:55:031253#if _LIBCPP_DEBUG_LEVEL >= 2
1254 __get_db()->__insert_c(this);
1255#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161256 if (__a == __c.get_allocator())
1257 splice(end(), __c);
1258 else
1259 {
Howard Hinnant99968442011-11-29 18:15:501260 typedef move_iterator<iterator> _Ip;
1261 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161262 }
1263}
1264
1265template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161267list<_Tp, _Alloc>&
1268list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281269 _NOEXCEPT_(
1270 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1271 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161272{
1273 __move_assign(__c, integral_constant<bool,
1274 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1275 return *this;
1276}
1277
1278template <class _Tp, class _Alloc>
1279void
1280list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1281{
1282 if (base::__node_alloc() != __c.__node_alloc())
1283 {
Howard Hinnant99968442011-11-29 18:15:501284 typedef move_iterator<iterator> _Ip;
1285 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161286 }
1287 else
1288 __move_assign(__c, true_type());
1289}
1290
1291template <class _Tp, class _Alloc>
1292void
1293list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:281294 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161295{
1296 clear();
1297 base::__move_assign_alloc(__c);
1298 splice(end(), __c);
1299}
1300
Howard Hinnant73d21a42010-09-04 23:28:191301#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161302
1303template <class _Tp, class _Alloc>
1304template <class _InpIter>
1305void
1306list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1307 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1308{
1309 iterator __i = begin();
1310 iterator __e = end();
1311 for (; __f != __l && __i != __e; ++__f, ++__i)
1312 *__i = *__f;
1313 if (__i == __e)
1314 insert(__e, __f, __l);
1315 else
1316 erase(__i, __e);
1317}
1318
1319template <class _Tp, class _Alloc>
1320void
1321list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1322{
1323 iterator __i = begin();
1324 iterator __e = end();
1325 for (; __n > 0 && __i != __e; --__n, ++__i)
1326 *__i = __x;
1327 if (__i == __e)
1328 insert(__e, __n, __x);
1329 else
1330 erase(__i, __e);
1331}
1332
1333template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:341334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161335_Alloc
Howard Hinnantc5607272011-06-03 17:30:281336list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161337{
1338 return allocator_type(base::__node_alloc());
1339}
1340
1341template <class _Tp, class _Alloc>
1342typename list<_Tp, _Alloc>::iterator
1343list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1344{
Howard Hinnant1c3ec6d2011-09-27 23:55:031345#if _LIBCPP_DEBUG_LEVEL >= 2
1346 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1347 "list::insert(iterator, x) called with an iterator not"
1348 " referring to this list");
1349#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161350 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501351 typedef __allocator_destructor<__node_allocator> _Dp;
1352 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161353 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191354 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnant29f74322013-06-25 16:08:471355 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161356 ++base::__sz();
Howard Hinnant79a35572013-04-05 00:18:491357#if _LIBCPP_DEBUG_LEVEL >= 2
1358 return iterator(__hold.release(), this);
1359#else
Howard Hinnantbc8d3f92010-05-11 19:42:161360 return iterator(__hold.release());
Howard Hinnant79a35572013-04-05 00:18:491361#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161362}
1363
1364template <class _Tp, class _Alloc>
1365typename list<_Tp, _Alloc>::iterator
1366list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1367{
Howard Hinnant1c3ec6d2011-09-27 23:55:031368#if _LIBCPP_DEBUG_LEVEL >= 2
1369 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1370 "list::insert(iterator, n, x) called with an iterator not"
1371 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471372 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031373#else
Howard Hinnant29f74322013-06-25 16:08:471374 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031375#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161376 if (__n > 0)
1377 {
1378 size_type __ds = 0;
1379 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501380 typedef __allocator_destructor<__node_allocator> _Dp;
1381 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161382 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191383 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161384 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031385#if _LIBCPP_DEBUG_LEVEL >= 2
1386 __r = iterator(__hold.get(), this);
1387#else
Howard Hinnantbc8d3f92010-05-11 19:42:161388 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:031389#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161390 __hold.release();
1391 iterator __e = __r;
1392#ifndef _LIBCPP_NO_EXCEPTIONS
1393 try
1394 {
Howard Hinnant324bb032010-08-22 00:02:431395#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161396 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1397 {
1398 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191399 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161400 __e.__ptr_->__next_ = __hold.get();
1401 __hold->__prev_ = __e.__ptr_;
1402 __hold.release();
1403 }
1404#ifndef _LIBCPP_NO_EXCEPTIONS
1405 }
1406 catch (...)
1407 {
1408 while (true)
1409 {
Howard Hinnant0949eed2011-06-30 21:18:191410 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161411 __node_pointer __prev = __e.__ptr_->__prev_;
1412 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1413 if (__prev == 0)
1414 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031415#if _LIBCPP_DEBUG_LEVEL >= 2
1416 __e = iterator(__prev, this);
1417#else
Howard Hinnantbc8d3f92010-05-11 19:42:161418 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031419#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161420 }
1421 throw;
1422 }
Howard Hinnant324bb032010-08-22 00:02:431423#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471424 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161425 base::__sz() += __ds;
1426 }
1427 return __r;
1428}
1429
1430template <class _Tp, class _Alloc>
1431template <class _InpIter>
1432typename list<_Tp, _Alloc>::iterator
1433list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1434 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1435{
Howard Hinnant1c3ec6d2011-09-27 23:55:031436#if _LIBCPP_DEBUG_LEVEL >= 2
1437 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1438 "list::insert(iterator, range) called with an iterator not"
1439 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471440 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031441#else
Howard Hinnant29f74322013-06-25 16:08:471442 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031443#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161444 if (__f != __l)
1445 {
1446 size_type __ds = 0;
1447 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501448 typedef __allocator_destructor<__node_allocator> _Dp;
1449 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161450 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191451 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:161452 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031453#if _LIBCPP_DEBUG_LEVEL >= 2
1454 __r = iterator(__hold.get(), this);
1455#else
Howard Hinnantbc8d3f92010-05-11 19:42:161456 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:031457#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161458 __hold.release();
1459 iterator __e = __r;
1460#ifndef _LIBCPP_NO_EXCEPTIONS
1461 try
1462 {
Howard Hinnant324bb032010-08-22 00:02:431463#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier537876b2015-03-19 03:20:021464 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnantbc8d3f92010-05-11 19:42:161465 {
1466 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191467 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:161468 __e.__ptr_->__next_ = __hold.get();
1469 __hold->__prev_ = __e.__ptr_;
1470 __hold.release();
1471 }
1472#ifndef _LIBCPP_NO_EXCEPTIONS
1473 }
1474 catch (...)
1475 {
1476 while (true)
1477 {
Howard Hinnant0949eed2011-06-30 21:18:191478 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161479 __node_pointer __prev = __e.__ptr_->__prev_;
1480 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1481 if (__prev == 0)
1482 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031483#if _LIBCPP_DEBUG_LEVEL >= 2
1484 __e = iterator(__prev, this);
1485#else
Howard Hinnantbc8d3f92010-05-11 19:42:161486 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031487#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161488 }
1489 throw;
1490 }
Howard Hinnant324bb032010-08-22 00:02:431491#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471492 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161493 base::__sz() += __ds;
1494 }
1495 return __r;
1496}
1497
1498template <class _Tp, class _Alloc>
1499void
1500list<_Tp, _Alloc>::push_front(const value_type& __x)
1501{
1502 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501503 typedef __allocator_destructor<__node_allocator> _Dp;
1504 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191505 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Marshall Clowea8ed832014-08-05 01:34:121506 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161507 ++base::__sz();
1508 __hold.release();
1509}
1510
1511template <class _Tp, class _Alloc>
1512void
1513list<_Tp, _Alloc>::push_back(const value_type& __x)
1514{
1515 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501516 typedef __allocator_destructor<__node_allocator> _Dp;
1517 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191518 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Marshall Clowea8ed832014-08-05 01:34:121519 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161520 ++base::__sz();
1521 __hold.release();
1522}
1523
Howard Hinnant73d21a42010-09-04 23:28:191524#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161525
1526template <class _Tp, class _Alloc>
1527void
1528list<_Tp, _Alloc>::push_front(value_type&& __x)
1529{
1530 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501531 typedef __allocator_destructor<__node_allocator> _Dp;
1532 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191533 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Marshall Clowea8ed832014-08-05 01:34:121534 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161535 ++base::__sz();
1536 __hold.release();
1537}
1538
1539template <class _Tp, class _Alloc>
1540void
1541list<_Tp, _Alloc>::push_back(value_type&& __x)
1542{
1543 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501544 typedef __allocator_destructor<__node_allocator> _Dp;
1545 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191546 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Marshall Clowea8ed832014-08-05 01:34:121547 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161548 ++base::__sz();
1549 __hold.release();
1550}
1551
Howard Hinnant73d21a42010-09-04 23:28:191552#ifndef _LIBCPP_HAS_NO_VARIADICS
1553
Howard Hinnantbc8d3f92010-05-11 19:42:161554template <class _Tp, class _Alloc>
1555template <class... _Args>
1556void
1557list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1558{
1559 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501560 typedef __allocator_destructor<__node_allocator> _Dp;
1561 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191562 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Marshall Clowea8ed832014-08-05 01:34:121563 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161564 ++base::__sz();
1565 __hold.release();
1566}
1567
1568template <class _Tp, class _Alloc>
1569template <class... _Args>
1570void
1571list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1572{
1573 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501574 typedef __allocator_destructor<__node_allocator> _Dp;
1575 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191576 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Marshall Clowea8ed832014-08-05 01:34:121577 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161578 ++base::__sz();
1579 __hold.release();
1580}
1581
1582template <class _Tp, class _Alloc>
1583template <class... _Args>
1584typename list<_Tp, _Alloc>::iterator
1585list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1586{
Howard Hinnant79a35572013-04-05 00:18:491587#if _LIBCPP_DEBUG_LEVEL >= 2
1588 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1589 "list::emplace(iterator, args...) called with an iterator not"
1590 " referring to this list");
1591#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161592 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501593 typedef __allocator_destructor<__node_allocator> _Dp;
1594 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161595 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191596 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Howard Hinnant29f74322013-06-25 16:08:471597 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161598 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031599#if _LIBCPP_DEBUG_LEVEL >= 2
1600 return iterator(__hold.release(), this);
1601#else
Howard Hinnantbc8d3f92010-05-11 19:42:161602 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031603#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161604}
1605
Howard Hinnant73d21a42010-09-04 23:28:191606#endif // _LIBCPP_HAS_NO_VARIADICS
1607
Howard Hinnantbc8d3f92010-05-11 19:42:161608template <class _Tp, class _Alloc>
1609typename list<_Tp, _Alloc>::iterator
1610list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1611{
Howard Hinnant1c3ec6d2011-09-27 23:55:031612#if _LIBCPP_DEBUG_LEVEL >= 2
1613 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1614 "list::insert(iterator, x) called with an iterator not"
1615 " referring to this list");
1616#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161617 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501618 typedef __allocator_destructor<__node_allocator> _Dp;
1619 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161620 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191621 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Howard Hinnant29f74322013-06-25 16:08:471622 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:161623 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031624#if _LIBCPP_DEBUG_LEVEL >= 2
1625 return iterator(__hold.release(), this);
1626#else
Howard Hinnantbc8d3f92010-05-11 19:42:161627 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031628#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161629}
1630
Howard Hinnant73d21a42010-09-04 23:28:191631#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161632
1633template <class _Tp, class _Alloc>
1634void
1635list<_Tp, _Alloc>::pop_front()
1636{
Howard Hinnant1c3ec6d2011-09-27 23:55:031637 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161638 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471639 __node_pointer __n = base::__end_.__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161640 base::__unlink_nodes(__n, __n);
1641 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031642#if _LIBCPP_DEBUG_LEVEL >= 2
1643 __c_node* __c = __get_db()->__find_c_and_lock(this);
1644 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1645 {
1646 --__p;
1647 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471648 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031649 {
1650 (*__p)->__c_ = nullptr;
1651 if (--__c->end_ != __p)
1652 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1653 }
1654 }
1655 __get_db()->unlock();
1656#endif
Howard Hinnant29f74322013-06-25 16:08:471657 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1658 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161659}
1660
1661template <class _Tp, class _Alloc>
1662void
1663list<_Tp, _Alloc>::pop_back()
1664{
Dmitri Gribenkoc7a39cf2013-06-24 06:15:571665 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161666 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471667 __node_pointer __n = base::__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161668 base::__unlink_nodes(__n, __n);
1669 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031670#if _LIBCPP_DEBUG_LEVEL >= 2
1671 __c_node* __c = __get_db()->__find_c_and_lock(this);
1672 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1673 {
1674 --__p;
1675 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471676 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031677 {
1678 (*__p)->__c_ = nullptr;
1679 if (--__c->end_ != __p)
1680 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1681 }
1682 }
1683 __get_db()->unlock();
1684#endif
Howard Hinnant29f74322013-06-25 16:08:471685 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1686 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161687}
1688
1689template <class _Tp, class _Alloc>
1690typename list<_Tp, _Alloc>::iterator
1691list<_Tp, _Alloc>::erase(const_iterator __p)
1692{
Howard Hinnant1c3ec6d2011-09-27 23:55:031693#if _LIBCPP_DEBUG_LEVEL >= 2
1694 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1695 "list::erase(iterator) called with an iterator not"
1696 " referring to this list");
1697#endif
Howard Hinnant79a35572013-04-05 00:18:491698 _LIBCPP_ASSERT(__p != end(),
1699 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:161700 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471701 __node_pointer __n = __p.__ptr_;
1702 __node_pointer __r = __n->__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161703 base::__unlink_nodes(__n, __n);
1704 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031705#if _LIBCPP_DEBUG_LEVEL >= 2
1706 __c_node* __c = __get_db()->__find_c_and_lock(this);
1707 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1708 {
1709 --__p;
1710 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471711 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031712 {
1713 (*__p)->__c_ = nullptr;
1714 if (--__c->end_ != __p)
1715 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1716 }
1717 }
1718 __get_db()->unlock();
1719#endif
Howard Hinnant29f74322013-06-25 16:08:471720 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1721 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnant1c3ec6d2011-09-27 23:55:031722#if _LIBCPP_DEBUG_LEVEL >= 2
1723 return iterator(__r, this);
1724#else
Howard Hinnantbc8d3f92010-05-11 19:42:161725 return iterator(__r);
Howard Hinnant1c3ec6d2011-09-27 23:55:031726#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161727}
1728
1729template <class _Tp, class _Alloc>
1730typename list<_Tp, _Alloc>::iterator
1731list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1732{
Howard Hinnant1c3ec6d2011-09-27 23:55:031733#if _LIBCPP_DEBUG_LEVEL >= 2
1734 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1735 "list::erase(iterator, iterator) called with an iterator not"
1736 " referring to this list");
1737#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161738 if (__f != __l)
1739 {
1740 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471741 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:161742 while (__f != __l)
1743 {
Howard Hinnant29f74322013-06-25 16:08:471744 __node_pointer __n = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:161745 ++__f;
1746 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031747#if _LIBCPP_DEBUG_LEVEL >= 2
1748 __c_node* __c = __get_db()->__find_c_and_lock(this);
1749 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1750 {
1751 --__p;
1752 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471753 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031754 {
1755 (*__p)->__c_ = nullptr;
1756 if (--__c->end_ != __p)
1757 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1758 }
1759 }
1760 __get_db()->unlock();
1761#endif
Howard Hinnant29f74322013-06-25 16:08:471762 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1763 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161764 }
1765 }
Howard Hinnant1c3ec6d2011-09-27 23:55:031766#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:471767 return iterator(__l.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031768#else
Howard Hinnant29f74322013-06-25 16:08:471769 return iterator(__l.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031770#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161771}
1772
1773template <class _Tp, class _Alloc>
1774void
1775list<_Tp, _Alloc>::resize(size_type __n)
1776{
1777 if (__n < base::__sz())
1778 erase(__iterator(__n), end());
1779 else if (__n > base::__sz())
1780 {
1781 __n -= base::__sz();
1782 size_type __ds = 0;
1783 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501784 typedef __allocator_destructor<__node_allocator> _Dp;
1785 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161786 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191787 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161788 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031789#if _LIBCPP_DEBUG_LEVEL >= 2
1790 iterator __r = iterator(__hold.release(), this);
1791#else
Howard Hinnantbc8d3f92010-05-11 19:42:161792 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031793#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161794 iterator __e = __r;
1795#ifndef _LIBCPP_NO_EXCEPTIONS
1796 try
1797 {
Howard Hinnant324bb032010-08-22 00:02:431798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161799 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1800 {
1801 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191802 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161803 __e.__ptr_->__next_ = __hold.get();
1804 __hold->__prev_ = __e.__ptr_;
1805 __hold.release();
1806 }
1807#ifndef _LIBCPP_NO_EXCEPTIONS
1808 }
1809 catch (...)
1810 {
1811 while (true)
1812 {
Howard Hinnant0949eed2011-06-30 21:18:191813 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161814 __node_pointer __prev = __e.__ptr_->__prev_;
1815 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1816 if (__prev == 0)
1817 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031818#if _LIBCPP_DEBUG_LEVEL >= 2
1819 __e = iterator(__prev, this);
1820#else
Howard Hinnantbc8d3f92010-05-11 19:42:161821 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031822#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161823 }
1824 throw;
1825 }
Howard Hinnant324bb032010-08-22 00:02:431826#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clowea8ed832014-08-05 01:34:121827 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161828 base::__sz() += __ds;
1829 }
1830}
1831
1832template <class _Tp, class _Alloc>
1833void
1834list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1835{
1836 if (__n < base::__sz())
1837 erase(__iterator(__n), end());
1838 else if (__n > base::__sz())
1839 {
1840 __n -= base::__sz();
1841 size_type __ds = 0;
1842 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501843 typedef __allocator_destructor<__node_allocator> _Dp;
1844 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161845 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191846 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161847 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031848#if _LIBCPP_DEBUG_LEVEL >= 2
1849 iterator __r = iterator(__hold.release(), this);
1850#else
Howard Hinnantbc8d3f92010-05-11 19:42:161851 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:031852#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161853 iterator __e = __r;
1854#ifndef _LIBCPP_NO_EXCEPTIONS
1855 try
1856 {
Howard Hinnant324bb032010-08-22 00:02:431857#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161858 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1859 {
1860 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191861 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161862 __e.__ptr_->__next_ = __hold.get();
1863 __hold->__prev_ = __e.__ptr_;
1864 __hold.release();
1865 }
1866#ifndef _LIBCPP_NO_EXCEPTIONS
1867 }
1868 catch (...)
1869 {
1870 while (true)
1871 {
Howard Hinnant0949eed2011-06-30 21:18:191872 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Howard Hinnantbc8d3f92010-05-11 19:42:161873 __node_pointer __prev = __e.__ptr_->__prev_;
1874 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
1875 if (__prev == 0)
1876 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031877#if _LIBCPP_DEBUG_LEVEL >= 2
1878 __e = iterator(__prev, this);
1879#else
Howard Hinnantbc8d3f92010-05-11 19:42:161880 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031881#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161882 }
1883 throw;
1884 }
Howard Hinnant324bb032010-08-22 00:02:431885#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471886 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>::
1887 pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161888 base::__sz() += __ds;
Howard Hinnant324bb032010-08-22 00:02:431889 }
Howard Hinnantbc8d3f92010-05-11 19:42:161890}
1891
1892template <class _Tp, class _Alloc>
1893void
1894list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1895{
Howard Hinnant1c3ec6d2011-09-27 23:55:031896 _LIBCPP_ASSERT(this != &__c,
1897 "list::splice(iterator, list) called with this == &list");
1898#if _LIBCPP_DEBUG_LEVEL >= 2
1899 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1900 "list::splice(iterator, list) called with an iterator not"
1901 " referring to this list");
1902#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161903 if (!__c.empty())
1904 {
Howard Hinnant29f74322013-06-25 16:08:471905 __node_pointer __f = __c.__end_.__next_;
1906 __node_pointer __l = __c.__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161907 base::__unlink_nodes(__f, __l);
Howard Hinnant29f74322013-06-25 16:08:471908 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161909 base::__sz() += __c.__sz();
1910 __c.__sz() = 0;
Howard Hinnant1c3ec6d2011-09-27 23:55:031911#if _LIBCPP_DEBUG_LEVEL >= 2
1912 __libcpp_db* __db = __get_db();
1913 __c_node* __cn1 = __db->__find_c_and_lock(this);
1914 __c_node* __cn2 = __db->__find_c(&__c);
1915 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1916 {
1917 --__p;
1918 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471919 if (__i->__ptr_ != static_cast<__node_pointer>(
1920 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:031921 {
1922 __cn1->__add(*__p);
1923 (*__p)->__c_ = __cn1;
1924 if (--__cn2->end_ != __p)
1925 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1926 }
1927 }
1928 __db->unlock();
1929#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161930 }
1931}
1932
1933template <class _Tp, class _Alloc>
1934void
1935list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1936{
Howard Hinnant1c3ec6d2011-09-27 23:55:031937#if _LIBCPP_DEBUG_LEVEL >= 2
1938 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1939 "list::splice(iterator, list, iterator) called with first iterator not"
1940 " referring to this list");
1941 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1942 "list::splice(iterator, list, iterator) called with second iterator not"
1943 " referring to list argument");
1944 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
1945 "list::splice(iterator, list, iterator) called with second iterator not"
1946 " derefereceable");
1947#endif
1948 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnantbc8d3f92010-05-11 19:42:161949 {
Howard Hinnant29f74322013-06-25 16:08:471950 __node_pointer __f = __i.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:161951 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:471952 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:161953 --__c.__sz();
1954 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031955#if _LIBCPP_DEBUG_LEVEL >= 2
1956 __libcpp_db* __db = __get_db();
1957 __c_node* __cn1 = __db->__find_c_and_lock(this);
1958 __c_node* __cn2 = __db->__find_c(&__c);
1959 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
1960 {
1961 --__p;
1962 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471963 if (__j->__ptr_ == __f)
Howard Hinnant1c3ec6d2011-09-27 23:55:031964 {
1965 __cn1->__add(*__p);
1966 (*__p)->__c_ = __cn1;
1967 if (--__cn2->end_ != __p)
1968 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
1969 }
1970 }
1971 __db->unlock();
1972#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161973 }
1974}
1975
1976template <class _Tp, class _Alloc>
1977void
1978list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
1979{
Howard Hinnant1c3ec6d2011-09-27 23:55:031980#if _LIBCPP_DEBUG_LEVEL >= 2
1981 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1982 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
1983 " referring to this list");
1984 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
1985 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
1986 " referring to list argument");
1987 if (this == &__c)
1988 {
1989 for (const_iterator __i = __f; __i != __l; ++__i)
1990 _LIBCPP_ASSERT(__i != __p,
1991 "list::splice(iterator, list, iterator, iterator)"
1992 " called with the first iterator within the range"
1993 " of the second and third iterators");
1994 }
1995#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161996 if (__f != __l)
1997 {
1998 if (this != &__c)
1999 {
Howard Hinnant0949eed2011-06-30 21:18:192000 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162001 __c.__sz() -= __s;
2002 base::__sz() += __s;
2003 }
Howard Hinnant29f74322013-06-25 16:08:472004 __node_pointer __first = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162005 --__l;
Howard Hinnant29f74322013-06-25 16:08:472006 __node_pointer __last = __l.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162007 base::__unlink_nodes(__first, __last);
Howard Hinnant29f74322013-06-25 16:08:472008 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant1c3ec6d2011-09-27 23:55:032009#if _LIBCPP_DEBUG_LEVEL >= 2
2010 __libcpp_db* __db = __get_db();
2011 __c_node* __cn1 = __db->__find_c_and_lock(this);
2012 __c_node* __cn2 = __db->__find_c(&__c);
2013 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2014 {
2015 --__p;
2016 iterator* __j = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:472017 for (__node_pointer __k = __f.__ptr_;
Howard Hinnant1c3ec6d2011-09-27 23:55:032018 __k != __l.__ptr_; __k = __k->__next_)
2019 {
2020 if (__j->__ptr_ == __k)
2021 {
2022 __cn1->__add(*__p);
2023 (*__p)->__c_ = __cn1;
2024 if (--__cn2->end_ != __p)
2025 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2026 }
2027 }
2028 }
2029 __db->unlock();
2030#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162031 }
2032}
2033
2034template <class _Tp, class _Alloc>
2035void
2036list<_Tp, _Alloc>::remove(const value_type& __x)
2037{
Marshall Clowfca038e2014-08-08 15:35:522038 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2039 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnantbc8d3f92010-05-11 19:42:162040 {
2041 if (*__i == __x)
2042 {
Marshall Clowfca038e2014-08-08 15:35:522043 const_iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162044 for (; __j != __e && *__j == __x; ++__j)
2045 ;
Marshall Clowfca038e2014-08-08 15:35:522046 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2047 __i = __j;
Marshall Clowf0f1bca2014-08-04 17:32:252048 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122049 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162050 }
2051 else
2052 ++__i;
2053 }
2054}
2055
2056template <class _Tp, class _Alloc>
2057template <class _Pred>
2058void
2059list<_Tp, _Alloc>::remove_if(_Pred __pred)
2060{
2061 for (iterator __i = begin(), __e = end(); __i != __e;)
2062 {
2063 if (__pred(*__i))
2064 {
Howard Hinnant0949eed2011-06-30 21:18:192065 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162066 for (; __j != __e && __pred(*__j); ++__j)
2067 ;
2068 __i = erase(__i, __j);
Marshall Clowf0f1bca2014-08-04 17:32:252069 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122070 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162071 }
2072 else
2073 ++__i;
2074 }
2075}
2076
2077template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162079void
2080list<_Tp, _Alloc>::unique()
2081{
2082 unique(__equal_to<value_type>());
2083}
2084
2085template <class _Tp, class _Alloc>
2086template <class _BinaryPred>
2087void
2088list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2089{
2090 for (iterator __i = begin(), __e = end(); __i != __e;)
2091 {
Howard Hinnant0949eed2011-06-30 21:18:192092 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162093 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2094 ;
2095 if (++__i != __j)
2096 __i = erase(__i, __j);
2097 }
2098}
2099
2100template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342101inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162102void
2103list<_Tp, _Alloc>::merge(list& __c)
2104{
2105 merge(__c, __less<value_type>());
2106}
2107
2108template <class _Tp, class _Alloc>
2109template <class _Comp>
2110void
2111list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2112{
2113 if (this != &__c)
2114 {
2115 iterator __f1 = begin();
2116 iterator __e1 = end();
2117 iterator __f2 = __c.begin();
2118 iterator __e2 = __c.end();
2119 while (__f1 != __e1 && __f2 != __e2)
2120 {
2121 if (__comp(*__f2, *__f1))
2122 {
2123 size_type __ds = 1;
Howard Hinnant0949eed2011-06-30 21:18:192124 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162125 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2126 ;
2127 base::__sz() += __ds;
2128 __c.__sz() -= __ds;
Howard Hinnant29f74322013-06-25 16:08:472129 __node_pointer __f = __f2.__ptr_;
2130 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162131 __f2 = __m2;
2132 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192133 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472134 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162135 __f1 = __m2;
2136 }
2137 else
2138 ++__f1;
2139 }
2140 splice(__e1, __c);
Howard Hinnant1c3ec6d2011-09-27 23:55:032141#if _LIBCPP_DEBUG_LEVEL >= 2
2142 __libcpp_db* __db = __get_db();
2143 __c_node* __cn1 = __db->__find_c_and_lock(this);
2144 __c_node* __cn2 = __db->__find_c(&__c);
2145 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2146 {
2147 --__p;
2148 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:472149 if (__i->__ptr_ != static_cast<__node_pointer>(
2150 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:032151 {
2152 __cn1->__add(*__p);
2153 (*__p)->__c_ = __cn1;
2154 if (--__cn2->end_ != __p)
2155 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2156 }
2157 }
2158 __db->unlock();
2159#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162160 }
2161}
2162
2163template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342164inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162165void
2166list<_Tp, _Alloc>::sort()
2167{
2168 sort(__less<value_type>());
2169}
2170
2171template <class _Tp, class _Alloc>
2172template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:342173inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162174void
2175list<_Tp, _Alloc>::sort(_Comp __comp)
2176{
2177 __sort(begin(), end(), base::__sz(), __comp);
2178}
2179
2180template <class _Tp, class _Alloc>
2181template <class _Comp>
Howard Hinnantbc8d3f92010-05-11 19:42:162182typename list<_Tp, _Alloc>::iterator
2183list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2184{
2185 switch (__n)
2186 {
2187 case 0:
2188 case 1:
2189 return __f1;
2190 case 2:
2191 if (__comp(*--__e2, *__f1))
2192 {
Howard Hinnant29f74322013-06-25 16:08:472193 __node_pointer __f = __e2.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162194 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:472195 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:162196 return __e2;
2197 }
2198 return __f1;
2199 }
2200 size_type __n2 = __n / 2;
Howard Hinnant0949eed2011-06-30 21:18:192201 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnantbc8d3f92010-05-11 19:42:162202 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2203 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2204 if (__comp(*__f2, *__f1))
2205 {
Howard Hinnant0949eed2011-06-30 21:18:192206 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162207 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2208 ;
Howard Hinnant29f74322013-06-25 16:08:472209 __node_pointer __f = __f2.__ptr_;
2210 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162211 __r = __f2;
2212 __e1 = __f2 = __m2;
2213 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192214 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472215 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162216 __f1 = __m2;
2217 }
2218 else
2219 ++__f1;
2220 while (__f1 != __e1 && __f2 != __e2)
2221 {
2222 if (__comp(*__f2, *__f1))
2223 {
Howard Hinnant0949eed2011-06-30 21:18:192224 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162225 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2226 ;
Howard Hinnant29f74322013-06-25 16:08:472227 __node_pointer __f = __f2.__ptr_;
2228 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162229 if (__e1 == __f2)
2230 __e1 = __m2;
2231 __f2 = __m2;
2232 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192233 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472234 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162235 __f1 = __m2;
2236 }
2237 else
2238 ++__f1;
2239 }
2240 return __r;
2241}
2242
2243template <class _Tp, class _Alloc>
2244void
Howard Hinnantc5607272011-06-03 17:30:282245list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162246{
2247 if (base::__sz() > 1)
2248 {
2249 iterator __e = end();
Howard Hinnant1c3ec6d2011-09-27 23:55:032250 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2251 {
Howard Hinnant0949eed2011-06-30 21:18:192252 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant1c3ec6d2011-09-27 23:55:032253 __i.__ptr_ = __i.__ptr_->__prev_;
2254 }
Howard Hinnant0949eed2011-06-30 21:18:192255 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:162256 }
2257}
2258
2259template <class _Tp, class _Alloc>
Howard Hinnant1c3ec6d2011-09-27 23:55:032260bool
2261list<_Tp, _Alloc>::__invariants() const
2262{
2263 return size() == _VSTD::distance(begin(), end());
2264}
2265
2266#if _LIBCPP_DEBUG_LEVEL >= 2
2267
2268template <class _Tp, class _Alloc>
2269bool
2270list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2271{
Howard Hinnant29f74322013-06-25 16:08:472272 return __i->__ptr_ != static_cast<__node_pointer>(
2273 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:032274}
2275
2276template <class _Tp, class _Alloc>
2277bool
2278list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2279{
2280 return !empty() && __i->__ptr_ != base::__end_.__next_;
2281}
2282
2283template <class _Tp, class _Alloc>
2284bool
2285list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2286{
2287 return false;
2288}
2289
2290template <class _Tp, class _Alloc>
2291bool
2292list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2293{
2294 return false;
2295}
2296
2297#endif // _LIBCPP_DEBUG_LEVEL >= 2
2298
2299template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162301bool
2302operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2303{
Howard Hinnant0949eed2011-06-30 21:18:192304 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:162305}
2306
2307template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162309bool
2310operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2311{
Howard Hinnant0949eed2011-06-30 21:18:192312 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162313}
2314
2315template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162317bool
2318operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2319{
2320 return !(__x == __y);
2321}
2322
2323template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162325bool
2326operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2327{
2328 return __y < __x;
2329}
2330
2331template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162333bool
2334operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2335{
2336 return !(__x < __y);
2337}
2338
2339template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162341bool
2342operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2343{
2344 return !(__y < __x);
2345}
2346
2347template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162349void
2350swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnantc5607272011-06-03 17:30:282351 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162352{
2353 __x.swap(__y);
2354}
2355
2356_LIBCPP_END_NAMESPACE_STD
2357
2358#endif // _LIBCPP_LIST