blob: 98843d61f272fd5e102253f9fb82fed0b1433018 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:161// -*- C++ -*-
2//===---------------------------- list ------------------------------------===//
3//
Howard Hinnantf5256e12010-05-11 21:36:014// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:165//
Howard Hinnantb64f8b02010-11-16 22:09:026// This file is dual licensed under the MIT and the University of Illinois Open
7// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantbc8d3f92010-05-11 19:42:168//
9//===----------------------------------------------------------------------===//
10
11#ifndef _LIBCPP_LIST
12#define _LIBCPP_LIST
13
14/*
15 list synopsis
16
17namespace std
18{
19
20template <class T, class Alloc = allocator<T> >
21class list
22{
23public:
24
25 // types:
26 typedef T value_type;
27 typedef Alloc allocator_type;
28 typedef typename allocator_type::reference reference;
29 typedef typename allocator_type::const_reference const_reference;
30 typedef typename allocator_type::pointer pointer;
31 typedef typename allocator_type::const_pointer const_pointer;
32 typedef implementation-defined iterator;
33 typedef implementation-defined const_iterator;
34 typedef implementation-defined size_type;
35 typedef implementation-defined difference_type;
36 typedef reverse_iterator<iterator> reverse_iterator;
37 typedef reverse_iterator<const_iterator> const_reverse_iterator;
38
Howard Hinnantc5607272011-06-03 17:30:2839 list()
40 noexcept(is_nothrow_default_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1641 explicit list(const allocator_type& a);
42 explicit list(size_type n);
Marshall Clowe00f53b2013-09-09 18:19:4543 explicit list(size_type n, const allocator_type& a); // C++14
Howard Hinnantbc8d3f92010-05-11 19:42:1644 list(size_type n, const value_type& value);
45 list(size_type n, const value_type& value, const allocator_type& a);
46 template <class Iter>
47 list(Iter first, Iter last);
48 template <class Iter>
49 list(Iter first, Iter last, const allocator_type& a);
50 list(const list& x);
51 list(const list&, const allocator_type& a);
Howard Hinnantc5607272011-06-03 17:30:2852 list(list&& x)
53 noexcept(is_nothrow_move_constructible<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1654 list(list&&, const allocator_type& a);
55 list(initializer_list<value_type>);
56 list(initializer_list<value_type>, const allocator_type& a);
57
58 ~list();
59
60 list& operator=(const list& x);
Howard Hinnantc5607272011-06-03 17:30:2861 list& operator=(list&& x)
62 noexcept(
63 allocator_type::propagate_on_container_move_assignment::value &&
64 is_nothrow_move_assignable<allocator_type>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:1665 list& operator=(initializer_list<value_type>);
66 template <class Iter>
67 void assign(Iter first, Iter last);
68 void assign(size_type n, const value_type& t);
69 void assign(initializer_list<value_type>);
70
Howard Hinnantc5607272011-06-03 17:30:2871 allocator_type get_allocator() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1672
Howard Hinnantc5607272011-06-03 17:30:2873 iterator begin() noexcept;
74 const_iterator begin() const noexcept;
75 iterator end() noexcept;
76 const_iterator end() const noexcept;
77 reverse_iterator rbegin() noexcept;
78 const_reverse_iterator rbegin() const noexcept;
79 reverse_iterator rend() noexcept;
80 const_reverse_iterator rend() const noexcept;
81 const_iterator cbegin() const noexcept;
82 const_iterator cend() const noexcept;
83 const_reverse_iterator crbegin() const noexcept;
84 const_reverse_iterator crend() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1685
86 reference front();
87 const_reference front() const;
88 reference back();
89 const_reference back() const;
90
Howard Hinnantc5607272011-06-03 17:30:2891 bool empty() const noexcept;
92 size_type size() const noexcept;
93 size_type max_size() const noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:1694
95 template <class... Args>
Eric Fiselier3816ef92016-07-21 03:20:1796 reference emplace_front(Args&&... args);
Howard Hinnantbc8d3f92010-05-11 19:42:1697 void pop_front();
98 template <class... Args>
Eric Fiselier3816ef92016-07-21 03:20:1799 reference emplace_back(Args&&... args);
Howard Hinnantbc8d3f92010-05-11 19:42:16100 void pop_back();
101 void push_front(const value_type& x);
102 void push_front(value_type&& x);
103 void push_back(const value_type& x);
104 void push_back(value_type&& x);
105 template <class... Args>
106 iterator emplace(const_iterator position, Args&&... args);
107 iterator insert(const_iterator position, const value_type& x);
108 iterator insert(const_iterator position, value_type&& x);
109 iterator insert(const_iterator position, size_type n, const value_type& x);
110 template <class Iter>
111 iterator insert(const_iterator position, Iter first, Iter last);
112 iterator insert(const_iterator position, initializer_list<value_type> il);
113
114 iterator erase(const_iterator position);
115 iterator erase(const_iterator position, const_iterator last);
116
117 void resize(size_type sz);
118 void resize(size_type sz, const value_type& c);
119
Howard Hinnantc5607272011-06-03 17:30:28120 void swap(list&)
Marshall Clow7d914d12015-07-13 20:04:56121 noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17
Howard Hinnantc5607272011-06-03 17:30:28122 void clear() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16123
124 void splice(const_iterator position, list& x);
125 void splice(const_iterator position, list&& x);
126 void splice(const_iterator position, list& x, const_iterator i);
127 void splice(const_iterator position, list&& x, const_iterator i);
128 void splice(const_iterator position, list& x, const_iterator first,
129 const_iterator last);
130 void splice(const_iterator position, list&& x, const_iterator first,
131 const_iterator last);
132
133 void remove(const value_type& value);
134 template <class Pred> void remove_if(Pred pred);
135 void unique();
136 template <class BinaryPredicate>
137 void unique(BinaryPredicate binary_pred);
138 void merge(list& x);
139 void merge(list&& x);
140 template <class Compare>
141 void merge(list& x, Compare comp);
142 template <class Compare>
143 void merge(list&& x, Compare comp);
144 void sort();
145 template <class Compare>
146 void sort(Compare comp);
Howard Hinnantc5607272011-06-03 17:30:28147 void reverse() noexcept;
Howard Hinnantbc8d3f92010-05-11 19:42:16148};
149
150template <class T, class Alloc>
151 bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y);
152template <class T, class Alloc>
153 bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y);
154template <class T, class Alloc>
155 bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y);
156template <class T, class Alloc>
157 bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y);
158template <class T, class Alloc>
159 bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y);
160template <class T, class Alloc>
161 bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y);
162
163template <class T, class Alloc>
Howard Hinnantc5607272011-06-03 17:30:28164 void swap(list<T,Alloc>& x, list<T,Alloc>& y)
165 noexcept(noexcept(x.swap(y)));
Howard Hinnantbc8d3f92010-05-11 19:42:16166
167} // std
168
169*/
170
171#include <__config>
172
173#include <memory>
174#include <limits>
175#include <initializer_list>
176#include <iterator>
177#include <algorithm>
Eric Fiselier5c74b482015-12-30 20:57:59178#include <type_traits>
Howard Hinnantbc8d3f92010-05-11 19:42:16179
Howard Hinnant66c6f972011-11-29 16:45:27180#include <__undef_min_max>
181
Eric Fiselierb9536102014-08-10 23:53:08182#include <__debug>
Howard Hinnant8b00e6c2013-08-02 00:26:35183
Howard Hinnant08e17472011-10-17 20:05:10184#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
Howard Hinnantbc8d3f92010-05-11 19:42:16185#pragma GCC system_header
Howard Hinnant08e17472011-10-17 20:05:10186#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16187
188_LIBCPP_BEGIN_NAMESPACE_STD
189
Howard Hinnant2b1b2d42011-06-14 19:58:17190template <class _Tp, class _VoidPtr> struct __list_node;
Eric Fiselier5c74b482015-12-30 20:57:59191template <class _Tp, class _VoidPtr> struct __list_node_base;
192
193template <class _Tp, class _VoidPtr>
194struct __list_node_pointer_traits {
195 typedef typename __rebind_pointer<_VoidPtr, __list_node<_Tp, _VoidPtr> >::type
196 __node_pointer;
197 typedef typename __rebind_pointer<_VoidPtr, __list_node_base<_Tp, _VoidPtr> >::type
198 __base_pointer;
199
200#if defined(_LIBCPP_ABI_LIST_REMOVE_NODE_POINTER_UB)
201 typedef __base_pointer __link_pointer;
202#else
203 typedef typename conditional<
204 is_pointer<_VoidPtr>::value,
205 __base_pointer,
206 __node_pointer
207 >::type __link_pointer;
208#endif
209
Eric Fiselier8e7bd4f2016-01-04 03:27:52210 typedef typename conditional<
211 is_same<__link_pointer, __node_pointer>::value,
212 __base_pointer,
213 __node_pointer
214 >::type __non_link_pointer;
215
216 static _LIBCPP_INLINE_VISIBILITY
217 __link_pointer __unsafe_link_pointer_cast(__link_pointer __p) {
218 return __p;
219 }
220
221 static _LIBCPP_INLINE_VISIBILITY
222 __link_pointer __unsafe_link_pointer_cast(__non_link_pointer __p) {
223 return static_cast<__link_pointer>(static_cast<_VoidPtr>(__p));
224 }
225
Eric Fiselier5c74b482015-12-30 20:57:59226};
Howard Hinnantbc8d3f92010-05-11 19:42:16227
228template <class _Tp, class _VoidPtr>
229struct __list_node_base
230{
Eric Fiselier5c74b482015-12-30 20:57:59231 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
232 typedef typename _NodeTraits::__node_pointer __node_pointer;
233 typedef typename _NodeTraits::__base_pointer __base_pointer;
234 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnant29f74322013-06-25 16:08:47235
Eric Fiselier5c74b482015-12-30 20:57:59236 __link_pointer __prev_;
237 __link_pointer __next_;
Howard Hinnantbc8d3f92010-05-11 19:42:16238
Howard Hinnant82894812010-09-22 16:48:34239 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8e7bd4f2016-01-04 03:27:52240 __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())),
241 __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {}
Marshall Clowea8ed832014-08-05 01:34:12242
243 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8e7bd4f2016-01-04 03:27:52244 __base_pointer __self() {
Eric Fiselier5c74b482015-12-30 20:57:59245 return pointer_traits<__base_pointer>::pointer_to(*this);
246 }
247
248 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:59249 __node_pointer __as_node() {
Eric Fiselier8e7bd4f2016-01-04 03:27:52250 return static_cast<__node_pointer>(__self());
Marshall Clowea8ed832014-08-05 01:34:12251 }
Howard Hinnantbc8d3f92010-05-11 19:42:16252};
253
254template <class _Tp, class _VoidPtr>
255struct __list_node
256 : public __list_node_base<_Tp, _VoidPtr>
257{
258 _Tp __value_;
Eric Fiselier8e7bd4f2016-01-04 03:27:52259
260 typedef __list_node_base<_Tp, _VoidPtr> __base;
261 typedef typename __base::__link_pointer __link_pointer;
262
263 _LIBCPP_INLINE_VISIBILITY
264 __link_pointer __as_link() {
265 return static_cast<__link_pointer>(__base::__self());
266 }
Howard Hinnantbc8d3f92010-05-11 19:42:16267};
268
Marshall Clowceead9c2015-02-18 17:24:08269template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
Howard Hinnant2b1b2d42011-06-14 19:58:17270template <class _Tp, class _Alloc> class __list_imp;
Howard Hinnant0f678bd2013-08-12 18:38:34271template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16272
273template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34274class _LIBCPP_TYPE_VIS_ONLY __list_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16275{
Eric Fiselier5c74b482015-12-30 20:57:59276 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
277 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16278
Eric Fiselier5c74b482015-12-30 20:57:59279 __link_pointer __ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16280
Howard Hinnant1c3ec6d2011-09-27 23:55:03281#if _LIBCPP_DEBUG_LEVEL >= 2
282 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:59283 explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03284 : __ptr_(__p)
285 {
286 __get_db()->__insert_ic(this, __c);
287 }
288#else
Howard Hinnant82894812010-09-22 16:48:34289 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:59290 explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03291#endif
292
293
Howard Hinnantbc8d3f92010-05-11 19:42:16294
295 template<class, class> friend class list;
296 template<class, class> friend class __list_imp;
297 template<class, class> friend class __list_const_iterator;
298public:
299 typedef bidirectional_iterator_tag iterator_category;
300 typedef _Tp value_type;
301 typedef value_type& reference;
Eric Fiselierbb2f28e2015-08-23 02:56:05302 typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16303 typedef typename pointer_traits<pointer>::difference_type difference_type;
304
Howard Hinnant82894812010-09-22 16:48:34305 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28306 __list_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03307 {
308#if _LIBCPP_DEBUG_LEVEL >= 2
309 __get_db()->__insert_i(this);
310#endif
311 }
312
313#if _LIBCPP_DEBUG_LEVEL >= 2
314
Howard Hinnant211f0ee2011-01-28 23:46:28315 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03316 __list_iterator(const __list_iterator& __p)
317 : __ptr_(__p.__ptr_)
318 {
319 __get_db()->__iterator_copy(this, &__p);
320 }
321
322 _LIBCPP_INLINE_VISIBILITY
323 ~__list_iterator()
324 {
325 __get_db()->__erase_i(this);
326 }
327
328 _LIBCPP_INLINE_VISIBILITY
329 __list_iterator& operator=(const __list_iterator& __p)
330 {
331 if (this != &__p)
332 {
333 __get_db()->__iterator_copy(this, &__p);
334 __ptr_ = __p.__ptr_;
335 }
336 return *this;
337 }
338
339#endif // _LIBCPP_DEBUG_LEVEL >= 2
340
341 _LIBCPP_INLINE_VISIBILITY
342 reference operator*() const
343 {
344#if _LIBCPP_DEBUG_LEVEL >= 2
345 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
346 "Attempted to dereference a non-dereferenceable list::iterator");
347#endif
Eric Fiselier5c74b482015-12-30 20:57:59348 return __ptr_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03349 }
Howard Hinnant82894812010-09-22 16:48:34350 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47351 pointer operator->() const
352 {
353#if _LIBCPP_DEBUG_LEVEL >= 2
354 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
355 "Attempted to dereference a non-dereferenceable list::iterator");
356#endif
Eric Fiselier5c74b482015-12-30 20:57:59357 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
Howard Hinnant29f74322013-06-25 16:08:47358 }
Howard Hinnantbc8d3f92010-05-11 19:42:16359
Howard Hinnant82894812010-09-22 16:48:34360 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03361 __list_iterator& operator++()
362 {
363#if _LIBCPP_DEBUG_LEVEL >= 2
364 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
365 "Attempted to increment non-incrementable list::iterator");
366#endif
367 __ptr_ = __ptr_->__next_;
368 return *this;
369 }
Howard Hinnant82894812010-09-22 16:48:34370 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16371 __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;}
372
Howard Hinnant82894812010-09-22 16:48:34373 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03374 __list_iterator& operator--()
375 {
376#if _LIBCPP_DEBUG_LEVEL >= 2
377 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
378 "Attempted to decrement non-decrementable list::iterator");
379#endif
380 __ptr_ = __ptr_->__prev_;
381 return *this;
382 }
Howard Hinnant82894812010-09-22 16:48:34383 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16384 __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;}
385
Howard Hinnant82894812010-09-22 16:48:34386 friend _LIBCPP_INLINE_VISIBILITY
387 bool operator==(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03388 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03389 return __x.__ptr_ == __y.__ptr_;
390 }
Howard Hinnant82894812010-09-22 16:48:34391 friend _LIBCPP_INLINE_VISIBILITY
392 bool operator!=(const __list_iterator& __x, const __list_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16393 {return !(__x == __y);}
394};
395
396template <class _Tp, class _VoidPtr>
Howard Hinnant0f678bd2013-08-12 18:38:34397class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
Howard Hinnantbc8d3f92010-05-11 19:42:16398{
Eric Fiselier5c74b482015-12-30 20:57:59399 typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
400 typedef typename _NodeTraits::__link_pointer __link_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16401
Eric Fiselier5c74b482015-12-30 20:57:59402 __link_pointer __ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:16403
Howard Hinnant1c3ec6d2011-09-27 23:55:03404#if _LIBCPP_DEBUG_LEVEL >= 2
405 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:59406 explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03407 : __ptr_(__p)
408 {
409 __get_db()->__insert_ic(this, __c);
410 }
411#else
Howard Hinnant82894812010-09-22 16:48:34412 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:59413 explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {}
Howard Hinnant1c3ec6d2011-09-27 23:55:03414#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16415
416 template<class, class> friend class list;
417 template<class, class> friend class __list_imp;
418public:
419 typedef bidirectional_iterator_tag iterator_category;
420 typedef _Tp value_type;
421 typedef const value_type& reference;
Eric Fiselierbb2f28e2015-08-23 02:56:05422 typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16423 typedef typename pointer_traits<pointer>::difference_type difference_type;
424
Howard Hinnant82894812010-09-22 16:48:34425 _LIBCPP_INLINE_VISIBILITY
Marshall Clow65d2e6a2013-08-05 21:23:28426 __list_const_iterator() _NOEXCEPT : __ptr_(nullptr)
Howard Hinnant1c3ec6d2011-09-27 23:55:03427 {
428#if _LIBCPP_DEBUG_LEVEL >= 2
429 __get_db()->__insert_i(this);
430#endif
431 }
Howard Hinnant211f0ee2011-01-28 23:46:28432 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant6dcaf3e2013-04-05 17:58:52433 __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03434 : __ptr_(__p.__ptr_)
435 {
436#if _LIBCPP_DEBUG_LEVEL >= 2
437 __get_db()->__iterator_copy(this, &__p);
438#endif
439 }
440
441#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnantbc8d3f92010-05-11 19:42:16442
Howard Hinnant82894812010-09-22 16:48:34443 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03444 __list_const_iterator(const __list_const_iterator& __p)
445 : __ptr_(__p.__ptr_)
446 {
447 __get_db()->__iterator_copy(this, &__p);
448 }
449
450 _LIBCPP_INLINE_VISIBILITY
451 ~__list_const_iterator()
452 {
453 __get_db()->__erase_i(this);
454 }
455
456 _LIBCPP_INLINE_VISIBILITY
457 __list_const_iterator& operator=(const __list_const_iterator& __p)
458 {
459 if (this != &__p)
460 {
461 __get_db()->__iterator_copy(this, &__p);
462 __ptr_ = __p.__ptr_;
463 }
464 return *this;
465 }
466
467#endif // _LIBCPP_DEBUG_LEVEL >= 2
468 _LIBCPP_INLINE_VISIBILITY
469 reference operator*() const
470 {
471#if _LIBCPP_DEBUG_LEVEL >= 2
472 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
473 "Attempted to dereference a non-dereferenceable list::const_iterator");
474#endif
Eric Fiselier5c74b482015-12-30 20:57:59475 return __ptr_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03476 }
Howard Hinnant82894812010-09-22 16:48:34477 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant29f74322013-06-25 16:08:47478 pointer operator->() const
479 {
480#if _LIBCPP_DEBUG_LEVEL >= 2
481 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
482 "Attempted to dereference a non-dereferenceable list::iterator");
483#endif
Eric Fiselier5c74b482015-12-30 20:57:59484 return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_);
Howard Hinnant29f74322013-06-25 16:08:47485 }
Howard Hinnantbc8d3f92010-05-11 19:42:16486
Howard Hinnant82894812010-09-22 16:48:34487 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03488 __list_const_iterator& operator++()
489 {
490#if _LIBCPP_DEBUG_LEVEL >= 2
491 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this),
492 "Attempted to increment non-incrementable list::const_iterator");
493#endif
494 __ptr_ = __ptr_->__next_;
495 return *this;
496 }
Howard Hinnant82894812010-09-22 16:48:34497 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16498 __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;}
499
Howard Hinnant82894812010-09-22 16:48:34500 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03501 __list_const_iterator& operator--()
502 {
503#if _LIBCPP_DEBUG_LEVEL >= 2
504 _LIBCPP_ASSERT(__get_const_db()->__decrementable(this),
505 "Attempted to decrement non-decrementable list::const_iterator");
506#endif
507 __ptr_ = __ptr_->__prev_;
508 return *this;
509 }
Howard Hinnant82894812010-09-22 16:48:34510 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16511 __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;}
512
Howard Hinnant82894812010-09-22 16:48:34513 friend _LIBCPP_INLINE_VISIBILITY
514 bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnant1c3ec6d2011-09-27 23:55:03515 {
Howard Hinnant1c3ec6d2011-09-27 23:55:03516 return __x.__ptr_ == __y.__ptr_;
517 }
Howard Hinnant82894812010-09-22 16:48:34518 friend _LIBCPP_INLINE_VISIBILITY
519 bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y)
Howard Hinnantbc8d3f92010-05-11 19:42:16520 {return !(__x == __y);}
521};
522
523template <class _Tp, class _Alloc>
524class __list_imp
525{
526 __list_imp(const __list_imp&);
527 __list_imp& operator=(const __list_imp&);
528protected:
529 typedef _Tp value_type;
530 typedef _Alloc allocator_type;
531 typedef allocator_traits<allocator_type> __alloc_traits;
532 typedef typename __alloc_traits::size_type size_type;
533 typedef typename __alloc_traits::void_pointer __void_pointer;
534 typedef __list_iterator<value_type, __void_pointer> iterator;
535 typedef __list_const_iterator<value_type, __void_pointer> const_iterator;
536 typedef __list_node_base<value_type, __void_pointer> __node_base;
537 typedef __list_node<value_type, __void_pointer> __node;
Marshall Clow66302c62015-04-07 05:21:38538 typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator;
Howard Hinnantbc8d3f92010-05-11 19:42:16539 typedef allocator_traits<__node_allocator> __node_alloc_traits;
540 typedef typename __node_alloc_traits::pointer __node_pointer;
Howard Hinnant29f74322013-06-25 16:08:47541 typedef typename __node_alloc_traits::pointer __node_const_pointer;
Eric Fiselier8e7bd4f2016-01-04 03:27:52542 typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits;
543 typedef typename __node_pointer_traits::__link_pointer __link_pointer;
Eric Fiselier5c74b482015-12-30 20:57:59544 typedef __link_pointer __link_const_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16545 typedef typename __alloc_traits::pointer pointer;
546 typedef typename __alloc_traits::const_pointer const_pointer;
547 typedef typename __alloc_traits::difference_type difference_type;
548
Marshall Clow66302c62015-04-07 05:21:38549 typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator;
Howard Hinnant29f74322013-06-25 16:08:47550 typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer;
551
Howard Hinnantbc8d3f92010-05-11 19:42:16552 __node_base __end_;
553 __compressed_pair<size_type, __node_allocator> __size_alloc_;
554
Howard Hinnant82894812010-09-22 16:48:34555 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier8e7bd4f2016-01-04 03:27:52556 __link_pointer __end_as_link() const _NOEXCEPT {
557 return __node_pointer_traits::__unsafe_link_pointer_cast(
558 const_cast<__node_base&>(__end_).__self());
559 }
560
561 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28562 size_type& __sz() _NOEXCEPT {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34563 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28564 const size_type& __sz() const _NOEXCEPT
565 {return __size_alloc_.first();}
Howard Hinnant82894812010-09-22 16:48:34566 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28567 __node_allocator& __node_alloc() _NOEXCEPT
568 {return __size_alloc_.second();}
Howard Hinnant82894812010-09-22 16:48:34569 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28570 const __node_allocator& __node_alloc() const _NOEXCEPT
571 {return __size_alloc_.second();}
Howard Hinnantbc8d3f92010-05-11 19:42:16572
Evgeniy Stepanov9341a8a2016-04-22 01:04:55573 _LIBCPP_INLINE_VISIBILITY
Eric Fiselieref3060e2016-11-23 01:18:56574 size_type __node_alloc_max_size() const _NOEXCEPT {
575 return __node_alloc_traits::max_size(__node_alloc());
576 }
577 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:59578 static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16579
Evgeniy Stepanov9341a8a2016-04-22 01:04:55580 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28581 __list_imp()
582 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55583 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16584 __list_imp(const allocator_type& __a);
585 ~__list_imp();
Howard Hinnantc5607272011-06-03 17:30:28586 void clear() _NOEXCEPT;
Howard Hinnant82894812010-09-22 16:48:34587 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28588 bool empty() const _NOEXCEPT {return __sz() == 0;}
Howard Hinnantbc8d3f92010-05-11 19:42:16589
Howard Hinnant82894812010-09-22 16:48:34590 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03591 iterator begin() _NOEXCEPT
592 {
593#if _LIBCPP_DEBUG_LEVEL >= 2
594 return iterator(__end_.__next_, this);
595#else
596 return iterator(__end_.__next_);
597#endif
598 }
Howard Hinnant82894812010-09-22 16:48:34599 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28600 const_iterator begin() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03601 {
602#if _LIBCPP_DEBUG_LEVEL >= 2
603 return const_iterator(__end_.__next_, this);
604#else
605 return const_iterator(__end_.__next_);
606#endif
607 }
Howard Hinnant82894812010-09-22 16:48:34608 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03609 iterator end() _NOEXCEPT
610 {
611#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier8e7bd4f2016-01-04 03:27:52612 return iterator(__end_as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03613#else
Eric Fiselier8e7bd4f2016-01-04 03:27:52614 return iterator(__end_as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:03615#endif
616 }
Howard Hinnant82894812010-09-22 16:48:34617 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28618 const_iterator end() const _NOEXCEPT
Howard Hinnant1c3ec6d2011-09-27 23:55:03619 {
620#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier8e7bd4f2016-01-04 03:27:52621 return const_iterator(__end_as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:03622#else
Eric Fiselier8e7bd4f2016-01-04 03:27:52623 return const_iterator(__end_as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:03624#endif
625 }
Howard Hinnantbc8d3f92010-05-11 19:42:16626
Howard Hinnantc5607272011-06-03 17:30:28627 void swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56628#if _LIBCPP_STD_VER >= 14
629 _NOEXCEPT;
630#else
631 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
632 __is_nothrow_swappable<allocator_type>::value);
633#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16634
Howard Hinnant82894812010-09-22 16:48:34635 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16636 void __copy_assign_alloc(const __list_imp& __c)
637 {__copy_assign_alloc(__c, integral_constant<bool,
638 __node_alloc_traits::propagate_on_container_copy_assignment::value>());}
639
Howard Hinnant82894812010-09-22 16:48:34640 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16641 void __move_assign_alloc(__list_imp& __c)
Howard Hinnantc5607272011-06-03 17:30:28642 _NOEXCEPT_(
643 !__node_alloc_traits::propagate_on_container_move_assignment::value ||
644 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16645 {__move_assign_alloc(__c, integral_constant<bool,
646 __node_alloc_traits::propagate_on_container_move_assignment::value>());}
647
648private:
Howard Hinnant82894812010-09-22 16:48:34649 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16650 void __copy_assign_alloc(const __list_imp& __c, true_type)
651 {
652 if (__node_alloc() != __c.__node_alloc())
653 clear();
654 __node_alloc() = __c.__node_alloc();
655 }
656
Howard Hinnant82894812010-09-22 16:48:34657 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16658 void __copy_assign_alloc(const __list_imp& __c, false_type)
659 {}
660
Howard Hinnant82894812010-09-22 16:48:34661 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31662 void __move_assign_alloc(__list_imp& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:28663 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16664 {
Howard Hinnant0949eed2011-06-30 21:18:19665 __node_alloc() = _VSTD::move(__c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16666 }
667
Howard Hinnant82894812010-09-22 16:48:34668 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant9cbee432011-09-02 20:42:31669 void __move_assign_alloc(__list_imp& __c, false_type)
Howard Hinnantc5607272011-06-03 17:30:28670 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16671 {}
672};
673
674// Unlink nodes [__f, __l]
675template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55676inline
Howard Hinnantbc8d3f92010-05-11 19:42:16677void
Eric Fiselier5c74b482015-12-30 20:57:59678__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
Howard Hinnantc5607272011-06-03 17:30:28679 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16680{
Howard Hinnant29f74322013-06-25 16:08:47681 __f->__prev_->__next_ = __l->__next_;
682 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16683}
684
685template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55686inline
Howard Hinnantbc8d3f92010-05-11 19:42:16687__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnantc5607272011-06-03 17:30:28688 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16689 : __size_alloc_(0)
690{
691}
692
693template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55694inline
Howard Hinnantbc8d3f92010-05-11 19:42:16695__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
696 : __size_alloc_(0, __node_allocator(__a))
697{
698}
699
700template <class _Tp, class _Alloc>
701__list_imp<_Tp, _Alloc>::~__list_imp()
702{
703 clear();
Howard Hinnant1c3ec6d2011-09-27 23:55:03704#if _LIBCPP_DEBUG_LEVEL >= 2
705 __get_db()->__erase_c(this);
706#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16707}
708
709template <class _Tp, class _Alloc>
710void
Howard Hinnantc5607272011-06-03 17:30:28711__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16712{
713 if (!empty())
714 {
715 __node_allocator& __na = __node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:59716 __link_pointer __f = __end_.__next_;
Eric Fiselier8e7bd4f2016-01-04 03:27:52717 __link_pointer __l = __end_as_link();
Howard Hinnant29f74322013-06-25 16:08:47718 __unlink_nodes(__f, __l->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16719 __sz() = 0;
720 while (__f != __l)
721 {
Eric Fiselier5c74b482015-12-30 20:57:59722 __node_pointer __np = __f->__as_node();
Howard Hinnant1c3ec6d2011-09-27 23:55:03723 __f = __f->__next_;
Eric Fiselier5c74b482015-12-30 20:57:59724 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
725 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16726 }
Howard Hinnant1c3ec6d2011-09-27 23:55:03727#if _LIBCPP_DEBUG_LEVEL >= 2
728 __c_node* __c = __get_db()->__find_c_and_lock(this);
729 for (__i_node** __p = __c->end_; __p != __c->beg_; )
730 {
731 --__p;
732 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
733 if (__i->__ptr_ != __l)
734 {
735 (*__p)->__c_ = nullptr;
736 if (--__c->end_ != __p)
737 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
738 }
739 }
740 __get_db()->unlock();
741#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16742 }
743}
744
745template <class _Tp, class _Alloc>
746void
747__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56748#if _LIBCPP_STD_VER >= 14
749 _NOEXCEPT
750#else
751 _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
752 __is_nothrow_swappable<allocator_type>::value)
753#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16754{
Howard Hinnant1c3ec6d2011-09-27 23:55:03755 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
756 this->__node_alloc() == __c.__node_alloc(),
757 "list::swap: Either propagate_on_container_swap must be true"
758 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19759 using _VSTD::swap;
Marshall Clow7d914d12015-07-13 20:04:56760 __swap_allocator(__node_alloc(), __c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16761 swap(__sz(), __c.__sz());
762 swap(__end_, __c.__end_);
763 if (__sz() == 0)
Eric Fiselier8e7bd4f2016-01-04 03:27:52764 __end_.__next_ = __end_.__prev_ = __end_as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:16765 else
Eric Fiselier8e7bd4f2016-01-04 03:27:52766 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:16767 if (__c.__sz() == 0)
Eric Fiselier8e7bd4f2016-01-04 03:27:52768 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:16769 else
Eric Fiselier8e7bd4f2016-01-04 03:27:52770 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
Marshall Clowea8ed832014-08-05 01:34:12771
Howard Hinnant1c3ec6d2011-09-27 23:55:03772#if _LIBCPP_DEBUG_LEVEL >= 2
773 __libcpp_db* __db = __get_db();
774 __c_node* __cn1 = __db->__find_c_and_lock(this);
775 __c_node* __cn2 = __db->__find_c(&__c);
776 std::swap(__cn1->beg_, __cn2->beg_);
777 std::swap(__cn1->end_, __cn2->end_);
778 std::swap(__cn1->cap_, __cn2->cap_);
779 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
780 {
781 --__p;
782 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:52783 if (__i->__ptr_ == __c.__end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:03784 {
785 __cn2->__add(*__p);
786 if (--__cn1->end_ != __p)
787 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
788 }
789 else
790 (*__p)->__c_ = __cn1;
791 }
792 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
793 {
794 --__p;
795 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:52796 if (__i->__ptr_ == __end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:03797 {
798 __cn1->__add(*__p);
799 if (--__cn2->end_ != __p)
800 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
801 }
802 else
803 (*__p)->__c_ = __cn2;
804 }
805 __db->unlock();
806#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16807}
808
Marshall Clowceead9c2015-02-18 17:24:08809template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Howard Hinnant0f678bd2013-08-12 18:38:34810class _LIBCPP_TYPE_VIS_ONLY list
Howard Hinnantbc8d3f92010-05-11 19:42:16811 : private __list_imp<_Tp, _Alloc>
812{
813 typedef __list_imp<_Tp, _Alloc> base;
814 typedef typename base::__node __node;
815 typedef typename base::__node_allocator __node_allocator;
816 typedef typename base::__node_pointer __node_pointer;
817 typedef typename base::__node_alloc_traits __node_alloc_traits;
Howard Hinnant29f74322013-06-25 16:08:47818 typedef typename base::__node_base __node_base;
819 typedef typename base::__node_base_pointer __node_base_pointer;
Eric Fiselier5c74b482015-12-30 20:57:59820 typedef typename base::__link_pointer __link_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16821
822public:
823 typedef _Tp value_type;
824 typedef _Alloc allocator_type;
825 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
826 "Invalid allocator::value_type");
827 typedef value_type& reference;
828 typedef const value_type& const_reference;
829 typedef typename base::pointer pointer;
830 typedef typename base::const_pointer const_pointer;
831 typedef typename base::size_type size_type;
832 typedef typename base::difference_type difference_type;
833 typedef typename base::iterator iterator;
834 typedef typename base::const_iterator const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19835 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
836 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16837
Howard Hinnant82894812010-09-22 16:48:34838 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28839 list()
840 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant1c3ec6d2011-09-27 23:55:03841 {
842#if _LIBCPP_DEBUG_LEVEL >= 2
843 __get_db()->__insert_c(this);
844#endif
845 }
Howard Hinnant82894812010-09-22 16:48:34846 _LIBCPP_INLINE_VISIBILITY
Marshall Clow955f2c82013-09-08 19:11:51847 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant1c3ec6d2011-09-27 23:55:03848 {
849#if _LIBCPP_DEBUG_LEVEL >= 2
850 __get_db()->__insert_c(this);
851#endif
852 }
Marshall Clow955f2c82013-09-08 19:11:51853 explicit list(size_type __n);
854#if _LIBCPP_STD_VER > 11
855 explicit list(size_type __n, const allocator_type& __a);
856#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16857 list(size_type __n, const value_type& __x);
858 list(size_type __n, const value_type& __x, const allocator_type& __a);
859 template <class _InpIter>
860 list(_InpIter __f, _InpIter __l,
861 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
862 template <class _InpIter>
863 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
864 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
865
866 list(const list& __c);
867 list(const list& __c, const allocator_type& __a);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55868 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16869 list& operator=(const list& __c);
Howard Hinnante3e32912011-08-12 21:56:02870#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16871 list(initializer_list<value_type> __il);
872 list(initializer_list<value_type> __il, const allocator_type& __a);
Howard Hinnante3e32912011-08-12 21:56:02873#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant73d21a42010-09-04 23:28:19874#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:55875 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28876 list(list&& __c)
877 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16879 list(list&& __c, const allocator_type& __a);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55880 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28881 list& operator=(list&& __c)
882 _NOEXCEPT_(
883 __node_alloc_traits::propagate_on_container_move_assignment::value &&
884 is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnant73d21a42010-09-04 23:28:19885#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnante3e32912011-08-12 21:56:02886#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34887 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16888 list& operator=(initializer_list<value_type> __il)
889 {assign(__il.begin(), __il.end()); return *this;}
Howard Hinnante3e32912011-08-12 21:56:02890#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16891
892 template <class _InpIter>
893 void assign(_InpIter __f, _InpIter __l,
894 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
895 void assign(size_type __n, const value_type& __x);
Howard Hinnante3e32912011-08-12 21:56:02896#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16898 void assign(initializer_list<value_type> __il)
899 {assign(__il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:02900#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:16901
Evgeniy Stepanov9341a8a2016-04-22 01:04:55902 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28903 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16904
Howard Hinnant82894812010-09-22 16:48:34905 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28906 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant82894812010-09-22 16:48:34907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28908 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant82894812010-09-22 16:48:34909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28910 size_type max_size() const _NOEXCEPT
Eric Fiselieref3060e2016-11-23 01:18:56911 {
912 return std::min<size_type>(
913 base::__node_alloc_max_size(),
914 numeric_limits<difference_type >::max());
915 }
Howard Hinnantbc8d3f92010-05-11 19:42:16916
Howard Hinnant82894812010-09-22 16:48:34917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28918 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34919 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28920 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34921 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28922 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28924 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34925 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28926 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34927 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28928 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16929
Howard Hinnant82894812010-09-22 16:48:34930 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28931 reverse_iterator rbegin() _NOEXCEPT
932 {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34933 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28934 const_reverse_iterator rbegin() const _NOEXCEPT
935 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34936 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28937 reverse_iterator rend() _NOEXCEPT
938 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28940 const_reverse_iterator rend() const _NOEXCEPT
941 {return const_reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34942 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28943 const_reverse_iterator crbegin() const _NOEXCEPT
944 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28946 const_reverse_iterator crend() const _NOEXCEPT
947 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16948
Howard Hinnant82894812010-09-22 16:48:34949 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03950 reference front()
951 {
952 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59953 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03954 }
Howard Hinnant82894812010-09-22 16:48:34955 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03956 const_reference front() const
957 {
958 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59959 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03960 }
Howard Hinnant82894812010-09-22 16:48:34961 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03962 reference back()
963 {
964 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59965 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03966 }
Howard Hinnant82894812010-09-22 16:48:34967 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03968 const_reference back() const
969 {
970 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59971 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03972 }
Howard Hinnantbc8d3f92010-05-11 19:42:16973
Howard Hinnant73d21a42010-09-04 23:28:19974#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16975 void push_front(value_type&& __x);
976 void push_back(value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19977#ifndef _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16978 template <class... _Args>
Eric Fiselier3816ef92016-07-21 03:20:17979 reference emplace_front(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16980 template <class... _Args>
Eric Fiselier3816ef92016-07-21 03:20:17981 reference emplace_back(_Args&&... __args);
Howard Hinnantbc8d3f92010-05-11 19:42:16982 template <class... _Args>
983 iterator emplace(const_iterator __p, _Args&&... __args);
Howard Hinnant73d21a42010-09-04 23:28:19984#endif // _LIBCPP_HAS_NO_VARIADICS
Howard Hinnantbc8d3f92010-05-11 19:42:16985 iterator insert(const_iterator __p, value_type&& __x);
Howard Hinnant73d21a42010-09-04 23:28:19986#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16987
988 void push_front(const value_type& __x);
989 void push_back(const value_type& __x);
990
991 iterator insert(const_iterator __p, const value_type& __x);
992 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
993 template <class _InpIter>
994 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
995 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnante3e32912011-08-12 21:56:02996#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnant82894812010-09-22 16:48:34997 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16998 iterator insert(const_iterator __p, initializer_list<value_type> __il)
999 {return insert(__p, __il.begin(), __il.end());}
Howard Hinnante3e32912011-08-12 21:56:021000#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
Howard Hinnantbc8d3f92010-05-11 19:42:161001
Howard Hinnant82894812010-09-22 16:48:341002 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:281003 void swap(list& __c)
Marshall Clow7d914d12015-07-13 20:04:561004#if _LIBCPP_STD_VER >= 14
1005 _NOEXCEPT
1006#else
Howard Hinnantc5607272011-06-03 17:30:281007 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
1008 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clow7d914d12015-07-13 20:04:561009#endif
Howard Hinnantc5607272011-06-03 17:30:281010 {base::swap(__c);}
Howard Hinnant82894812010-09-22 16:48:341011 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:281012 void clear() _NOEXCEPT {base::clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:161013
1014 void pop_front();
1015 void pop_back();
1016
1017 iterator erase(const_iterator __p);
1018 iterator erase(const_iterator __f, const_iterator __l);
1019
1020 void resize(size_type __n);
1021 void resize(size_type __n, const value_type& __x);
1022
1023 void splice(const_iterator __p, list& __c);
Howard Hinnant73d21a42010-09-04 23:28:191024#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341025 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161026 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
1027#endif
1028 void splice(const_iterator __p, list& __c, const_iterator __i);
Howard Hinnant73d21a42010-09-04 23:28:191029#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341030 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161031 void splice(const_iterator __p, list&& __c, const_iterator __i)
1032 {splice(__p, __c, __i);}
Howard Hinnant73d21a42010-09-04 23:28:191033#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161034 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnant73d21a42010-09-04 23:28:191035#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161037 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1038 {splice(__p, __c, __f, __l);}
Howard Hinnant73d21a42010-09-04 23:28:191039#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161040
1041 void remove(const value_type& __x);
1042 template <class _Pred> void remove_if(_Pred __pred);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161044 void unique();
1045 template <class _BinaryPred>
1046 void unique(_BinaryPred __binary_pred);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161048 void merge(list& __c);
Howard Hinnant73d21a42010-09-04 23:28:191049#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnant82894812010-09-22 16:48:341050 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161051 void merge(list&& __c) {merge(__c);}
1052#endif
1053 template <class _Comp>
1054 void merge(list& __c, _Comp __comp);
Howard Hinnant73d21a42010-09-04 23:28:191055#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161056 template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:341057 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161058 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Howard Hinnant73d21a42010-09-04 23:28:191059#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Evgeniy Stepanov9341a8a2016-04-22 01:04:551060 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161061 void sort();
1062 template <class _Comp>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551063 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161064 void sort(_Comp __comp);
1065
Howard Hinnantc5607272011-06-03 17:30:281066 void reverse() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161067
Howard Hinnant1c3ec6d2011-09-27 23:55:031068 bool __invariants() const;
1069
1070#if _LIBCPP_DEBUG_LEVEL >= 2
1071
1072 bool __dereferenceable(const const_iterator* __i) const;
1073 bool __decrementable(const const_iterator* __i) const;
1074 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1075 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1076
1077#endif // _LIBCPP_DEBUG_LEVEL >= 2
1078
Howard Hinnantbc8d3f92010-05-11 19:42:161079private:
Evgeniy Stepanov9341a8a2016-04-22 01:04:551080 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:591081 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551082 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:591083 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551084 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:591085 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161086 iterator __iterator(size_type __n);
1087 template <class _Comp>
1088 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1089
Howard Hinnantc5607272011-06-03 17:30:281090 void __move_assign(list& __c, true_type)
1091 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:161092 void __move_assign(list& __c, false_type);
1093};
1094
1095// Link in nodes [__f, __l] just prior to __p
1096template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551097inline
Howard Hinnantbc8d3f92010-05-11 19:42:161098void
Eric Fiselier5c74b482015-12-30 20:57:591099list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
Howard Hinnantbc8d3f92010-05-11 19:42:161100{
Howard Hinnant29f74322013-06-25 16:08:471101 __p->__prev_->__next_ = __f;
1102 __f->__prev_ = __p->__prev_;
1103 __p->__prev_ = __l;
1104 __l->__next_ = __p;
Howard Hinnantbc8d3f92010-05-11 19:42:161105}
1106
Marshall Clowea8ed832014-08-05 01:34:121107// Link in nodes [__f, __l] at the front of the list
1108template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551109inline
Marshall Clowea8ed832014-08-05 01:34:121110void
Eric Fiselier5c74b482015-12-30 20:57:591111list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
Marshall Clowea8ed832014-08-05 01:34:121112{
Eric Fiselier8e7bd4f2016-01-04 03:27:521113 __f->__prev_ = base::__end_as_link();
Marshall Clowfca038e2014-08-08 15:35:521114 __l->__next_ = base::__end_.__next_;
1115 __l->__next_->__prev_ = __l;
1116 base::__end_.__next_ = __f;
Marshall Clowea8ed832014-08-05 01:34:121117}
1118
1119// Link in nodes [__f, __l] at the front of the list
1120template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551121inline
Marshall Clowea8ed832014-08-05 01:34:121122void
Eric Fiselier5c74b482015-12-30 20:57:591123list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
Marshall Clowea8ed832014-08-05 01:34:121124{
Eric Fiselier8e7bd4f2016-01-04 03:27:521125 __l->__next_ = base::__end_as_link();
Marshall Clowfca038e2014-08-08 15:35:521126 __f->__prev_ = base::__end_.__prev_;
1127 __f->__prev_->__next_ = __f;
1128 base::__end_.__prev_ = __l;
Marshall Clowea8ed832014-08-05 01:34:121129}
1130
1131
Howard Hinnantbc8d3f92010-05-11 19:42:161132template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551133inline
Howard Hinnantbc8d3f92010-05-11 19:42:161134typename list<_Tp, _Alloc>::iterator
1135list<_Tp, _Alloc>::__iterator(size_type __n)
1136{
Howard Hinnant0949eed2011-06-30 21:18:191137 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1138 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161139}
1140
1141template <class _Tp, class _Alloc>
1142list<_Tp, _Alloc>::list(size_type __n)
1143{
Howard Hinnant1c3ec6d2011-09-27 23:55:031144#if _LIBCPP_DEBUG_LEVEL >= 2
1145 __get_db()->__insert_c(this);
1146#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161147 for (; __n > 0; --__n)
Howard Hinnant73d21a42010-09-04 23:28:191148#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161149 emplace_back();
1150#else
1151 push_back(value_type());
1152#endif
1153}
1154
Marshall Clow955f2c82013-09-08 19:11:511155#if _LIBCPP_STD_VER > 11
1156template <class _Tp, class _Alloc>
1157list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1158{
1159#if _LIBCPP_DEBUG_LEVEL >= 2
1160 __get_db()->__insert_c(this);
1161#endif
1162 for (; __n > 0; --__n)
1163#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
1164 emplace_back();
1165#else
1166 push_back(value_type());
1167#endif
1168}
1169#endif
1170
Howard Hinnantbc8d3f92010-05-11 19:42:161171template <class _Tp, class _Alloc>
1172list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1173{
Howard Hinnant1c3ec6d2011-09-27 23:55:031174#if _LIBCPP_DEBUG_LEVEL >= 2
1175 __get_db()->__insert_c(this);
1176#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161177 for (; __n > 0; --__n)
1178 push_back(__x);
1179}
1180
1181template <class _Tp, class _Alloc>
1182list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1183 : base(__a)
1184{
Howard Hinnant1c3ec6d2011-09-27 23:55:031185#if _LIBCPP_DEBUG_LEVEL >= 2
1186 __get_db()->__insert_c(this);
1187#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161188 for (; __n > 0; --__n)
1189 push_back(__x);
1190}
1191
1192template <class _Tp, class _Alloc>
1193template <class _InpIter>
1194list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1195 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1196{
Howard Hinnant1c3ec6d2011-09-27 23:55:031197#if _LIBCPP_DEBUG_LEVEL >= 2
1198 __get_db()->__insert_c(this);
1199#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161200 for (; __f != __l; ++__f)
1201 push_back(*__f);
1202}
1203
1204template <class _Tp, class _Alloc>
1205template <class _InpIter>
1206list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1207 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1208 : base(__a)
1209{
Howard Hinnant1c3ec6d2011-09-27 23:55:031210#if _LIBCPP_DEBUG_LEVEL >= 2
1211 __get_db()->__insert_c(this);
1212#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161213 for (; __f != __l; ++__f)
1214 push_back(*__f);
1215}
1216
1217template <class _Tp, class _Alloc>
1218list<_Tp, _Alloc>::list(const list& __c)
1219 : base(allocator_type(
1220 __node_alloc_traits::select_on_container_copy_construction(
1221 __c.__node_alloc())))
1222{
Howard Hinnant1c3ec6d2011-09-27 23:55:031223#if _LIBCPP_DEBUG_LEVEL >= 2
1224 __get_db()->__insert_c(this);
1225#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161226 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1227 push_back(*__i);
1228}
1229
1230template <class _Tp, class _Alloc>
1231list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1232 : base(__a)
1233{
Howard Hinnant1c3ec6d2011-09-27 23:55:031234#if _LIBCPP_DEBUG_LEVEL >= 2
1235 __get_db()->__insert_c(this);
1236#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161237 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1238 push_back(*__i);
1239}
1240
Howard Hinnante3e32912011-08-12 21:56:021241#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1242
Howard Hinnantbc8d3f92010-05-11 19:42:161243template <class _Tp, class _Alloc>
1244list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1245 : base(__a)
1246{
Howard Hinnant1c3ec6d2011-09-27 23:55:031247#if _LIBCPP_DEBUG_LEVEL >= 2
1248 __get_db()->__insert_c(this);
1249#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161250 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1251 __e = __il.end(); __i != __e; ++__i)
1252 push_back(*__i);
1253}
1254
1255template <class _Tp, class _Alloc>
1256list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
1257{
Howard Hinnant1c3ec6d2011-09-27 23:55:031258#if _LIBCPP_DEBUG_LEVEL >= 2
1259 __get_db()->__insert_c(this);
1260#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161261 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1262 __e = __il.end(); __i != __e; ++__i)
1263 push_back(*__i);
1264}
1265
Howard Hinnante3e32912011-08-12 21:56:021266#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
1267
Howard Hinnantbc8d3f92010-05-11 19:42:161268template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551269inline
Howard Hinnantbc8d3f92010-05-11 19:42:161270list<_Tp, _Alloc>&
1271list<_Tp, _Alloc>::operator=(const list& __c)
1272{
1273 if (this != &__c)
1274 {
1275 base::__copy_assign_alloc(__c);
1276 assign(__c.begin(), __c.end());
1277 }
1278 return *this;
1279}
1280
Howard Hinnant73d21a42010-09-04 23:28:191281#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161282
1283template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551284inline
Howard Hinnantbc8d3f92010-05-11 19:42:161285list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281286 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnant0949eed2011-06-30 21:18:191287 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnantbc8d3f92010-05-11 19:42:161288{
Howard Hinnant1c3ec6d2011-09-27 23:55:031289#if _LIBCPP_DEBUG_LEVEL >= 2
1290 __get_db()->__insert_c(this);
1291#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161292 splice(end(), __c);
1293}
1294
1295template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551296inline
Howard Hinnantbc8d3f92010-05-11 19:42:161297list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1298 : base(__a)
1299{
Howard Hinnant1c3ec6d2011-09-27 23:55:031300#if _LIBCPP_DEBUG_LEVEL >= 2
1301 __get_db()->__insert_c(this);
1302#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161303 if (__a == __c.get_allocator())
1304 splice(end(), __c);
1305 else
1306 {
Howard Hinnant99968442011-11-29 18:15:501307 typedef move_iterator<iterator> _Ip;
1308 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161309 }
1310}
1311
1312template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551313inline
Howard Hinnantbc8d3f92010-05-11 19:42:161314list<_Tp, _Alloc>&
1315list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281316 _NOEXCEPT_(
1317 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1318 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161319{
1320 __move_assign(__c, integral_constant<bool,
1321 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1322 return *this;
1323}
1324
1325template <class _Tp, class _Alloc>
1326void
1327list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1328{
1329 if (base::__node_alloc() != __c.__node_alloc())
1330 {
Howard Hinnant99968442011-11-29 18:15:501331 typedef move_iterator<iterator> _Ip;
1332 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161333 }
1334 else
1335 __move_assign(__c, true_type());
1336}
1337
1338template <class _Tp, class _Alloc>
1339void
1340list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:281341 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161342{
1343 clear();
1344 base::__move_assign_alloc(__c);
1345 splice(end(), __c);
1346}
1347
Howard Hinnant73d21a42010-09-04 23:28:191348#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161349
1350template <class _Tp, class _Alloc>
1351template <class _InpIter>
1352void
1353list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1354 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1355{
1356 iterator __i = begin();
1357 iterator __e = end();
1358 for (; __f != __l && __i != __e; ++__f, ++__i)
1359 *__i = *__f;
1360 if (__i == __e)
1361 insert(__e, __f, __l);
1362 else
1363 erase(__i, __e);
1364}
1365
1366template <class _Tp, class _Alloc>
1367void
1368list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1369{
1370 iterator __i = begin();
1371 iterator __e = end();
1372 for (; __n > 0 && __i != __e; --__n, ++__i)
1373 *__i = __x;
1374 if (__i == __e)
1375 insert(__e, __n, __x);
1376 else
1377 erase(__i, __e);
1378}
1379
1380template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551381inline
Howard Hinnantbc8d3f92010-05-11 19:42:161382_Alloc
Howard Hinnantc5607272011-06-03 17:30:281383list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161384{
1385 return allocator_type(base::__node_alloc());
1386}
1387
1388template <class _Tp, class _Alloc>
1389typename list<_Tp, _Alloc>::iterator
1390list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1391{
Howard Hinnant1c3ec6d2011-09-27 23:55:031392#if _LIBCPP_DEBUG_LEVEL >= 2
1393 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1394 "list::insert(iterator, x) called with an iterator not"
1395 " referring to this list");
1396#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161397 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501398 typedef __allocator_destructor<__node_allocator> _Dp;
1399 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161400 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191401 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591402 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161403 ++base::__sz();
Howard Hinnant79a35572013-04-05 00:18:491404#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591405 return iterator(__hold.release()->__as_link(), this);
Howard Hinnant79a35572013-04-05 00:18:491406#else
Eric Fiselier5c74b482015-12-30 20:57:591407 return iterator(__hold.release()->__as_link());
Howard Hinnant79a35572013-04-05 00:18:491408#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161409}
1410
1411template <class _Tp, class _Alloc>
1412typename list<_Tp, _Alloc>::iterator
1413list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1414{
Howard Hinnant1c3ec6d2011-09-27 23:55:031415#if _LIBCPP_DEBUG_LEVEL >= 2
1416 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1417 "list::insert(iterator, n, x) called with an iterator not"
1418 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471419 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031420#else
Howard Hinnant29f74322013-06-25 16:08:471421 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031422#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161423 if (__n > 0)
1424 {
1425 size_type __ds = 0;
1426 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501427 typedef __allocator_destructor<__node_allocator> _Dp;
1428 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161429 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191430 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161431 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031432#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591433 __r = iterator(__hold->__as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031434#else
Eric Fiselier5c74b482015-12-30 20:57:591435 __r = iterator(__hold->__as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:031436#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161437 __hold.release();
1438 iterator __e = __r;
1439#ifndef _LIBCPP_NO_EXCEPTIONS
1440 try
1441 {
Howard Hinnant324bb032010-08-22 00:02:431442#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161443 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1444 {
1445 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191446 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591447 __e.__ptr_->__next_ = __hold->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161448 __hold->__prev_ = __e.__ptr_;
1449 __hold.release();
1450 }
1451#ifndef _LIBCPP_NO_EXCEPTIONS
1452 }
1453 catch (...)
1454 {
1455 while (true)
1456 {
Howard Hinnant0949eed2011-06-30 21:18:191457 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591458 __link_pointer __prev = __e.__ptr_->__prev_;
1459 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161460 if (__prev == 0)
1461 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031462#if _LIBCPP_DEBUG_LEVEL >= 2
1463 __e = iterator(__prev, this);
1464#else
Howard Hinnantbc8d3f92010-05-11 19:42:161465 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031466#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161467 }
1468 throw;
1469 }
Howard Hinnant324bb032010-08-22 00:02:431470#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471471 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161472 base::__sz() += __ds;
1473 }
1474 return __r;
1475}
1476
1477template <class _Tp, class _Alloc>
1478template <class _InpIter>
1479typename list<_Tp, _Alloc>::iterator
1480list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1481 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1482{
Howard Hinnant1c3ec6d2011-09-27 23:55:031483#if _LIBCPP_DEBUG_LEVEL >= 2
1484 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1485 "list::insert(iterator, range) called with an iterator not"
1486 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471487 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031488#else
Howard Hinnant29f74322013-06-25 16:08:471489 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031490#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161491 if (__f != __l)
1492 {
1493 size_type __ds = 0;
1494 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501495 typedef __allocator_destructor<__node_allocator> _Dp;
1496 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161497 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191498 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:161499 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031500#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591501 __r = iterator(__hold.get()->__as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031502#else
Eric Fiselier5c74b482015-12-30 20:57:591503 __r = iterator(__hold.get()->__as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:031504#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161505 __hold.release();
1506 iterator __e = __r;
1507#ifndef _LIBCPP_NO_EXCEPTIONS
1508 try
1509 {
Howard Hinnant324bb032010-08-22 00:02:431510#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier537876b2015-03-19 03:20:021511 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnantbc8d3f92010-05-11 19:42:161512 {
1513 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191514 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Eric Fiselier5c74b482015-12-30 20:57:591515 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161516 __hold->__prev_ = __e.__ptr_;
1517 __hold.release();
1518 }
1519#ifndef _LIBCPP_NO_EXCEPTIONS
1520 }
1521 catch (...)
1522 {
1523 while (true)
1524 {
Howard Hinnant0949eed2011-06-30 21:18:191525 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591526 __link_pointer __prev = __e.__ptr_->__prev_;
1527 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161528 if (__prev == 0)
1529 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031530#if _LIBCPP_DEBUG_LEVEL >= 2
1531 __e = iterator(__prev, this);
1532#else
Howard Hinnantbc8d3f92010-05-11 19:42:161533 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031534#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161535 }
1536 throw;
1537 }
Howard Hinnant324bb032010-08-22 00:02:431538#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471539 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161540 base::__sz() += __ds;
1541 }
1542 return __r;
1543}
1544
1545template <class _Tp, class _Alloc>
1546void
1547list<_Tp, _Alloc>::push_front(const value_type& __x)
1548{
1549 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501550 typedef __allocator_destructor<__node_allocator> _Dp;
1551 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191552 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591553 __link_pointer __nl = __hold->__as_link();
1554 __link_nodes_at_front(__nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161555 ++base::__sz();
1556 __hold.release();
1557}
1558
1559template <class _Tp, class _Alloc>
1560void
1561list<_Tp, _Alloc>::push_back(const value_type& __x)
1562{
1563 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501564 typedef __allocator_destructor<__node_allocator> _Dp;
1565 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191566 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591567 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161568 ++base::__sz();
1569 __hold.release();
1570}
1571
Howard Hinnant73d21a42010-09-04 23:28:191572#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161573
1574template <class _Tp, class _Alloc>
1575void
1576list<_Tp, _Alloc>::push_front(value_type&& __x)
1577{
1578 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501579 typedef __allocator_destructor<__node_allocator> _Dp;
1580 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191581 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselier5c74b482015-12-30 20:57:591582 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161583 ++base::__sz();
1584 __hold.release();
1585}
1586
1587template <class _Tp, class _Alloc>
1588void
1589list<_Tp, _Alloc>::push_back(value_type&& __x)
1590{
1591 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501592 typedef __allocator_destructor<__node_allocator> _Dp;
1593 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191594 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselier5c74b482015-12-30 20:57:591595 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161596 ++base::__sz();
1597 __hold.release();
1598}
1599
Howard Hinnant73d21a42010-09-04 23:28:191600#ifndef _LIBCPP_HAS_NO_VARIADICS
1601
Howard Hinnantbc8d3f92010-05-11 19:42:161602template <class _Tp, class _Alloc>
1603template <class... _Args>
Eric Fiselier3816ef92016-07-21 03:20:171604typename list<_Tp, _Alloc>::reference
Howard Hinnantbc8d3f92010-05-11 19:42:161605list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1606{
1607 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501608 typedef __allocator_destructor<__node_allocator> _Dp;
1609 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191610 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselier5c74b482015-12-30 20:57:591611 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161612 ++base::__sz();
Eric Fiselier3816ef92016-07-21 03:20:171613 return __hold.release()->__value_;
Howard Hinnantbc8d3f92010-05-11 19:42:161614}
1615
1616template <class _Tp, class _Alloc>
1617template <class... _Args>
Eric Fiselier3816ef92016-07-21 03:20:171618typename list<_Tp, _Alloc>::reference
Howard Hinnantbc8d3f92010-05-11 19:42:161619list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1620{
1621 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501622 typedef __allocator_destructor<__node_allocator> _Dp;
1623 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191624 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselier5c74b482015-12-30 20:57:591625 __link_pointer __nl = __hold->__as_link();
1626 __link_nodes_at_back(__nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161627 ++base::__sz();
Eric Fiselier3816ef92016-07-21 03:20:171628 return __hold.release()->__value_;
Howard Hinnantbc8d3f92010-05-11 19:42:161629}
1630
1631template <class _Tp, class _Alloc>
1632template <class... _Args>
1633typename list<_Tp, _Alloc>::iterator
1634list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1635{
Howard Hinnant79a35572013-04-05 00:18:491636#if _LIBCPP_DEBUG_LEVEL >= 2
1637 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1638 "list::emplace(iterator, args...) called with an iterator not"
1639 " referring to this list");
1640#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161641 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501642 typedef __allocator_destructor<__node_allocator> _Dp;
1643 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161644 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191645 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselier5c74b482015-12-30 20:57:591646 __link_pointer __nl = __hold.get()->__as_link();
1647 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161648 ++base::__sz();
Eric Fiselier5c74b482015-12-30 20:57:591649 __hold.release();
Howard Hinnant1c3ec6d2011-09-27 23:55:031650#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591651 return iterator(__nl, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031652#else
Eric Fiselier5c74b482015-12-30 20:57:591653 return iterator(__nl);
Howard Hinnant1c3ec6d2011-09-27 23:55:031654#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161655}
1656
Howard Hinnant73d21a42010-09-04 23:28:191657#endif // _LIBCPP_HAS_NO_VARIADICS
1658
Howard Hinnantbc8d3f92010-05-11 19:42:161659template <class _Tp, class _Alloc>
1660typename list<_Tp, _Alloc>::iterator
1661list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1662{
Howard Hinnant1c3ec6d2011-09-27 23:55:031663#if _LIBCPP_DEBUG_LEVEL >= 2
1664 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1665 "list::insert(iterator, x) called with an iterator not"
1666 " referring to this list");
1667#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161668 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501669 typedef __allocator_destructor<__node_allocator> _Dp;
1670 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161671 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191672 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselier5c74b482015-12-30 20:57:591673 __link_pointer __nl = __hold->__as_link();
1674 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161675 ++base::__sz();
Eric Fiselier5c74b482015-12-30 20:57:591676 __hold.release();
Howard Hinnant1c3ec6d2011-09-27 23:55:031677#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591678 return iterator(__nl, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031679#else
Eric Fiselier5c74b482015-12-30 20:57:591680 return iterator(__nl);
Howard Hinnant1c3ec6d2011-09-27 23:55:031681#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161682}
1683
Howard Hinnant73d21a42010-09-04 23:28:191684#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:161685
1686template <class _Tp, class _Alloc>
1687void
1688list<_Tp, _Alloc>::pop_front()
1689{
Howard Hinnant1c3ec6d2011-09-27 23:55:031690 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161691 __node_allocator& __na = base::__node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:591692 __link_pointer __n = base::__end_.__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161693 base::__unlink_nodes(__n, __n);
1694 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031695#if _LIBCPP_DEBUG_LEVEL >= 2
1696 __c_node* __c = __get_db()->__find_c_and_lock(this);
1697 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1698 {
1699 --__p;
1700 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471701 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031702 {
1703 (*__p)->__c_ = nullptr;
1704 if (--__c->end_ != __p)
1705 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1706 }
1707 }
1708 __get_db()->unlock();
1709#endif
Eric Fiselier5c74b482015-12-30 20:57:591710 __node_pointer __np = __n->__as_node();
1711 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1712 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161713}
1714
1715template <class _Tp, class _Alloc>
1716void
1717list<_Tp, _Alloc>::pop_back()
1718{
Dmitri Gribenkoc7a39cf2013-06-24 06:15:571719 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161720 __node_allocator& __na = base::__node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:591721 __link_pointer __n = base::__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161722 base::__unlink_nodes(__n, __n);
1723 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031724#if _LIBCPP_DEBUG_LEVEL >= 2
1725 __c_node* __c = __get_db()->__find_c_and_lock(this);
1726 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1727 {
1728 --__p;
1729 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471730 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031731 {
1732 (*__p)->__c_ = nullptr;
1733 if (--__c->end_ != __p)
1734 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1735 }
1736 }
1737 __get_db()->unlock();
1738#endif
Eric Fiselier5c74b482015-12-30 20:57:591739 __node_pointer __np = __n->__as_node();
1740 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1741 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161742}
1743
1744template <class _Tp, class _Alloc>
1745typename list<_Tp, _Alloc>::iterator
1746list<_Tp, _Alloc>::erase(const_iterator __p)
1747{
Howard Hinnant1c3ec6d2011-09-27 23:55:031748#if _LIBCPP_DEBUG_LEVEL >= 2
1749 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1750 "list::erase(iterator) called with an iterator not"
1751 " referring to this list");
1752#endif
Howard Hinnant79a35572013-04-05 00:18:491753 _LIBCPP_ASSERT(__p != end(),
1754 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:161755 __node_allocator& __na = base::__node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:591756 __link_pointer __n = __p.__ptr_;
1757 __link_pointer __r = __n->__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161758 base::__unlink_nodes(__n, __n);
1759 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031760#if _LIBCPP_DEBUG_LEVEL >= 2
1761 __c_node* __c = __get_db()->__find_c_and_lock(this);
Eric Fiselier1e836f02016-10-23 19:26:391762 for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
Howard Hinnant1c3ec6d2011-09-27 23:55:031763 {
Eric Fiselier1e836f02016-10-23 19:26:391764 --__ip;
1765 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471766 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031767 {
Eric Fiselier1e836f02016-10-23 19:26:391768 (*__ip)->__c_ = nullptr;
1769 if (--__c->end_ != __ip)
1770 memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:031771 }
1772 }
1773 __get_db()->unlock();
1774#endif
Eric Fiselier5c74b482015-12-30 20:57:591775 __node_pointer __np = __n->__as_node();
1776 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1777 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant1c3ec6d2011-09-27 23:55:031778#if _LIBCPP_DEBUG_LEVEL >= 2
1779 return iterator(__r, this);
1780#else
Howard Hinnantbc8d3f92010-05-11 19:42:161781 return iterator(__r);
Howard Hinnant1c3ec6d2011-09-27 23:55:031782#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161783}
1784
1785template <class _Tp, class _Alloc>
1786typename list<_Tp, _Alloc>::iterator
1787list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1788{
Howard Hinnant1c3ec6d2011-09-27 23:55:031789#if _LIBCPP_DEBUG_LEVEL >= 2
1790 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1791 "list::erase(iterator, iterator) called with an iterator not"
1792 " referring to this list");
1793#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161794 if (__f != __l)
1795 {
1796 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471797 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:161798 while (__f != __l)
1799 {
Eric Fiselier5c74b482015-12-30 20:57:591800 __link_pointer __n = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:161801 ++__f;
1802 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031803#if _LIBCPP_DEBUG_LEVEL >= 2
1804 __c_node* __c = __get_db()->__find_c_and_lock(this);
1805 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1806 {
1807 --__p;
1808 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471809 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031810 {
1811 (*__p)->__c_ = nullptr;
1812 if (--__c->end_ != __p)
1813 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1814 }
1815 }
1816 __get_db()->unlock();
1817#endif
Eric Fiselier5c74b482015-12-30 20:57:591818 __node_pointer __np = __n->__as_node();
1819 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1820 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161821 }
1822 }
Howard Hinnant1c3ec6d2011-09-27 23:55:031823#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:471824 return iterator(__l.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031825#else
Howard Hinnant29f74322013-06-25 16:08:471826 return iterator(__l.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031827#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161828}
1829
1830template <class _Tp, class _Alloc>
1831void
1832list<_Tp, _Alloc>::resize(size_type __n)
1833{
1834 if (__n < base::__sz())
1835 erase(__iterator(__n), end());
1836 else if (__n > base::__sz())
1837 {
1838 __n -= base::__sz();
1839 size_type __ds = 0;
1840 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501841 typedef __allocator_destructor<__node_allocator> _Dp;
1842 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161843 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191844 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161845 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031846#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591847 iterator __r = iterator(__hold.release()->__as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031848#else
Eric Fiselier5c74b482015-12-30 20:57:591849 iterator __r = iterator(__hold.release()->__as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:031850#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161851 iterator __e = __r;
1852#ifndef _LIBCPP_NO_EXCEPTIONS
1853 try
1854 {
Howard Hinnant324bb032010-08-22 00:02:431855#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161856 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1857 {
1858 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191859 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Eric Fiselier5c74b482015-12-30 20:57:591860 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161861 __hold->__prev_ = __e.__ptr_;
1862 __hold.release();
1863 }
1864#ifndef _LIBCPP_NO_EXCEPTIONS
1865 }
1866 catch (...)
1867 {
1868 while (true)
1869 {
Howard Hinnant0949eed2011-06-30 21:18:191870 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591871 __link_pointer __prev = __e.__ptr_->__prev_;
1872 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161873 if (__prev == 0)
1874 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031875#if _LIBCPP_DEBUG_LEVEL >= 2
1876 __e = iterator(__prev, this);
1877#else
Howard Hinnantbc8d3f92010-05-11 19:42:161878 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031879#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161880 }
1881 throw;
1882 }
Howard Hinnant324bb032010-08-22 00:02:431883#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clowea8ed832014-08-05 01:34:121884 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161885 base::__sz() += __ds;
1886 }
1887}
1888
1889template <class _Tp, class _Alloc>
1890void
1891list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1892{
1893 if (__n < base::__sz())
1894 erase(__iterator(__n), end());
1895 else if (__n > base::__sz())
1896 {
1897 __n -= base::__sz();
1898 size_type __ds = 0;
1899 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501900 typedef __allocator_destructor<__node_allocator> _Dp;
1901 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161902 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191903 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161904 ++__ds;
Eric Fiselier5c74b482015-12-30 20:57:591905 __link_pointer __nl = __hold.release()->__as_link();
Howard Hinnant1c3ec6d2011-09-27 23:55:031906#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591907 iterator __r = iterator(__nl, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031908#else
Eric Fiselier5c74b482015-12-30 20:57:591909 iterator __r = iterator(__nl);
Howard Hinnant1c3ec6d2011-09-27 23:55:031910#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161911 iterator __e = __r;
1912#ifndef _LIBCPP_NO_EXCEPTIONS
1913 try
1914 {
Howard Hinnant324bb032010-08-22 00:02:431915#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161916 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1917 {
1918 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191919 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591920 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161921 __hold->__prev_ = __e.__ptr_;
1922 __hold.release();
1923 }
1924#ifndef _LIBCPP_NO_EXCEPTIONS
1925 }
1926 catch (...)
1927 {
1928 while (true)
1929 {
Howard Hinnant0949eed2011-06-30 21:18:191930 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591931 __link_pointer __prev = __e.__ptr_->__prev_;
1932 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161933 if (__prev == 0)
1934 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031935#if _LIBCPP_DEBUG_LEVEL >= 2
1936 __e = iterator(__prev, this);
1937#else
Howard Hinnantbc8d3f92010-05-11 19:42:161938 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031939#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161940 }
1941 throw;
1942 }
Howard Hinnant324bb032010-08-22 00:02:431943#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier8e7bd4f2016-01-04 03:27:521944 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161945 base::__sz() += __ds;
Howard Hinnant324bb032010-08-22 00:02:431946 }
Howard Hinnantbc8d3f92010-05-11 19:42:161947}
1948
1949template <class _Tp, class _Alloc>
1950void
1951list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1952{
Howard Hinnant1c3ec6d2011-09-27 23:55:031953 _LIBCPP_ASSERT(this != &__c,
1954 "list::splice(iterator, list) called with this == &list");
1955#if _LIBCPP_DEBUG_LEVEL >= 2
1956 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1957 "list::splice(iterator, list) called with an iterator not"
1958 " referring to this list");
1959#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161960 if (!__c.empty())
1961 {
Eric Fiselier5c74b482015-12-30 20:57:591962 __link_pointer __f = __c.__end_.__next_;
1963 __link_pointer __l = __c.__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161964 base::__unlink_nodes(__f, __l);
Howard Hinnant29f74322013-06-25 16:08:471965 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161966 base::__sz() += __c.__sz();
1967 __c.__sz() = 0;
Howard Hinnant1c3ec6d2011-09-27 23:55:031968#if _LIBCPP_DEBUG_LEVEL >= 2
1969 __libcpp_db* __db = __get_db();
1970 __c_node* __cn1 = __db->__find_c_and_lock(this);
1971 __c_node* __cn2 = __db->__find_c(&__c);
Eric Fiselier1e836f02016-10-23 19:26:391972 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
Howard Hinnant1c3ec6d2011-09-27 23:55:031973 {
Eric Fiselier1e836f02016-10-23 19:26:391974 --__ip;
1975 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:521976 if (__i->__ptr_ != __c.__end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:031977 {
Eric Fiselier1e836f02016-10-23 19:26:391978 __cn1->__add(*__ip);
1979 (*__ip)->__c_ = __cn1;
1980 if (--__cn2->end_ != __ip)
1981 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:031982 }
1983 }
1984 __db->unlock();
1985#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161986 }
1987}
1988
1989template <class _Tp, class _Alloc>
1990void
1991list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1992{
Howard Hinnant1c3ec6d2011-09-27 23:55:031993#if _LIBCPP_DEBUG_LEVEL >= 2
1994 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1995 "list::splice(iterator, list, iterator) called with first iterator not"
1996 " referring to this list");
1997 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
1998 "list::splice(iterator, list, iterator) called with second iterator not"
1999 " referring to list argument");
2000 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
2001 "list::splice(iterator, list, iterator) called with second iterator not"
2002 " derefereceable");
2003#endif
2004 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnantbc8d3f92010-05-11 19:42:162005 {
Eric Fiselier5c74b482015-12-30 20:57:592006 __link_pointer __f = __i.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162007 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:472008 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:162009 --__c.__sz();
2010 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:032011#if _LIBCPP_DEBUG_LEVEL >= 2
2012 __libcpp_db* __db = __get_db();
2013 __c_node* __cn1 = __db->__find_c_and_lock(this);
2014 __c_node* __cn2 = __db->__find_c(&__c);
Eric Fiselier1e836f02016-10-23 19:26:392015 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
Howard Hinnant1c3ec6d2011-09-27 23:55:032016 {
Eric Fiselier1e836f02016-10-23 19:26:392017 --__ip;
2018 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
Howard Hinnant29f74322013-06-25 16:08:472019 if (__j->__ptr_ == __f)
Howard Hinnant1c3ec6d2011-09-27 23:55:032020 {
Eric Fiselier1e836f02016-10-23 19:26:392021 __cn1->__add(*__ip);
2022 (*__ip)->__c_ = __cn1;
2023 if (--__cn2->end_ != __ip)
2024 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:032025 }
2026 }
2027 __db->unlock();
2028#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162029 }
2030}
2031
2032template <class _Tp, class _Alloc>
2033void
2034list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
2035{
Howard Hinnant1c3ec6d2011-09-27 23:55:032036#if _LIBCPP_DEBUG_LEVEL >= 2
2037 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2038 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2039 " referring to this list");
2040 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2041 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2042 " referring to list argument");
2043 if (this == &__c)
2044 {
2045 for (const_iterator __i = __f; __i != __l; ++__i)
2046 _LIBCPP_ASSERT(__i != __p,
2047 "list::splice(iterator, list, iterator, iterator)"
2048 " called with the first iterator within the range"
2049 " of the second and third iterators");
2050 }
2051#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162052 if (__f != __l)
2053 {
2054 if (this != &__c)
2055 {
Howard Hinnant0949eed2011-06-30 21:18:192056 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162057 __c.__sz() -= __s;
2058 base::__sz() += __s;
2059 }
Eric Fiselier5c74b482015-12-30 20:57:592060 __link_pointer __first = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162061 --__l;
Eric Fiselier5c74b482015-12-30 20:57:592062 __link_pointer __last = __l.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162063 base::__unlink_nodes(__first, __last);
Howard Hinnant29f74322013-06-25 16:08:472064 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant1c3ec6d2011-09-27 23:55:032065#if _LIBCPP_DEBUG_LEVEL >= 2
2066 __libcpp_db* __db = __get_db();
2067 __c_node* __cn1 = __db->__find_c_and_lock(this);
2068 __c_node* __cn2 = __db->__find_c(&__c);
Eric Fiselier1e836f02016-10-23 19:26:392069 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
Howard Hinnant1c3ec6d2011-09-27 23:55:032070 {
Eric Fiselier1e836f02016-10-23 19:26:392071 --__ip;
2072 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
Eric Fiselier5c74b482015-12-30 20:57:592073 for (__link_pointer __k = __f.__ptr_;
Howard Hinnant1c3ec6d2011-09-27 23:55:032074 __k != __l.__ptr_; __k = __k->__next_)
2075 {
2076 if (__j->__ptr_ == __k)
2077 {
Eric Fiselier1e836f02016-10-23 19:26:392078 __cn1->__add(*__ip);
2079 (*__ip)->__c_ = __cn1;
2080 if (--__cn2->end_ != __ip)
2081 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:032082 }
2083 }
2084 }
2085 __db->unlock();
2086#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162087 }
2088}
2089
2090template <class _Tp, class _Alloc>
2091void
2092list<_Tp, _Alloc>::remove(const value_type& __x)
2093{
Marshall Clowfca038e2014-08-08 15:35:522094 list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
2095 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnantbc8d3f92010-05-11 19:42:162096 {
2097 if (*__i == __x)
2098 {
Marshall Clowfca038e2014-08-08 15:35:522099 const_iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162100 for (; __j != __e && *__j == __x; ++__j)
2101 ;
Marshall Clowfca038e2014-08-08 15:35:522102 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2103 __i = __j;
Marshall Clowf0f1bca2014-08-04 17:32:252104 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122105 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162106 }
2107 else
2108 ++__i;
2109 }
2110}
2111
2112template <class _Tp, class _Alloc>
2113template <class _Pred>
2114void
2115list<_Tp, _Alloc>::remove_if(_Pred __pred)
2116{
2117 for (iterator __i = begin(), __e = end(); __i != __e;)
2118 {
2119 if (__pred(*__i))
2120 {
Howard Hinnant0949eed2011-06-30 21:18:192121 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162122 for (; __j != __e && __pred(*__j); ++__j)
2123 ;
2124 __i = erase(__i, __j);
Marshall Clowf0f1bca2014-08-04 17:32:252125 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122126 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162127 }
2128 else
2129 ++__i;
2130 }
2131}
2132
2133template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552134inline
Howard Hinnantbc8d3f92010-05-11 19:42:162135void
2136list<_Tp, _Alloc>::unique()
2137{
2138 unique(__equal_to<value_type>());
2139}
2140
2141template <class _Tp, class _Alloc>
2142template <class _BinaryPred>
2143void
2144list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2145{
2146 for (iterator __i = begin(), __e = end(); __i != __e;)
2147 {
Howard Hinnant0949eed2011-06-30 21:18:192148 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162149 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2150 ;
2151 if (++__i != __j)
2152 __i = erase(__i, __j);
2153 }
2154}
2155
2156template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552157inline
Howard Hinnantbc8d3f92010-05-11 19:42:162158void
2159list<_Tp, _Alloc>::merge(list& __c)
2160{
2161 merge(__c, __less<value_type>());
2162}
2163
2164template <class _Tp, class _Alloc>
2165template <class _Comp>
2166void
2167list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2168{
2169 if (this != &__c)
2170 {
2171 iterator __f1 = begin();
2172 iterator __e1 = end();
2173 iterator __f2 = __c.begin();
2174 iterator __e2 = __c.end();
2175 while (__f1 != __e1 && __f2 != __e2)
2176 {
2177 if (__comp(*__f2, *__f1))
2178 {
2179 size_type __ds = 1;
Howard Hinnant0949eed2011-06-30 21:18:192180 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162181 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2182 ;
2183 base::__sz() += __ds;
2184 __c.__sz() -= __ds;
Eric Fiselier5c74b482015-12-30 20:57:592185 __link_pointer __f = __f2.__ptr_;
2186 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162187 __f2 = __m2;
2188 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192189 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472190 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162191 __f1 = __m2;
2192 }
2193 else
2194 ++__f1;
2195 }
2196 splice(__e1, __c);
Howard Hinnant1c3ec6d2011-09-27 23:55:032197#if _LIBCPP_DEBUG_LEVEL >= 2
2198 __libcpp_db* __db = __get_db();
2199 __c_node* __cn1 = __db->__find_c_and_lock(this);
2200 __c_node* __cn2 = __db->__find_c(&__c);
2201 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2202 {
2203 --__p;
2204 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:522205 if (__i->__ptr_ != __c.__end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:032206 {
2207 __cn1->__add(*__p);
2208 (*__p)->__c_ = __cn1;
2209 if (--__cn2->end_ != __p)
2210 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2211 }
2212 }
2213 __db->unlock();
2214#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162215 }
2216}
2217
2218template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552219inline
Howard Hinnantbc8d3f92010-05-11 19:42:162220void
2221list<_Tp, _Alloc>::sort()
2222{
2223 sort(__less<value_type>());
2224}
2225
2226template <class _Tp, class _Alloc>
2227template <class _Comp>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552228inline
Howard Hinnantbc8d3f92010-05-11 19:42:162229void
2230list<_Tp, _Alloc>::sort(_Comp __comp)
2231{
2232 __sort(begin(), end(), base::__sz(), __comp);
2233}
2234
2235template <class _Tp, class _Alloc>
2236template <class _Comp>
Howard Hinnantbc8d3f92010-05-11 19:42:162237typename list<_Tp, _Alloc>::iterator
2238list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2239{
2240 switch (__n)
2241 {
2242 case 0:
2243 case 1:
2244 return __f1;
2245 case 2:
2246 if (__comp(*--__e2, *__f1))
2247 {
Eric Fiselier5c74b482015-12-30 20:57:592248 __link_pointer __f = __e2.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162249 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:472250 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:162251 return __e2;
2252 }
2253 return __f1;
2254 }
2255 size_type __n2 = __n / 2;
Howard Hinnant0949eed2011-06-30 21:18:192256 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnantbc8d3f92010-05-11 19:42:162257 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2258 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2259 if (__comp(*__f2, *__f1))
2260 {
Howard Hinnant0949eed2011-06-30 21:18:192261 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162262 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2263 ;
Eric Fiselier5c74b482015-12-30 20:57:592264 __link_pointer __f = __f2.__ptr_;
2265 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162266 __r = __f2;
2267 __e1 = __f2 = __m2;
2268 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192269 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472270 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162271 __f1 = __m2;
2272 }
2273 else
2274 ++__f1;
2275 while (__f1 != __e1 && __f2 != __e2)
2276 {
2277 if (__comp(*__f2, *__f1))
2278 {
Howard Hinnant0949eed2011-06-30 21:18:192279 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162280 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2281 ;
Eric Fiselier5c74b482015-12-30 20:57:592282 __link_pointer __f = __f2.__ptr_;
2283 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162284 if (__e1 == __f2)
2285 __e1 = __m2;
2286 __f2 = __m2;
2287 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192288 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472289 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162290 __f1 = __m2;
2291 }
2292 else
2293 ++__f1;
2294 }
2295 return __r;
2296}
2297
2298template <class _Tp, class _Alloc>
2299void
Howard Hinnantc5607272011-06-03 17:30:282300list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162301{
2302 if (base::__sz() > 1)
2303 {
2304 iterator __e = end();
Howard Hinnant1c3ec6d2011-09-27 23:55:032305 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2306 {
Howard Hinnant0949eed2011-06-30 21:18:192307 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant1c3ec6d2011-09-27 23:55:032308 __i.__ptr_ = __i.__ptr_->__prev_;
2309 }
Howard Hinnant0949eed2011-06-30 21:18:192310 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:162311 }
2312}
2313
2314template <class _Tp, class _Alloc>
Howard Hinnant1c3ec6d2011-09-27 23:55:032315bool
2316list<_Tp, _Alloc>::__invariants() const
2317{
2318 return size() == _VSTD::distance(begin(), end());
2319}
2320
2321#if _LIBCPP_DEBUG_LEVEL >= 2
2322
2323template <class _Tp, class _Alloc>
2324bool
2325list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2326{
Eric Fiselier8e7bd4f2016-01-04 03:27:522327 return __i->__ptr_ != this->__end_as_link();
Howard Hinnant1c3ec6d2011-09-27 23:55:032328}
2329
2330template <class _Tp, class _Alloc>
2331bool
2332list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2333{
2334 return !empty() && __i->__ptr_ != base::__end_.__next_;
2335}
2336
2337template <class _Tp, class _Alloc>
2338bool
2339list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
2340{
2341 return false;
2342}
2343
2344template <class _Tp, class _Alloc>
2345bool
2346list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
2347{
2348 return false;
2349}
2350
2351#endif // _LIBCPP_DEBUG_LEVEL >= 2
2352
2353template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342354inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162355bool
2356operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2357{
Howard Hinnant0949eed2011-06-30 21:18:192358 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:162359}
2360
2361template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342362inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162363bool
2364operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2365{
Howard Hinnant0949eed2011-06-30 21:18:192366 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162367}
2368
2369template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342370inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162371bool
2372operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2373{
2374 return !(__x == __y);
2375}
2376
2377template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342378inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162379bool
2380operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2381{
2382 return __y < __x;
2383}
2384
2385template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342386inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162387bool
2388operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2389{
2390 return !(__x < __y);
2391}
2392
2393template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342394inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162395bool
2396operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2397{
2398 return !(__y < __x);
2399}
2400
2401template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342402inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162403void
2404swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnantc5607272011-06-03 17:30:282405 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162406{
2407 __x.swap(__y);
2408}
2409
2410_LIBCPP_END_NAMESPACE_STD
2411
2412#endif // _LIBCPP_LIST