blob: 14201a80e3488f9f782a703e6fa17963525fa67c [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001// -*- C++ -*-
2//===---------------------------- list ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:01 +00004// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00005//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00006// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00008//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_LIST
12#define _LIBCPP_LIST
13
14/*
15 list synopsis
16
17namespace std
18{
19
20template <class T, class Alloc = allocator<T> >
21class list
22{
23public:
24
25 // types:
26 typedef T value_type;
27 typedef Alloc allocator_type;
28 typedef typename allocator_type::reference reference;
29 typedef typename allocator_type::const_reference const_reference;
30 typedef typename allocator_type::pointer pointer;
31 typedef typename allocator_type::const_pointer const_pointer;
32 typedef implementation-defined iterator;
33 typedef implementation-defined const_iterator;
34 typedef implementation-defined size_type;
35 typedef implementation-defined difference_type;
36 typedef reverse_iterator<iterator> reverse_iterator;
37 typedef reverse_iterator<const_iterator> const_reverse_iterator;
38
Howard Hinnantc5607272011-06-03 17:30:28 +000039 list()
40 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000041 explicit list(const allocator_type& a);
42 explicit list(size_type n);
Marshall Clowe00f53b2013-09-09 18:19:45 +000043 explicit list(size_type n, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000044 list(size_type n, const value_type& value);
45 list(size_type n, const value_type& value, const allocator_type& a);
46 template <class Iter>
47 list(Iter first, Iter last);
48 template <class Iter>
49 list(Iter first, Iter last, const allocator_type& a);
50 list(const list& x);
51 list(const list&, const allocator_type& a);
Howard Hinnantc5607272011-06-03 17:30:28 +000052 list(list&& x)
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000054 list(list&&, const allocator_type& a);
55 list(initializer_list<value_type>);
56 list(initializer_list<value_type>, const allocator_type& a);
57
58 ~list();
59
60 list& operator=(const list& x);
Howard Hinnantc5607272011-06-03 17:30:28 +000061 list& operator=(list&& x)
62 noexcept(
63 allocator_type::propagate_on_container_move_assignment::value &&
64 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000065 list& operator=(initializer_list<value_type>);
66 template <class Iter>
67 void assign(Iter first, Iter last);
68 void assign(size_type n, const value_type& t);
69 void assign(initializer_list<value_type>);
70
Howard Hinnantc5607272011-06-03 17:30:28 +000071 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000072
Howard Hinnantc5607272011-06-03 17:30:28 +000073 iterator begin() noexcept;
74 const_iterator begin() const noexcept;
75 iterator end() noexcept;
76 const_iterator end() const noexcept;
77 reverse_iterator rbegin() noexcept;
78 const_reverse_iterator rbegin() const noexcept;
79 reverse_iterator rend() noexcept;
80 const_reverse_iterator rend() const noexcept;
81 const_iterator cbegin() const noexcept;
82 const_iterator cend() const noexcept;
83 const_reverse_iterator crbegin() const noexcept;
84 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000085
86 reference front();
87 const_reference front() const;
88 reference back();
89 const_reference back() const;
90
Howard Hinnantc5607272011-06-03 17:30:28 +000091 bool empty() const noexcept;
92 size_type size() const noexcept;
93 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000094
95 template <class... Args>
96 void emplace_front(Args&&... args);
97 void pop_front();
98 template <class... Args>
99 void emplace_back(Args&&... args);
100 void pop_back();
101 void push_front(const value_type& x);
102 void push_front(value_type&& x);
103 void push_back(const value_type& x);
104 void push_back(value_type&& x);
105 template <class... Args>
106 iterator emplace(const_iterator position, Args&&... args);
107 iterator insert(const_iterator position, const value_type& x);
108 iterator insert(const_iterator position, value_type&& x);
109 iterator insert(const_iterator position, size_type n, const value_type& x);
110 template <class Iter>
111 iterator insert(const_iterator position, Iter first, Iter last);
112 iterator insert(const_iterator position, initializer_list<value_type> il);
113
114 iterator erase(const_iterator position);
115 iterator erase(const_iterator position, const_iterator last);
116
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
119
Howard Hinnantc5607272011-06-03 17:30:28 +0000120 void swap(list&)
Marshall Clow7d914d12015-07-13 20:04:56 +0000121 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantc5607272011-06-03 17:30:28 +0000122 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000123
124 void splice(const_iterator position, list& x);
125 void splice(const_iterator position, list&& x);
126 void splice(const_iterator position, list& x, const_iterator i);
127 void splice(const_iterator position, list&& x, const_iterator i);
128 void splice(const_iterator position, list& x, const_iterator first,
129 const_iterator last);
130 void splice(const_iterator position, list&& x, const_iterator first,
131 const_iterator last);
132
133 void remove(const value_type& value);
134 template <class Pred> void remove_if(Pred pred);
135 void unique();
136 template <class BinaryPredicate>
137 void unique(BinaryPredicate binary_pred);
138 void merge(list& x);
139 void merge(list&& x);
140 template <class Compare>
141 void merge(list& x, Compare comp);
142 template <class Compare>
143 void merge(list&& x, Compare comp);
144 void sort();
145 template <class Compare>
146 void sort(Compare comp);
Howard Hinnantc5607272011-06-03 17:30:28 +0000147 void reverse() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000148};
149
150template <class T, class Alloc>
151 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
152template <class T, class Alloc>
153 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
154template <class T, class Alloc>
155 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
156template <class T, class Alloc>
157 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
158template <class T, class Alloc>
159 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
160template <class T, class Alloc>
161 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
162
163template <class T, class Alloc>
Howard Hinnantc5607272011-06-03 17:30:28 +0000164 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
165 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000166
167} // std
168
169*/
170
171#include <__config>
172
173#include <memory>
174#include <limits>
175#include <initializer_list>
176#include <iterator>
177#include <algorithm>
178
Howard Hinnant66c6f972011-11-29 16:45:27 +0000179#include <__undef_min_max>
180
Eric Fiselierb9536102014-08-10 23:53:08 +0000181#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35 +0000182
Howard Hinnant08e17472011-10-17 20:05:10 +0000183#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000184#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10 +0000185#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000186
187_LIBCPP_BEGIN_NAMESPACE_STD
188
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000189template <class _Tp, class _VoidPtr> struct __list_node;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000190
191template <class _Tp, class _VoidPtr>
192struct __list_node_base
193{
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700194 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
Howard Hinnant29f74322013-06-25 16:08:47 +0000200
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700201 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
208 pointer __prev_;
209 pointer __next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000210
Howard Hinnant82894812010-09-22 16:48:34 +0000211 _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700212 __list_node_base() : __prev_(__self()), __next_(__self()) {}
Marshall Clowea8ed832014-08-05 01:34:12 +0000213
214 _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700215 pointer __self()
216 {
217 return static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this));
Marshall Clowea8ed832014-08-05 01:34:12 +0000218 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000219};
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:08 +0000228template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnant2b1b2d42011-06-14 19:58:17 +0000229template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000230template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000231
232template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000233class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000234{
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700235 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
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000241
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700242 __node_pointer __ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000243
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000244#if _LIBCPP_DEBUG_LEVEL >= 2
245 _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700246 explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000247 : __ptr_(__p)
248 {
249 __get_db()->__insert_ic(this, __c);
250 }
251#else
Howard Hinnant82894812010-09-22 16:48:34 +0000252 _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700253 explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000254#endif
255
256
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000257
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;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700265 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000272 typedef typename pointer_traits<pointer>::difference_type difference_type;
273
Howard Hinnant82894812010-09-22 16:48:34 +0000274 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28 +0000275 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000276 {
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:28 +0000284 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000285 __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
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700317 return __ptr_->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000318 }
Howard Hinnant82894812010-09-22 16:48:34 +0000319 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47 +0000320 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
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700326 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
Howard Hinnant29f74322013-06-25 16:08:47 +0000327 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000328
Howard Hinnant82894812010-09-22 16:48:34 +0000329 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000330 __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:34 +0000339 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000340 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
341
Howard Hinnant82894812010-09-22 16:48:34 +0000342 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000343 __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:34 +0000352 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000353 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
354
Howard Hinnant82894812010-09-22 16:48:34 +0000355 friend _LIBCPP_INLINE_VISIBILITY
356 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000357 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000358 return __x.__ptr_ == __y.__ptr_;
359 }
Howard Hinnant82894812010-09-22 16:48:34 +0000360 friend _LIBCPP_INLINE_VISIBILITY
361 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000362 {return !(__x == __y);}
363};
364
365template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000366class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000367{
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700368 typedef typename pointer_traits<_VoidPtr>::template
369#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
370 rebind<__list_node<_Tp, _VoidPtr> > __node_pointer;
371#else
372 rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer;
373#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000374
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700375 __node_pointer __ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000376
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000377#if _LIBCPP_DEBUG_LEVEL >= 2
378 _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700379 explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000380 : __ptr_(__p)
381 {
382 __get_db()->__insert_ic(this, __c);
383 }
384#else
Howard Hinnant82894812010-09-22 16:48:34 +0000385 _LIBCPP_INLINE_VISIBILITY
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700386 explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000387#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000388
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;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700395 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;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000402 typedef typename pointer_traits<pointer>::difference_type difference_type;
403
Howard Hinnant82894812010-09-22 16:48:34 +0000404 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28 +0000405 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000406 {
407#if _LIBCPP_DEBUG_LEVEL >= 2
408 __get_db()->__insert_i(this);
409#endif
410 }
Howard Hinnant211f0ee2011-01-28 23:46:28 +0000411 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6dcaf3e2013-04-05 17:58:52 +0000412 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000413 : __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:16 +0000421
Howard Hinnant82894812010-09-22 16:48:34 +0000422 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000423 __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
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700454 return __ptr_->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000455 }
Howard Hinnant82894812010-09-22 16:48:34 +0000456 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47 +0000457 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
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700463 return pointer_traits<pointer>::pointer_to(__ptr_->__value_);
Howard Hinnant29f74322013-06-25 16:08:47 +0000464 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000465
Howard Hinnant82894812010-09-22 16:48:34 +0000466 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000467 __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:34 +0000476 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000477 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
478
Howard Hinnant82894812010-09-22 16:48:34 +0000479 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000480 __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:34 +0000489 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000490 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
491
Howard Hinnant82894812010-09-22 16:48:34 +0000492 friend _LIBCPP_INLINE_VISIBILITY
493 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000494 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000495 return __x.__ptr_ == __y.__ptr_;
496 }
Howard Hinnant82894812010-09-22 16:48:34 +0000497 friend _LIBCPP_INLINE_VISIBILITY
498 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000499 {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:38 +0000517 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000518 typedef allocator_traits<__node_allocator> __node_alloc_traits;
519 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant29f74322013-06-25 16:08:47 +0000520 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000521 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:38 +0000525 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
Howard Hinnant29f74322013-06-25 16:08:47 +0000526 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
527
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000528 __node_base __end_;
529 __compressed_pair<size_type, __node_allocator> __size_alloc_;
530
Howard Hinnant82894812010-09-22 16:48:34 +0000531 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000532 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34 +0000533 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000534 const size_type& __sz() const _NOEXCEPT
535 {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34 +0000536 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000537 __node_allocator& __node_alloc() _NOEXCEPT
538 {return __size_alloc_.second();}
Howard Hinnant82894812010-09-22 16:48:34 +0000539 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000540 const __node_allocator& __node_alloc() const _NOEXCEPT
541 {return __size_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000542
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700543 static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000544
Howard Hinnantc5607272011-06-03 17:30:28 +0000545 __list_imp()
546 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000547 __list_imp(const allocator_type& __a);
548 ~__list_imp();
Howard Hinnantc5607272011-06-03 17:30:28 +0000549 void clear() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34 +0000550 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000551 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000552
Howard Hinnant82894812010-09-22 16:48:34 +0000553 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000554 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:34 +0000562 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000563 const_iterator begin() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000564 {
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:34 +0000571 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000572 iterator end() _NOEXCEPT
573 {
574#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700575 return iterator(static_cast<__node_pointer>(
576 pointer_traits<__node_base_pointer>::pointer_to(__end_)), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000577#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700578 return iterator(static_cast<__node_pointer>(
579 pointer_traits<__node_base_pointer>::pointer_to(__end_)));
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000580#endif
581 }
Howard Hinnant82894812010-09-22 16:48:34 +0000582 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000583 const_iterator end() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000584 {
585#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700586 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:03 +0000588#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700589 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:03 +0000591#endif
592 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000593
Howard Hinnantc5607272011-06-03 17:30:28 +0000594 void swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56 +0000595#if _LIBCPP_STD_VER >= 14
596 _NOEXCEPT;
597#else
598 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
599 __is_nothrow_swappable<allocator_type>::value);
600#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000601
Howard Hinnant82894812010-09-22 16:48:34 +0000602 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000603 void __copy_assign_alloc(const __list_imp& __c)
604 {__copy_assign_alloc(__c, integral_constant<bool,
605 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
606
Howard Hinnant82894812010-09-22 16:48:34 +0000607 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000608 void __move_assign_alloc(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +0000609 _NOEXCEPT_(
610 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
611 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000612 {__move_assign_alloc(__c, integral_constant<bool,
613 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
614
615private:
Howard Hinnant82894812010-09-22 16:48:34 +0000616 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000617 void __copy_assign_alloc(const __list_imp& __c, true_type)
618 {
619 if (__node_alloc() != __c.__node_alloc())
620 clear();
621 __node_alloc() = __c.__node_alloc();
622 }
623
Howard Hinnant82894812010-09-22 16:48:34 +0000624 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000625 void __copy_assign_alloc(const __list_imp& __c, false_type)
626 {}
627
Howard Hinnant82894812010-09-22 16:48:34 +0000628 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000629 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:28 +0000630 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000631 {
Howard Hinnant0949eed2011-06-30 21:18:19 +0000632 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000633 }
634
Howard Hinnant82894812010-09-22 16:48:34 +0000635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31 +0000636 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnantc5607272011-06-03 17:30:28 +0000637 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000638 {}
639};
640
641// Unlink nodes [__f, __l]
642template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700643inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000644void
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700645__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l)
Howard Hinnantc5607272011-06-03 17:30:28 +0000646 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000647{
Howard Hinnant29f74322013-06-25 16:08:47 +0000648 __f->__prev_->__next_ = __l->__next_;
649 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000650}
651
652template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700653inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000654__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnantc5607272011-06-03 17:30:28 +0000655 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000656 : __size_alloc_(0)
657{
658}
659
660template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700661inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000662__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
663 : __size_alloc_(0, __node_allocator(__a))
664{
665}
666
667template <class _Tp, class _Alloc>
668__list_imp<_Tp, _Alloc>::~__list_imp()
669{
670 clear();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000671#if _LIBCPP_DEBUG_LEVEL >= 2
672 __get_db()->__erase_c(this);
673#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000674}
675
676template <class _Tp, class _Alloc>
677void
Howard Hinnantc5607272011-06-03 17:30:28 +0000678__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000679{
680 if (!empty())
681 {
682 __node_allocator& __na = __node_alloc();
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700683 __node_pointer __f = __end_.__next_;
684 __node_pointer __l = static_cast<__node_pointer>(
685 pointer_traits<__node_base_pointer>::pointer_to(__end_));
Howard Hinnant29f74322013-06-25 16:08:47 +0000686 __unlink_nodes(__f, __l->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000687 __sz() = 0;
688 while (__f != __l)
689 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700690 __node_pointer __n = __f;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000691 __f = __f->__next_;
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700692 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
693 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000694 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000695#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:16 +0000710 }
711}
712
713template <class _Tp, class _Alloc>
714void
715__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56 +0000716#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:16 +0000722{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000723 _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:19 +0000727 using _VSTD::swap;
Marshall Clow7d914d12015-07-13 20:04:56 +0000728 __swap_allocator(__node_alloc(), __c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000729 swap(__sz(), __c.__sz());
730 swap(__end_, __c.__end_);
731 if (__sz() == 0)
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700732 __end_.__next_ = __end_.__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000733 else
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700734 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000735 if (__c.__sz() == 0)
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700736 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_.__self();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000737 else
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700738 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_.__self();
Marshall Clowea8ed832014-08-05 01:34:12 +0000739
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000740#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_);
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700751 if (__i->__ptr_ == static_cast<__node_pointer>(
752 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000753 {
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_);
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700765 if (__i->__ptr_ == static_cast<__node_pointer>(
766 pointer_traits<__node_base_pointer>::pointer_to(__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000767 {
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:16 +0000777}
778
Marshall Clowceead9c2015-02-18 17:24:08 +0000779template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34 +0000780class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000781 : 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:47 +0000788 typedef typename base::__node_base __node_base;
789 typedef typename base::__node_base_pointer __node_base_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000790
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:19 +0000804 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
805 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000806
Howard Hinnant82894812010-09-22 16:48:34 +0000807 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000808 list()
809 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000810 {
811#if _LIBCPP_DEBUG_LEVEL >= 2
812 __get_db()->__insert_c(this);
813#endif
814 }
Howard Hinnant82894812010-09-22 16:48:34 +0000815 _LIBCPP_INLINE_VISIBILITY
Marshall Clow955f2c82013-09-08 19:11:51 +0000816 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000817 {
818#if _LIBCPP_DEBUG_LEVEL >= 2
819 __get_db()->__insert_c(this);
820#endif
821 }
Marshall Clow955f2c82013-09-08 19:11:51 +0000822 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:16 +0000826 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:02 +0000838#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000839 list(initializer_list<value_type> __il);
840 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02 +0000841#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant73d21a42010-09-04 23:28:19 +0000842#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantc5607272011-06-03 17:30:28 +0000843 list(list&& __c)
844 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000845 list(list&& __c, const allocator_type& __a);
Howard Hinnantc5607272011-06-03 17:30:28 +0000846 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:19 +0000850#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02 +0000851#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34 +0000852 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000853 list& operator=(initializer_list<value_type> __il)
854 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02 +0000855#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000856
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:02 +0000861#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34 +0000862 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000863 void assign(initializer_list<value_type> __il)
864 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000865#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000866
Howard Hinnantc5607272011-06-03 17:30:28 +0000867 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000868
Howard Hinnant82894812010-09-22 16:48:34 +0000869 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000870 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant82894812010-09-22 16:48:34 +0000871 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000872 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant82894812010-09-22 16:48:34 +0000873 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000874 size_type max_size() const _NOEXCEPT
875 {return numeric_limits<difference_type>::max();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000876
Howard Hinnant82894812010-09-22 16:48:34 +0000877 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000878 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34 +0000879 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000880 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34 +0000881 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000882 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34 +0000883 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000884 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34 +0000885 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000886 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34 +0000887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000888 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000889
Howard Hinnant82894812010-09-22 16:48:34 +0000890 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000891 reverse_iterator rbegin() _NOEXCEPT
892 {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34 +0000893 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000894 const_reverse_iterator rbegin() const _NOEXCEPT
895 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34 +0000896 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000897 reverse_iterator rend() _NOEXCEPT
898 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34 +0000899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000900 const_reverse_iterator rend() const _NOEXCEPT
901 {return const_reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34 +0000902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000903 const_reverse_iterator crbegin() const _NOEXCEPT
904 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34 +0000905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000906 const_reverse_iterator crend() const _NOEXCEPT
907 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000908
Howard Hinnant82894812010-09-22 16:48:34 +0000909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000910 reference front()
911 {
912 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700913 return base::__end_.__next_->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000914 }
Howard Hinnant82894812010-09-22 16:48:34 +0000915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000916 const_reference front() const
917 {
918 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700919 return base::__end_.__next_->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000920 }
Howard Hinnant82894812010-09-22 16:48:34 +0000921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000922 reference back()
923 {
924 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700925 return base::__end_.__prev_->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000926 }
Howard Hinnant82894812010-09-22 16:48:34 +0000927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000928 const_reference back() const
929 {
930 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Dan Albert1d4a1ed2016-05-25 22:36:09 -0700931 return base::__end_.__prev_->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +0000932 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000933
Howard Hinnant73d21a42010-09-04 23:28:19 +0000934#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000935 void push_front(value_type&& __x);
936 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000937#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000938 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:19 +0000944#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000945 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000946#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000947
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:02 +0000956#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34 +0000957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000958 iterator insert(const_iterator __p, initializer_list<value_type> __il)
959 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02 +0000960#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000961
Howard Hinnant82894812010-09-22 16:48:34 +0000962 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000963 void swap(list& __c)
Marshall Clow7d914d12015-07-13 20:04:56 +0000964#if _LIBCPP_STD_VER >= 14
965 _NOEXCEPT
966#else
Howard Hinnantc5607272011-06-03 17:30:28 +0000967 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
968 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clow7d914d12015-07-13 20:04:56 +0000969#endif
Howard Hinnantc5607272011-06-03 17:30:28 +0000970 {base::swap(__c);}
Howard Hinnant82894812010-09-22 16:48:34 +0000971 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28 +0000972 void clear() _NOEXCEPT {base::clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000973
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:19 +0000984#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +0000985 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000986 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:19 +0000989#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +0000990 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000991 void splice(const_iterator __p, list&& __c, const_iterator __i)
992 {splice(__p, __c, __i);}
Howard Hinnant73d21a42010-09-04 23:28:19 +0000993#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000994 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant73d21a42010-09-04 23:28:19 +0000995#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +0000996 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +0000997 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:19 +0000999#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001000
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:19 +00001007#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:34 +00001008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001009 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:19 +00001013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001014 template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:34 +00001015 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001016 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant73d21a42010-09-04 23:28:19 +00001017#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001018 void sort();
1019 template <class _Comp>
1020 void sort(_Comp __comp);
1021
Howard Hinnantc5607272011-06-03 17:30:28 +00001022 void reverse() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001023
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001024 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:16 +00001035private:
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001036 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:16 +00001039 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:28 +00001043 void __move_assign(list& __c, true_type)
1044 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001045 void __move_assign(list& __c, false_type);
1046};
1047
1048// Link in nodes [__f, __l] just prior to __p
1049template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001050inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001051void
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001052list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001053{
Howard Hinnant29f74322013-06-25 16:08:47 +00001054 __p->__prev_->__next_ = __f;
1055 __f->__prev_ = __p->__prev_;
1056 __p->__prev_ = __l;
1057 __l->__next_ = __p;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001058}
1059
Marshall Clowea8ed832014-08-05 01:34:12 +00001060// Link in nodes [__f, __l] at the front of the list
1061template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001062inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowea8ed832014-08-05 01:34:12 +00001063void
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001064list<_Tp, _Alloc>::__link_nodes_at_front(__node_pointer __f, __node_pointer __l)
Marshall Clowea8ed832014-08-05 01:34:12 +00001065{
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001066 __f->__prev_ = base::__end_.__self();
Marshall Clowfca038e2014-08-08 15:35:52 +00001067 __l->__next_ = base::__end_.__next_;
1068 __l->__next_->__prev_ = __l;
1069 base::__end_.__next_ = __f;
Marshall Clowea8ed832014-08-05 01:34:12 +00001070}
1071
1072// Link in nodes [__f, __l] at the front of the list
1073template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001074inline _LIBCPP_INLINE_VISIBILITY
Marshall Clowea8ed832014-08-05 01:34:12 +00001075void
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001076list<_Tp, _Alloc>::__link_nodes_at_back(__node_pointer __f, __node_pointer __l)
Marshall Clowea8ed832014-08-05 01:34:12 +00001077{
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001078 __l->__next_ = base::__end_.__self();
Marshall Clowfca038e2014-08-08 15:35:52 +00001079 __f->__prev_ = base::__end_.__prev_;
1080 __f->__prev_->__next_ = __f;
1081 base::__end_.__prev_ = __l;
Marshall Clowea8ed832014-08-05 01:34:12 +00001082}
1083
1084
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001085template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001086inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001087typename list<_Tp, _Alloc>::iterator
1088list<_Tp, _Alloc>::__iterator(size_type __n)
1089{
Howard Hinnant0949eed2011-06-30 21:18:19 +00001090 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1091 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001092}
1093
1094template <class _Tp, class _Alloc>
1095list<_Tp, _Alloc>::list(size_type __n)
1096{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001097#if _LIBCPP_DEBUG_LEVEL >= 2
1098 __get_db()->__insert_c(this);
1099#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001100 for (; __n > 0; --__n)
Howard Hinnant73d21a42010-09-04 23:28:19 +00001101#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001102 emplace_back();
1103#else
1104 push_back(value_type());
1105#endif
1106}
1107
Marshall Clow955f2c82013-09-08 19:11:51 +00001108#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:16 +00001124template <class _Tp, class _Alloc>
1125list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1126{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001127#if _LIBCPP_DEBUG_LEVEL >= 2
1128 __get_db()->__insert_c(this);
1129#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001130 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:03 +00001138#if _LIBCPP_DEBUG_LEVEL >= 2
1139 __get_db()->__insert_c(this);
1140#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001141 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:03 +00001150#if _LIBCPP_DEBUG_LEVEL >= 2
1151 __get_db()->__insert_c(this);
1152#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001153 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:03 +00001163#if _LIBCPP_DEBUG_LEVEL >= 2
1164 __get_db()->__insert_c(this);
1165#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001166 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:03 +00001176#if _LIBCPP_DEBUG_LEVEL >= 2
1177 __get_db()->__insert_c(this);
1178#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001179 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:03 +00001187#if _LIBCPP_DEBUG_LEVEL >= 2
1188 __get_db()->__insert_c(this);
1189#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001190 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1191 push_back(*__i);
1192}
1193
Howard Hinnante3e32912011-08-12 21:56:02 +00001194#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1195
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001196template <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:03 +00001200#if _LIBCPP_DEBUG_LEVEL >= 2
1201 __get_db()->__insert_c(this);
1202#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001203 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:03 +00001211#if _LIBCPP_DEBUG_LEVEL >= 2
1212 __get_db()->__insert_c(this);
1213#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001214 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:02 +00001219#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1220
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001221template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001222inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001223list<_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:19 +00001234#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001235
1236template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001237inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001238list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +00001239 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnant0949eed2011-06-30 21:18:19 +00001240 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001241{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001242#if _LIBCPP_DEBUG_LEVEL >= 2
1243 __get_db()->__insert_c(this);
1244#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001245 splice(end(), __c);
1246}
1247
1248template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001249inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001250list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1251 : base(__a)
1252{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001253#if _LIBCPP_DEBUG_LEVEL >= 2
1254 __get_db()->__insert_c(this);
1255#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001256 if (__a == __c.get_allocator())
1257 splice(end(), __c);
1258 else
1259 {
Howard Hinnant99968442011-11-29 18:15:50 +00001260 typedef move_iterator<iterator> _Ip;
1261 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001262 }
1263}
1264
1265template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001266inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001267list<_Tp, _Alloc>&
1268list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:28 +00001269 _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:16 +00001272{
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:50 +00001284 typedef move_iterator<iterator> _Ip;
1285 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001286 }
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:28 +00001294 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001295{
1296 clear();
1297 base::__move_assign_alloc(__c);
1298 splice(end(), __c);
1299}
1300
Howard Hinnant73d21a42010-09-04 23:28:19 +00001301#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001302
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>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001334inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001335_Alloc
Howard Hinnantc5607272011-06-03 17:30:28 +00001336list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001337{
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:03 +00001345#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:16 +00001350 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001351 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:16 +00001353 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001354 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001355 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001356 ++base::__sz();
Howard Hinnant79a35572013-04-05 00:18:49 +00001357#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001358 return iterator(__hold.release(), this);
Howard Hinnant79a35572013-04-05 00:18:49 +00001359#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001360 return iterator(__hold.release());
Howard Hinnant79a35572013-04-05 00:18:49 +00001361#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001362}
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:03 +00001368#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:47 +00001372 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001373#else
Howard Hinnant29f74322013-06-25 16:08:47 +00001374 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001375#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001376 if (__n > 0)
1377 {
1378 size_type __ds = 0;
1379 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001380 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:16 +00001382 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001383 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001384 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001385#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001386 __r = iterator(__hold.get(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001387#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001388 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001389#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001390 __hold.release();
1391 iterator __e = __r;
1392#ifndef _LIBCPP_NO_EXCEPTIONS
1393 try
1394 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001395#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001396 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1397 {
1398 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001399 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001400 __e.__ptr_->__next_ = __hold.get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001401 __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:19 +00001410 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001411 __node_pointer __prev = __e.__ptr_->__prev_;
1412 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001413 if (__prev == 0)
1414 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001415#if _LIBCPP_DEBUG_LEVEL >= 2
1416 __e = iterator(__prev, this);
1417#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001418 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001419#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001420 }
1421 throw;
1422 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001423#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:47 +00001424 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001425 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:03 +00001436#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:47 +00001440 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001441#else
Howard Hinnant29f74322013-06-25 16:08:47 +00001442 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001443#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001444 if (__f != __l)
1445 {
1446 size_type __ds = 0;
1447 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001448 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:16 +00001450 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001451 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001452 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001453#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001454 __r = iterator(__hold.get(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001455#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001456 __r = iterator(__hold.get());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001457#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001458 __hold.release();
1459 iterator __e = __r;
1460#ifndef _LIBCPP_NO_EXCEPTIONS
1461 try
1462 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001463#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier537876b2015-03-19 03:20:02 +00001464 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001465 {
1466 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001467 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001468 __e.__ptr_->__next_ = __hold.get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001469 __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:19 +00001478 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001479 __node_pointer __prev = __e.__ptr_->__prev_;
1480 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001481 if (__prev == 0)
1482 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001483#if _LIBCPP_DEBUG_LEVEL >= 2
1484 __e = iterator(__prev, this);
1485#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001486 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001487#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001488 }
1489 throw;
1490 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001491#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:47 +00001492 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001493 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:50 +00001503 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:19 +00001505 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001506 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001507 ++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:50 +00001516 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:19 +00001518 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001519 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001520 ++base::__sz();
1521 __hold.release();
1522}
1523
Howard Hinnant73d21a42010-09-04 23:28:19 +00001524#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001525
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:50 +00001531 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:19 +00001533 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001534 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001535 ++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:50 +00001544 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:19 +00001546 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001547 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001548 ++base::__sz();
1549 __hold.release();
1550}
1551
Howard Hinnant73d21a42010-09-04 23:28:19 +00001552#ifndef _LIBCPP_HAS_NO_VARIADICS
1553
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001554template <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:50 +00001560 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:19 +00001562 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001563 __link_nodes_at_front(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001564 ++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:50 +00001574 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:19 +00001576 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001577 __link_nodes_at_back(__hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001578 ++base::__sz();
1579 __hold.release();
1580}
1581
1582template <class _Tp, class _Alloc>
1583template <class... _Args>
1584typename list<_Tp, _Alloc>::iterator
1585list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1586{
Howard Hinnant79a35572013-04-05 00:18:49 +00001587#if _LIBCPP_DEBUG_LEVEL >= 2
1588 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1589 "list::emplace(iterator, args...) called with an iterator not"
1590 " referring to this list");
1591#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001592 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001593 typedef __allocator_destructor<__node_allocator> _Dp;
1594 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001595 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001596 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001597 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001598 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001599#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001600 return iterator(__hold.release(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001601#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001602 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001603#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001604}
1605
Howard Hinnant73d21a42010-09-04 23:28:19 +00001606#endif // _LIBCPP_HAS_NO_VARIADICS
1607
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001608template <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:03 +00001612#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:16 +00001617 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:50 +00001618 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:16 +00001620 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001621 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001622 __link_nodes(__p.__ptr_, __hold.get(), __hold.get());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001623 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001624#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001625 return iterator(__hold.release(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001626#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001627 return iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001628#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001629}
1630
Howard Hinnant73d21a42010-09-04 23:28:19 +00001631#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001632
1633template <class _Tp, class _Alloc>
1634void
1635list<_Tp, _Alloc>::pop_front()
1636{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001637 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001638 __node_allocator& __na = base::__node_alloc();
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001639 __node_pointer __n = base::__end_.__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001640 base::__unlink_nodes(__n, __n);
1641 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001642#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:47 +00001648 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001649 {
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
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001657 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1658 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001659}
1660
1661template <class _Tp, class _Alloc>
1662void
1663list<_Tp, _Alloc>::pop_back()
1664{
Dmitri Gribenkoc7a39cf2013-06-24 06:15:57 +00001665 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001666 __node_allocator& __na = base::__node_alloc();
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001667 __node_pointer __n = base::__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001668 base::__unlink_nodes(__n, __n);
1669 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001670#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:47 +00001676 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001677 {
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
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001685 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1686 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001687}
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:03 +00001693#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:49 +00001698 _LIBCPP_ASSERT(__p != end(),
1699 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001700 __node_allocator& __na = base::__node_alloc();
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001701 __node_pointer __n = __p.__ptr_;
1702 __node_pointer __r = __n->__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001703 base::__unlink_nodes(__n, __n);
1704 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001705#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:47 +00001711 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001712 {
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
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001720 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1721 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001722#if _LIBCPP_DEBUG_LEVEL >= 2
1723 return iterator(__r, this);
1724#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001725 return iterator(__r);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001726#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001727}
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:03 +00001733#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:16 +00001738 if (__f != __l)
1739 {
1740 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:47 +00001741 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001742 while (__f != __l)
1743 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001744 __node_pointer __n = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001745 ++__f;
1746 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001747#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:47 +00001753 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001754 {
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
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001762 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_));
1763 __node_alloc_traits::deallocate(__na, __n, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001764 }
1765 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001766#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:47 +00001767 return iterator(__l.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001768#else
Howard Hinnant29f74322013-06-25 16:08:47 +00001769 return iterator(__l.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001770#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001771}
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:50 +00001784 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:16 +00001786 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001787 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001788 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001789#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001790 iterator __r = iterator(__hold.release(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001791#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001792 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001793#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001794 iterator __e = __r;
1795#ifndef _LIBCPP_NO_EXCEPTIONS
1796 try
1797 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001798#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001799 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1800 {
1801 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001802 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001803 __e.__ptr_->__next_ = __hold.get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001804 __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:19 +00001813 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001814 __node_pointer __prev = __e.__ptr_->__prev_;
1815 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001816 if (__prev == 0)
1817 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001818#if _LIBCPP_DEBUG_LEVEL >= 2
1819 __e = iterator(__prev, this);
1820#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001821 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001822#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001823 }
1824 throw;
1825 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001826#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clowea8ed832014-08-05 01:34:12 +00001827 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001828 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:50 +00001843 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:16 +00001845 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:19 +00001846 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001847 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001848#if _LIBCPP_DEBUG_LEVEL >= 2
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001849 iterator __r = iterator(__hold.release(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001850#else
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001851 iterator __r = iterator(__hold.release());
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001852#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001853 iterator __e = __r;
1854#ifndef _LIBCPP_NO_EXCEPTIONS
1855 try
1856 {
Howard Hinnant324bb032010-08-22 00:02:43 +00001857#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001858 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1859 {
1860 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:19 +00001861 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001862 __e.__ptr_->__next_ = __hold.get();
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001863 __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:19 +00001872 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001873 __node_pointer __prev = __e.__ptr_->__prev_;
1874 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001875 if (__prev == 0)
1876 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001877#if _LIBCPP_DEBUG_LEVEL >= 2
1878 __e = iterator(__prev, this);
1879#else
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001880 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001881#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001882 }
1883 throw;
1884 }
Howard Hinnant324bb032010-08-22 00:02:43 +00001885#endif // _LIBCPP_NO_EXCEPTIONS
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001886 __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:16 +00001888 base::__sz() += __ds;
Howard Hinnant324bb032010-08-22 00:02:43 +00001889 }
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001890}
1891
1892template <class _Tp, class _Alloc>
1893void
1894list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1895{
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001896 _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:16 +00001903 if (!__c.empty())
1904 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001905 __node_pointer __f = __c.__end_.__next_;
1906 __node_pointer __l = __c.__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001907 base::__unlink_nodes(__f, __l);
Howard Hinnant29f74322013-06-25 16:08:47 +00001908 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001909 base::__sz() += __c.__sz();
1910 __c.__sz() = 0;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001911#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_);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001919 if (__i->__ptr_ != static_cast<__node_pointer>(
1920 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001921 {
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:16 +00001930 }
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:03 +00001937#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:16 +00001949 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -07001950 __node_pointer __f = __i.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001951 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:47 +00001952 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001953 --__c.__sz();
1954 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001955#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:47 +00001963 if (__j->__ptr_ == __f)
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00001964 {
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:16 +00001973 }
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:03 +00001980#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:16 +00001996 if (__f != __l)
1997 {
1998 if (this != &__c)
1999 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002000 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002001 __c.__sz() -= __s;
2002 base::__sz() += __s;
2003 }
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002004 __node_pointer __first = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002005 --__l;
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002006 __node_pointer __last = __l.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002007 base::__unlink_nodes(__first, __last);
Howard Hinnant29f74322013-06-25 16:08:47 +00002008 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002009#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_);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002017 for (__node_pointer __k = __f.__ptr_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002018 __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:16 +00002031 }
2032}
2033
2034template <class _Tp, class _Alloc>
2035void
2036list<_Tp, _Alloc>::remove(const value_type& __x)
2037{
Marshall Clowfca038e2014-08-08 15:35:52 +00002038 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:16 +00002040 {
2041 if (*__i == __x)
2042 {
Marshall Clowfca038e2014-08-08 15:35:52 +00002043 const_iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002044 for (; __j != __e && *__j == __x; ++__j)
2045 ;
Marshall Clowfca038e2014-08-08 15:35:52 +00002046 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2047 __i = __j;
Marshall Clowf0f1bca2014-08-04 17:32:25 +00002048 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:12 +00002049 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002050 }
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:19 +00002065 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002066 for (; __j != __e && __pred(*__j); ++__j)
2067 ;
2068 __i = erase(__i, __j);
Marshall Clowf0f1bca2014-08-04 17:32:25 +00002069 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:12 +00002070 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002071 }
2072 else
2073 ++__i;
2074 }
2075}
2076
2077template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002078inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002079void
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:19 +00002092 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002093 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>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002101inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002102void
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:19 +00002124 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002125 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2126 ;
2127 base::__sz() += __ds;
2128 __c.__sz() -= __ds;
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002129 __node_pointer __f = __f2.__ptr_;
2130 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002131 __f2 = __m2;
2132 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002133 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:47 +00002134 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002135 __f1 = __m2;
2136 }
2137 else
2138 ++__f1;
2139 }
2140 splice(__e1, __c);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002141#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_);
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002149 if (__i->__ptr_ != static_cast<__node_pointer>(
2150 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)))
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002151 {
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:16 +00002160 }
2161}
2162
2163template <class _Tp, class _Alloc>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002164inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002165void
2166list<_Tp, _Alloc>::sort()
2167{
2168 sort(__less<value_type>());
2169}
2170
2171template <class _Tp, class _Alloc>
2172template <class _Comp>
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002173inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002174void
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:16 +00002182typename 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 {
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002193 __node_pointer __f = __e2.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002194 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:47 +00002195 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002196 return __e2;
2197 }
2198 return __f1;
2199 }
2200 size_type __n2 = __n / 2;
Howard Hinnant0949eed2011-06-30 21:18:19 +00002201 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002202 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:19 +00002206 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002207 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2208 ;
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002209 __node_pointer __f = __f2.__ptr_;
2210 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002211 __r = __f2;
2212 __e1 = __f2 = __m2;
2213 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002214 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:47 +00002215 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002216 __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:19 +00002224 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002225 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2226 ;
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002227 __node_pointer __f = __f2.__ptr_;
2228 __node_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002229 if (__e1 == __f2)
2230 __e1 = __m2;
2231 __f2 = __m2;
2232 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:19 +00002233 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:47 +00002234 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002235 __f1 = __m2;
2236 }
2237 else
2238 ++__f1;
2239 }
2240 return __r;
2241}
2242
2243template <class _Tp, class _Alloc>
2244void
Howard Hinnantc5607272011-06-03 17:30:28 +00002245list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002246{
2247 if (base::__sz() > 1)
2248 {
2249 iterator __e = end();
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002250 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2251 {
Howard Hinnant0949eed2011-06-30 21:18:19 +00002252 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002253 __i.__ptr_ = __i.__ptr_->__prev_;
2254 }
Howard Hinnant0949eed2011-06-30 21:18:19 +00002255 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002256 }
2257}
2258
2259template <class _Tp, class _Alloc>
Howard Hinnant1c3ec6d2011-09-27 23:55:03 +00002260bool
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{
Dan Albert1d4a1ed2016-05-25 22:36:09 -07002272 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:03 +00002274}
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:34 +00002300inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002301bool
2302operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2303{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002304 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002305}
2306
2307template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002308inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002309bool
2310operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2311{
Howard Hinnant0949eed2011-06-30 21:18:19 +00002312 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002313}
2314
2315template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:34 +00002316inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002317bool
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:34 +00002324inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002325bool
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:34 +00002332inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002333bool
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:34 +00002340inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002341bool
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:34 +00002348inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002349void
2350swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnantc5607272011-06-03 17:30:28 +00002351 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00002352{
2353 __x.swap(__y);
2354}
2355
2356_LIBCPP_END_NAMESPACE_STD
2357
2358#endif // _LIBCPP_LIST