blob: 5e76d1103371df1e9cdb41509c0c3bdc73bbf504 [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>
Marshall Clow4e42dc92017-01-24 23:09:1296 reference emplace_front(Args&&... args); // reference in C++17
Howard Hinnantbc8d3f92010-05-11 19:42:1697 void pop_front();
98 template <class... Args>
Marshall Clow4e42dc92017-01-24 23:09:1299 reference emplace_back(Args&&... args); // reference in C++17
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
Eric Fiselierc3589a82017-01-04 23:56:00269template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
Howard Hinnant2b1b2d42011-06-14 19:58:17270template <class _Tp, class _Alloc> class __list_imp;
Eric Fiselierc3589a82017-01-04 23:56:00271template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16272
273template <class _Tp, class _VoidPtr>
Eric Fiselierc3589a82017-01-04 23:56:00274class _LIBCPP_TEMPLATE_VIS __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>
Eric Fiselierc3589a82017-01-04 23:56:00397class _LIBCPP_TEMPLATE_VIS __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
Eric Fiselierfb342382016-12-28 06:06:09629 _NOEXCEPT_DEBUG;
Marshall Clow7d914d12015-07-13 20:04:56630#else
Eric Fiselierfb342382016-12-28 06:06:09631 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56632 __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
Eric Fiselier0e5ebbc2016-12-23 23:37:52658 void __copy_assign_alloc(const __list_imp&, false_type)
Howard Hinnantbc8d3f92010-05-11 19:42:16659 {}
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
Eric Fiselier0e5ebbc2016-12-23 23:37:52669 void __move_assign_alloc(__list_imp&, false_type)
Howard Hinnantc5607272011-06-03 17:30:28670 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16671 {}
Eric Fiselierfb342382016-12-28 06:06:09672
673 _LIBCPP_INLINE_VISIBILITY
674 void __invalidate_all_iterators() {
675#if _LIBCPP_DEBUG_LEVEL >= 2
676 __get_db()->__invalidate_all(this);
677#endif
678 }
Howard Hinnantbc8d3f92010-05-11 19:42:16679};
680
681// Unlink nodes [__f, __l]
682template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55683inline
Howard Hinnantbc8d3f92010-05-11 19:42:16684void
Eric Fiselier5c74b482015-12-30 20:57:59685__list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l)
Howard Hinnantc5607272011-06-03 17:30:28686 _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16687{
Howard Hinnant29f74322013-06-25 16:08:47688 __f->__prev_->__next_ = __l->__next_;
689 __l->__next_->__prev_ = __f->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:16690}
691
692template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55693inline
Howard Hinnantbc8d3f92010-05-11 19:42:16694__list_imp<_Tp, _Alloc>::__list_imp()
Howard Hinnantc5607272011-06-03 17:30:28695 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:16696 : __size_alloc_(0)
697{
698}
699
700template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:55701inline
Howard Hinnantbc8d3f92010-05-11 19:42:16702__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a)
703 : __size_alloc_(0, __node_allocator(__a))
704{
705}
706
707template <class _Tp, class _Alloc>
708__list_imp<_Tp, _Alloc>::~__list_imp()
709{
710 clear();
Howard Hinnant1c3ec6d2011-09-27 23:55:03711#if _LIBCPP_DEBUG_LEVEL >= 2
712 __get_db()->__erase_c(this);
713#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16714}
715
716template <class _Tp, class _Alloc>
717void
Howard Hinnantc5607272011-06-03 17:30:28718__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:16719{
720 if (!empty())
721 {
722 __node_allocator& __na = __node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:59723 __link_pointer __f = __end_.__next_;
Eric Fiselier8e7bd4f2016-01-04 03:27:52724 __link_pointer __l = __end_as_link();
Howard Hinnant29f74322013-06-25 16:08:47725 __unlink_nodes(__f, __l->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:16726 __sz() = 0;
727 while (__f != __l)
728 {
Eric Fiselier5c74b482015-12-30 20:57:59729 __node_pointer __np = __f->__as_node();
Howard Hinnant1c3ec6d2011-09-27 23:55:03730 __f = __f->__next_;
Eric Fiselier5c74b482015-12-30 20:57:59731 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
732 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:16733 }
Eric Fiselierfb342382016-12-28 06:06:09734 __invalidate_all_iterators();
Howard Hinnantbc8d3f92010-05-11 19:42:16735 }
736}
737
738template <class _Tp, class _Alloc>
739void
740__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
Marshall Clow7d914d12015-07-13 20:04:56741#if _LIBCPP_STD_VER >= 14
Eric Fiselierfb342382016-12-28 06:06:09742 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:56743#else
Eric Fiselierfb342382016-12-28 06:06:09744 _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
Marshall Clow7d914d12015-07-13 20:04:56745 __is_nothrow_swappable<allocator_type>::value)
746#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16747{
Howard Hinnant1c3ec6d2011-09-27 23:55:03748 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value ||
749 this->__node_alloc() == __c.__node_alloc(),
750 "list::swap: Either propagate_on_container_swap must be true"
751 " or the allocators must compare equal");
Howard Hinnant0949eed2011-06-30 21:18:19752 using _VSTD::swap;
Marshall Clow7d914d12015-07-13 20:04:56753 __swap_allocator(__node_alloc(), __c.__node_alloc());
Howard Hinnantbc8d3f92010-05-11 19:42:16754 swap(__sz(), __c.__sz());
755 swap(__end_, __c.__end_);
756 if (__sz() == 0)
Eric Fiselier8e7bd4f2016-01-04 03:27:52757 __end_.__next_ = __end_.__prev_ = __end_as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:16758 else
Eric Fiselier8e7bd4f2016-01-04 03:27:52759 __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:16760 if (__c.__sz() == 0)
Eric Fiselier8e7bd4f2016-01-04 03:27:52761 __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:16762 else
Eric Fiselier8e7bd4f2016-01-04 03:27:52763 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link();
Marshall Clowea8ed832014-08-05 01:34:12764
Howard Hinnant1c3ec6d2011-09-27 23:55:03765#if _LIBCPP_DEBUG_LEVEL >= 2
766 __libcpp_db* __db = __get_db();
767 __c_node* __cn1 = __db->__find_c_and_lock(this);
768 __c_node* __cn2 = __db->__find_c(&__c);
769 std::swap(__cn1->beg_, __cn2->beg_);
770 std::swap(__cn1->end_, __cn2->end_);
771 std::swap(__cn1->cap_, __cn2->cap_);
772 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;)
773 {
774 --__p;
775 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:52776 if (__i->__ptr_ == __c.__end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:03777 {
778 __cn2->__add(*__p);
779 if (--__cn1->end_ != __p)
780 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*));
781 }
782 else
783 (*__p)->__c_ = __cn1;
784 }
785 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
786 {
787 --__p;
788 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:52789 if (__i->__ptr_ == __end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:03790 {
791 __cn1->__add(*__p);
792 if (--__cn2->end_ != __p)
793 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
794 }
795 else
796 (*__p)->__c_ = __cn2;
797 }
798 __db->unlock();
799#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16800}
801
Marshall Clowceead9c2015-02-18 17:24:08802template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
Eric Fiselierc3589a82017-01-04 23:56:00803class _LIBCPP_TEMPLATE_VIS list
Howard Hinnantbc8d3f92010-05-11 19:42:16804 : private __list_imp<_Tp, _Alloc>
805{
806 typedef __list_imp<_Tp, _Alloc> base;
807 typedef typename base::__node __node;
808 typedef typename base::__node_allocator __node_allocator;
809 typedef typename base::__node_pointer __node_pointer;
810 typedef typename base::__node_alloc_traits __node_alloc_traits;
Howard Hinnant29f74322013-06-25 16:08:47811 typedef typename base::__node_base __node_base;
812 typedef typename base::__node_base_pointer __node_base_pointer;
Eric Fiselier5c74b482015-12-30 20:57:59813 typedef typename base::__link_pointer __link_pointer;
Howard Hinnantbc8d3f92010-05-11 19:42:16814
815public:
816 typedef _Tp value_type;
817 typedef _Alloc allocator_type;
818 static_assert((is_same<value_type, typename allocator_type::value_type>::value),
819 "Invalid allocator::value_type");
820 typedef value_type& reference;
821 typedef const value_type& const_reference;
822 typedef typename base::pointer pointer;
823 typedef typename base::const_pointer const_pointer;
824 typedef typename base::size_type size_type;
825 typedef typename base::difference_type difference_type;
826 typedef typename base::iterator iterator;
827 typedef typename base::const_iterator const_iterator;
Howard Hinnant0949eed2011-06-30 21:18:19828 typedef _VSTD::reverse_iterator<iterator> reverse_iterator;
829 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator;
Howard Hinnantbc8d3f92010-05-11 19:42:16830
Howard Hinnant82894812010-09-22 16:48:34831 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28832 list()
833 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value)
Howard Hinnant1c3ec6d2011-09-27 23:55:03834 {
835#if _LIBCPP_DEBUG_LEVEL >= 2
836 __get_db()->__insert_c(this);
837#endif
838 }
Howard Hinnant82894812010-09-22 16:48:34839 _LIBCPP_INLINE_VISIBILITY
Marshall Clow955f2c82013-09-08 19:11:51840 explicit list(const allocator_type& __a) : base(__a)
Howard Hinnant1c3ec6d2011-09-27 23:55:03841 {
842#if _LIBCPP_DEBUG_LEVEL >= 2
843 __get_db()->__insert_c(this);
844#endif
845 }
Marshall Clow955f2c82013-09-08 19:11:51846 explicit list(size_type __n);
847#if _LIBCPP_STD_VER > 11
848 explicit list(size_type __n, const allocator_type& __a);
849#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16850 list(size_type __n, const value_type& __x);
851 list(size_type __n, const value_type& __x, const allocator_type& __a);
852 template <class _InpIter>
853 list(_InpIter __f, _InpIter __l,
854 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
855 template <class _InpIter>
856 list(_InpIter __f, _InpIter __l, const allocator_type& __a,
857 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
858
859 list(const list& __c);
860 list(const list& __c, const allocator_type& __a);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55861 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16862 list& operator=(const list& __c);
Eric Fiselier55ff80e2017-04-16 03:45:35863#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16864 list(initializer_list<value_type> __il);
865 list(initializer_list<value_type> __il, const allocator_type& __a);
Eric Fiselier55ff80e2017-04-16 03:45:35866
Evgeniy Stepanov9341a8a2016-04-22 01:04:55867 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28868 list(list&& __c)
869 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55870 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16871 list(list&& __c, const allocator_type& __a);
Evgeniy Stepanov9341a8a2016-04-22 01:04:55872 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28873 list& operator=(list&& __c)
874 _NOEXCEPT_(
875 __node_alloc_traits::propagate_on_container_move_assignment::value &&
876 is_nothrow_move_assignable<__node_allocator>::value);
Eric Fiselier55ff80e2017-04-16 03:45:35877
Howard Hinnant82894812010-09-22 16:48:34878 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:16879 list& operator=(initializer_list<value_type> __il)
880 {assign(__il.begin(), __il.end()); return *this;}
Eric Fiselier55ff80e2017-04-16 03:45:35881
882 _LIBCPP_INLINE_VISIBILITY
883 void assign(initializer_list<value_type> __il)
884 {assign(__il.begin(), __il.end());}
885#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16886
887 template <class _InpIter>
888 void assign(_InpIter __f, _InpIter __l,
889 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
890 void assign(size_type __n, const value_type& __x);
Howard Hinnantbc8d3f92010-05-11 19:42:16891
Evgeniy Stepanov9341a8a2016-04-22 01:04:55892 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28893 allocator_type get_allocator() const _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:16894
Howard Hinnant82894812010-09-22 16:48:34895 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28896 size_type size() const _NOEXCEPT {return base::__sz();}
Howard Hinnant82894812010-09-22 16:48:34897 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28898 bool empty() const _NOEXCEPT {return base::empty();}
Howard Hinnant82894812010-09-22 16:48:34899 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28900 size_type max_size() const _NOEXCEPT
Eric Fiselieref3060e2016-11-23 01:18:56901 {
902 return std::min<size_type>(
903 base::__node_alloc_max_size(),
904 numeric_limits<difference_type >::max());
905 }
Howard Hinnantbc8d3f92010-05-11 19:42:16906
Howard Hinnant82894812010-09-22 16:48:34907 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28908 iterator begin() _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34909 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28910 const_iterator begin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34911 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28912 iterator end() _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34913 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28914 const_iterator end() const _NOEXCEPT {return base::end();}
Howard Hinnant82894812010-09-22 16:48:34915 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28916 const_iterator cbegin() const _NOEXCEPT {return base::begin();}
Howard Hinnant82894812010-09-22 16:48:34917 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28918 const_iterator cend() const _NOEXCEPT {return base::end();}
Howard Hinnantbc8d3f92010-05-11 19:42:16919
Howard Hinnant82894812010-09-22 16:48:34920 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28921 reverse_iterator rbegin() _NOEXCEPT
922 {return reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34923 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28924 const_reverse_iterator rbegin() const _NOEXCEPT
925 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34926 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28927 reverse_iterator rend() _NOEXCEPT
928 {return reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34929 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28930 const_reverse_iterator rend() const _NOEXCEPT
931 {return const_reverse_iterator(begin());}
Howard Hinnant82894812010-09-22 16:48:34932 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28933 const_reverse_iterator crbegin() const _NOEXCEPT
934 {return const_reverse_iterator(end());}
Howard Hinnant82894812010-09-22 16:48:34935 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:28936 const_reverse_iterator crend() const _NOEXCEPT
937 {return const_reverse_iterator(begin());}
Howard Hinnantbc8d3f92010-05-11 19:42:16938
Howard Hinnant82894812010-09-22 16:48:34939 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03940 reference front()
941 {
942 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59943 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03944 }
Howard Hinnant82894812010-09-22 16:48:34945 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03946 const_reference front() const
947 {
948 _LIBCPP_ASSERT(!empty(), "list::front called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59949 return base::__end_.__next_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03950 }
Howard Hinnant82894812010-09-22 16:48:34951 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03952 reference back()
953 {
954 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59955 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03956 }
Howard Hinnant82894812010-09-22 16:48:34957 _LIBCPP_INLINE_VISIBILITY
Howard Hinnant1c3ec6d2011-09-27 23:55:03958 const_reference back() const
959 {
960 _LIBCPP_ASSERT(!empty(), "list::back called on empty list");
Eric Fiselier5c74b482015-12-30 20:57:59961 return base::__end_.__prev_->__as_node()->__value_;
Howard Hinnant1c3ec6d2011-09-27 23:55:03962 }
Howard Hinnantbc8d3f92010-05-11 19:42:16963
Eric Fiselier55ff80e2017-04-16 03:45:35964#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16965 void push_front(value_type&& __x);
966 void push_back(value_type&& __x);
Eric Fiselier55ff80e2017-04-16 03:45:35967
Howard Hinnantbc8d3f92010-05-11 19:42:16968 template <class... _Args>
Marshall Clow4e42dc92017-01-24 23:09:12969#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:17970 reference emplace_front(_Args&&... __args);
Marshall Clow4e42dc92017-01-24 23:09:12971#else
972 void emplace_front(_Args&&... __args);
973#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16974 template <class... _Args>
Marshall Clow4e42dc92017-01-24 23:09:12975#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:17976 reference emplace_back(_Args&&... __args);
Marshall Clow4e42dc92017-01-24 23:09:12977#else
978 void emplace_back(_Args&&... __args);
979#endif
Howard Hinnantbc8d3f92010-05-11 19:42:16980 template <class... _Args>
981 iterator emplace(const_iterator __p, _Args&&... __args);
Eric Fiselier55ff80e2017-04-16 03:45:35982
Howard Hinnantbc8d3f92010-05-11 19:42:16983 iterator insert(const_iterator __p, value_type&& __x);
Eric Fiselier55ff80e2017-04-16 03:45:35984
985 _LIBCPP_INLINE_VISIBILITY
986 iterator insert(const_iterator __p, initializer_list<value_type> __il)
987 {return insert(__p, __il.begin(), __il.end());}
988#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:16989
990 void push_front(const value_type& __x);
991 void push_back(const value_type& __x);
992
993 iterator insert(const_iterator __p, const value_type& __x);
994 iterator insert(const_iterator __p, size_type __n, const value_type& __x);
995 template <class _InpIter>
996 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l,
997 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0);
Howard Hinnantbc8d3f92010-05-11 19:42:16998
Howard Hinnant82894812010-09-22 16:48:34999 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:281000 void swap(list& __c)
Marshall Clow7d914d12015-07-13 20:04:561001#if _LIBCPP_STD_VER >= 14
Eric Fiselierfb342382016-12-28 06:06:091002 _NOEXCEPT_DEBUG
Marshall Clow7d914d12015-07-13 20:04:561003#else
Eric Fiselierfb342382016-12-28 06:06:091004 _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value ||
Howard Hinnantc5607272011-06-03 17:30:281005 __is_nothrow_swappable<__node_allocator>::value)
Marshall Clow7d914d12015-07-13 20:04:561006#endif
Howard Hinnantc5607272011-06-03 17:30:281007 {base::swap(__c);}
Howard Hinnant82894812010-09-22 16:48:341008 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantc5607272011-06-03 17:30:281009 void clear() _NOEXCEPT {base::clear();}
Howard Hinnantbc8d3f92010-05-11 19:42:161010
1011 void pop_front();
1012 void pop_back();
1013
1014 iterator erase(const_iterator __p);
1015 iterator erase(const_iterator __f, const_iterator __l);
1016
1017 void resize(size_type __n);
1018 void resize(size_type __n, const value_type& __x);
1019
1020 void splice(const_iterator __p, list& __c);
Eric Fiselier55ff80e2017-04-16 03:45:351021#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant82894812010-09-22 16:48:341022 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161023 void splice(const_iterator __p, list&& __c) {splice(__p, __c);}
Howard Hinnant82894812010-09-22 16:48:341024 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161025 void splice(const_iterator __p, list&& __c, const_iterator __i)
1026 {splice(__p, __c, __i);}
Howard Hinnant82894812010-09-22 16:48:341027 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161028 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l)
1029 {splice(__p, __c, __f, __l);}
Eric Fiselier55ff80e2017-04-16 03:45:351030#endif
1031 void splice(const_iterator __p, list& __c, const_iterator __i);
1032 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161033
1034 void remove(const value_type& __x);
1035 template <class _Pred> void remove_if(_Pred __pred);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551036 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161037 void unique();
1038 template <class _BinaryPred>
1039 void unique(_BinaryPred __binary_pred);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551040 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161041 void merge(list& __c);
Eric Fiselier55ff80e2017-04-16 03:45:351042#ifndef _LIBCPP_CXX03_LANG
Howard Hinnant82894812010-09-22 16:48:341043 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161044 void merge(list&& __c) {merge(__c);}
Eric Fiselier55ff80e2017-04-16 03:45:351045
Howard Hinnantbc8d3f92010-05-11 19:42:161046 template <class _Comp>
Howard Hinnant82894812010-09-22 16:48:341047 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161048 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);}
Eric Fiselier55ff80e2017-04-16 03:45:351049#endif
1050 template <class _Comp>
1051 void merge(list& __c, _Comp __comp);
1052
Evgeniy Stepanov9341a8a2016-04-22 01:04:551053 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161054 void sort();
1055 template <class _Comp>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551056 _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:161057 void sort(_Comp __comp);
1058
Howard Hinnantc5607272011-06-03 17:30:281059 void reverse() _NOEXCEPT;
Howard Hinnantbc8d3f92010-05-11 19:42:161060
Howard Hinnant1c3ec6d2011-09-27 23:55:031061 bool __invariants() const;
1062
1063#if _LIBCPP_DEBUG_LEVEL >= 2
1064
1065 bool __dereferenceable(const const_iterator* __i) const;
1066 bool __decrementable(const const_iterator* __i) const;
1067 bool __addable(const const_iterator* __i, ptrdiff_t __n) const;
1068 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const;
1069
1070#endif // _LIBCPP_DEBUG_LEVEL >= 2
1071
Howard Hinnantbc8d3f92010-05-11 19:42:161072private:
Evgeniy Stepanov9341a8a2016-04-22 01:04:551073 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:591074 static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551075 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:591076 void __link_nodes_at_front(__link_pointer __f, __link_pointer __l);
Evgeniy Stepanov9341a8a2016-04-22 01:04:551077 _LIBCPP_INLINE_VISIBILITY
Eric Fiselier5c74b482015-12-30 20:57:591078 void __link_nodes_at_back (__link_pointer __f, __link_pointer __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161079 iterator __iterator(size_type __n);
1080 template <class _Comp>
1081 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp);
1082
Howard Hinnantc5607272011-06-03 17:30:281083 void __move_assign(list& __c, true_type)
1084 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value);
Howard Hinnantbc8d3f92010-05-11 19:42:161085 void __move_assign(list& __c, false_type);
1086};
1087
1088// Link in nodes [__f, __l] just prior to __p
1089template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551090inline
Howard Hinnantbc8d3f92010-05-11 19:42:161091void
Eric Fiselier5c74b482015-12-30 20:57:591092list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l)
Howard Hinnantbc8d3f92010-05-11 19:42:161093{
Howard Hinnant29f74322013-06-25 16:08:471094 __p->__prev_->__next_ = __f;
1095 __f->__prev_ = __p->__prev_;
1096 __p->__prev_ = __l;
1097 __l->__next_ = __p;
Howard Hinnantbc8d3f92010-05-11 19:42:161098}
1099
Marshall Clowea8ed832014-08-05 01:34:121100// Link in nodes [__f, __l] at the front of the list
1101template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551102inline
Marshall Clowea8ed832014-08-05 01:34:121103void
Eric Fiselier5c74b482015-12-30 20:57:591104list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l)
Marshall Clowea8ed832014-08-05 01:34:121105{
Eric Fiselier8e7bd4f2016-01-04 03:27:521106 __f->__prev_ = base::__end_as_link();
Marshall Clowfca038e2014-08-08 15:35:521107 __l->__next_ = base::__end_.__next_;
1108 __l->__next_->__prev_ = __l;
1109 base::__end_.__next_ = __f;
Marshall Clowea8ed832014-08-05 01:34:121110}
1111
1112// Link in nodes [__f, __l] at the front of the list
1113template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551114inline
Marshall Clowea8ed832014-08-05 01:34:121115void
Eric Fiselier5c74b482015-12-30 20:57:591116list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l)
Marshall Clowea8ed832014-08-05 01:34:121117{
Eric Fiselier8e7bd4f2016-01-04 03:27:521118 __l->__next_ = base::__end_as_link();
Marshall Clowfca038e2014-08-08 15:35:521119 __f->__prev_ = base::__end_.__prev_;
1120 __f->__prev_->__next_ = __f;
1121 base::__end_.__prev_ = __l;
Marshall Clowea8ed832014-08-05 01:34:121122}
1123
1124
Howard Hinnantbc8d3f92010-05-11 19:42:161125template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551126inline
Howard Hinnantbc8d3f92010-05-11 19:42:161127typename list<_Tp, _Alloc>::iterator
1128list<_Tp, _Alloc>::__iterator(size_type __n)
1129{
Howard Hinnant0949eed2011-06-30 21:18:191130 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n)
1131 : _VSTD::prev(end(), base::__sz() - __n);
Howard Hinnantbc8d3f92010-05-11 19:42:161132}
1133
1134template <class _Tp, class _Alloc>
1135list<_Tp, _Alloc>::list(size_type __n)
1136{
Howard Hinnant1c3ec6d2011-09-27 23:55:031137#if _LIBCPP_DEBUG_LEVEL >= 2
1138 __get_db()->__insert_c(this);
1139#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161140 for (; __n > 0; --__n)
Eric Fiselier55ff80e2017-04-16 03:45:351141#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161142 emplace_back();
1143#else
1144 push_back(value_type());
1145#endif
1146}
1147
Marshall Clow955f2c82013-09-08 19:11:511148#if _LIBCPP_STD_VER > 11
1149template <class _Tp, class _Alloc>
1150list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
1151{
1152#if _LIBCPP_DEBUG_LEVEL >= 2
1153 __get_db()->__insert_c(this);
1154#endif
1155 for (; __n > 0; --__n)
Marshall Clow955f2c82013-09-08 19:11:511156 emplace_back();
Marshall Clow955f2c82013-09-08 19:11:511157}
1158#endif
1159
Howard Hinnantbc8d3f92010-05-11 19:42:161160template <class _Tp, class _Alloc>
1161list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
1162{
Howard Hinnant1c3ec6d2011-09-27 23:55:031163#if _LIBCPP_DEBUG_LEVEL >= 2
1164 __get_db()->__insert_c(this);
1165#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161166 for (; __n > 0; --__n)
1167 push_back(__x);
1168}
1169
1170template <class _Tp, class _Alloc>
1171list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a)
1172 : base(__a)
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>
1182template <class _InpIter>
1183list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l,
1184 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1185{
Howard Hinnant1c3ec6d2011-09-27 23:55:031186#if _LIBCPP_DEBUG_LEVEL >= 2
1187 __get_db()->__insert_c(this);
1188#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161189 for (; __f != __l; ++__f)
1190 push_back(*__f);
1191}
1192
1193template <class _Tp, class _Alloc>
1194template <class _InpIter>
1195list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a,
1196 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1197 : base(__a)
1198{
Howard Hinnant1c3ec6d2011-09-27 23:55:031199#if _LIBCPP_DEBUG_LEVEL >= 2
1200 __get_db()->__insert_c(this);
1201#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161202 for (; __f != __l; ++__f)
1203 push_back(*__f);
1204}
1205
1206template <class _Tp, class _Alloc>
1207list<_Tp, _Alloc>::list(const list& __c)
1208 : base(allocator_type(
1209 __node_alloc_traits::select_on_container_copy_construction(
1210 __c.__node_alloc())))
1211{
Howard Hinnant1c3ec6d2011-09-27 23:55:031212#if _LIBCPP_DEBUG_LEVEL >= 2
1213 __get_db()->__insert_c(this);
1214#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161215 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i)
1216 push_back(*__i);
1217}
1218
1219template <class _Tp, class _Alloc>
1220list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a)
1221 : base(__a)
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
Eric Fiselier55ff80e2017-04-16 03:45:351230#ifndef _LIBCPP_CXX03_LANG
Howard Hinnante3e32912011-08-12 21:56:021231
Howard Hinnantbc8d3f92010-05-11 19:42:161232template <class _Tp, class _Alloc>
1233list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a)
1234 : base(__a)
1235{
Howard Hinnant1c3ec6d2011-09-27 23:55:031236#if _LIBCPP_DEBUG_LEVEL >= 2
1237 __get_db()->__insert_c(this);
1238#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161239 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(),
1240 __e = __il.end(); __i != __e; ++__i)
1241 push_back(*__i);
1242}
1243
1244template <class _Tp, class _Alloc>
1245list<_Tp, _Alloc>::list(initializer_list<value_type> __il)
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
Howard Hinnantbc8d3f92010-05-11 19:42:161255template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551256inline
Howard Hinnantbc8d3f92010-05-11 19:42:161257list<_Tp, _Alloc>::list(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281258 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value)
Howard Hinnant0949eed2011-06-30 21:18:191259 : base(allocator_type(_VSTD::move(__c.__node_alloc())))
Howard Hinnantbc8d3f92010-05-11 19:42:161260{
Howard Hinnant1c3ec6d2011-09-27 23:55:031261#if _LIBCPP_DEBUG_LEVEL >= 2
1262 __get_db()->__insert_c(this);
1263#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161264 splice(end(), __c);
1265}
1266
1267template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551268inline
Howard Hinnantbc8d3f92010-05-11 19:42:161269list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a)
1270 : base(__a)
1271{
Howard Hinnant1c3ec6d2011-09-27 23:55:031272#if _LIBCPP_DEBUG_LEVEL >= 2
1273 __get_db()->__insert_c(this);
1274#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161275 if (__a == __c.get_allocator())
1276 splice(end(), __c);
1277 else
1278 {
Howard Hinnant99968442011-11-29 18:15:501279 typedef move_iterator<iterator> _Ip;
1280 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161281 }
1282}
1283
1284template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551285inline
Howard Hinnantbc8d3f92010-05-11 19:42:161286list<_Tp, _Alloc>&
1287list<_Tp, _Alloc>::operator=(list&& __c)
Howard Hinnantc5607272011-06-03 17:30:281288 _NOEXCEPT_(
1289 __node_alloc_traits::propagate_on_container_move_assignment::value &&
1290 is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161291{
1292 __move_assign(__c, integral_constant<bool,
1293 __node_alloc_traits::propagate_on_container_move_assignment::value>());
1294 return *this;
1295}
1296
1297template <class _Tp, class _Alloc>
1298void
1299list<_Tp, _Alloc>::__move_assign(list& __c, false_type)
1300{
1301 if (base::__node_alloc() != __c.__node_alloc())
1302 {
Howard Hinnant99968442011-11-29 18:15:501303 typedef move_iterator<iterator> _Ip;
1304 assign(_Ip(__c.begin()), _Ip(__c.end()));
Howard Hinnantbc8d3f92010-05-11 19:42:161305 }
1306 else
1307 __move_assign(__c, true_type());
1308}
1309
1310template <class _Tp, class _Alloc>
1311void
1312list<_Tp, _Alloc>::__move_assign(list& __c, true_type)
Howard Hinnantc5607272011-06-03 17:30:281313 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value)
Howard Hinnantbc8d3f92010-05-11 19:42:161314{
1315 clear();
1316 base::__move_assign_alloc(__c);
1317 splice(end(), __c);
1318}
1319
Eric Fiselier55ff80e2017-04-16 03:45:351320#endif // _LIBCPP_CXX03_LANG
1321
1322template <class _Tp, class _Alloc>
1323inline
1324list<_Tp, _Alloc>&
1325list<_Tp, _Alloc>::operator=(const list& __c)
1326{
1327 if (this != &__c)
1328 {
1329 base::__copy_assign_alloc(__c);
1330 assign(__c.begin(), __c.end());
1331 }
1332 return *this;
1333}
Howard Hinnantbc8d3f92010-05-11 19:42:161334
1335template <class _Tp, class _Alloc>
1336template <class _InpIter>
1337void
1338list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
1339 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1340{
1341 iterator __i = begin();
1342 iterator __e = end();
1343 for (; __f != __l && __i != __e; ++__f, ++__i)
1344 *__i = *__f;
1345 if (__i == __e)
1346 insert(__e, __f, __l);
1347 else
1348 erase(__i, __e);
Eric Fiselierfb342382016-12-28 06:06:091349#if _LIBCPP_DEBUG_LEVEL >= 2
1350 __get_db()->__invalidate_all(this);
1351#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161352}
1353
1354template <class _Tp, class _Alloc>
1355void
1356list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
1357{
1358 iterator __i = begin();
1359 iterator __e = end();
1360 for (; __n > 0 && __i != __e; --__n, ++__i)
1361 *__i = __x;
1362 if (__i == __e)
1363 insert(__e, __n, __x);
1364 else
1365 erase(__i, __e);
Eric Fiselierfb342382016-12-28 06:06:091366#if _LIBCPP_DEBUG_LEVEL >= 2
1367 __get_db()->__invalidate_all(this);
1368#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161369}
1370
1371template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:551372inline
Howard Hinnantbc8d3f92010-05-11 19:42:161373_Alloc
Howard Hinnantc5607272011-06-03 17:30:281374list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:161375{
1376 return allocator_type(base::__node_alloc());
1377}
1378
1379template <class _Tp, class _Alloc>
1380typename list<_Tp, _Alloc>::iterator
1381list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x)
1382{
Howard Hinnant1c3ec6d2011-09-27 23:55:031383#if _LIBCPP_DEBUG_LEVEL >= 2
1384 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1385 "list::insert(iterator, x) called with an iterator not"
1386 " referring to this list");
1387#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161388 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501389 typedef __allocator_destructor<__node_allocator> _Dp;
1390 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161391 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191392 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591393 __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161394 ++base::__sz();
Howard Hinnant79a35572013-04-05 00:18:491395#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591396 return iterator(__hold.release()->__as_link(), this);
Howard Hinnant79a35572013-04-05 00:18:491397#else
Eric Fiselier5c74b482015-12-30 20:57:591398 return iterator(__hold.release()->__as_link());
Howard Hinnant79a35572013-04-05 00:18:491399#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161400}
1401
1402template <class _Tp, class _Alloc>
1403typename list<_Tp, _Alloc>::iterator
1404list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x)
1405{
Howard Hinnant1c3ec6d2011-09-27 23:55:031406#if _LIBCPP_DEBUG_LEVEL >= 2
1407 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1408 "list::insert(iterator, n, x) called with an iterator not"
1409 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471410 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031411#else
Howard Hinnant29f74322013-06-25 16:08:471412 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031413#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161414 if (__n > 0)
1415 {
1416 size_type __ds = 0;
1417 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501418 typedef __allocator_destructor<__node_allocator> _Dp;
1419 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161420 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191421 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161422 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031423#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591424 __r = iterator(__hold->__as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031425#else
Eric Fiselier5c74b482015-12-30 20:57:591426 __r = iterator(__hold->__as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:031427#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161428 __hold.release();
1429 iterator __e = __r;
1430#ifndef _LIBCPP_NO_EXCEPTIONS
1431 try
1432 {
Howard Hinnant324bb032010-08-22 00:02:431433#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161434 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1435 {
1436 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191437 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591438 __e.__ptr_->__next_ = __hold->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161439 __hold->__prev_ = __e.__ptr_;
1440 __hold.release();
1441 }
1442#ifndef _LIBCPP_NO_EXCEPTIONS
1443 }
1444 catch (...)
1445 {
1446 while (true)
1447 {
Howard Hinnant0949eed2011-06-30 21:18:191448 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591449 __link_pointer __prev = __e.__ptr_->__prev_;
1450 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161451 if (__prev == 0)
1452 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031453#if _LIBCPP_DEBUG_LEVEL >= 2
1454 __e = iterator(__prev, this);
1455#else
Howard Hinnantbc8d3f92010-05-11 19:42:161456 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031457#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161458 }
1459 throw;
1460 }
Howard Hinnant324bb032010-08-22 00:02:431461#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471462 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161463 base::__sz() += __ds;
1464 }
1465 return __r;
1466}
1467
1468template <class _Tp, class _Alloc>
1469template <class _InpIter>
1470typename list<_Tp, _Alloc>::iterator
1471list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l,
1472 typename enable_if<__is_input_iterator<_InpIter>::value>::type*)
1473{
Howard Hinnant1c3ec6d2011-09-27 23:55:031474#if _LIBCPP_DEBUG_LEVEL >= 2
1475 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1476 "list::insert(iterator, range) called with an iterator not"
1477 " referring to this list");
Howard Hinnant29f74322013-06-25 16:08:471478 iterator __r(__p.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031479#else
Howard Hinnant29f74322013-06-25 16:08:471480 iterator __r(__p.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031481#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161482 if (__f != __l)
1483 {
1484 size_type __ds = 0;
1485 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501486 typedef __allocator_destructor<__node_allocator> _Dp;
1487 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161488 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191489 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Howard Hinnantbc8d3f92010-05-11 19:42:161490 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031491#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591492 __r = iterator(__hold.get()->__as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031493#else
Eric Fiselier5c74b482015-12-30 20:57:591494 __r = iterator(__hold.get()->__as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:031495#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161496 __hold.release();
1497 iterator __e = __r;
1498#ifndef _LIBCPP_NO_EXCEPTIONS
1499 try
1500 {
Howard Hinnant324bb032010-08-22 00:02:431501#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier537876b2015-03-19 03:20:021502 for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds)
Howard Hinnantbc8d3f92010-05-11 19:42:161503 {
1504 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191505 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f);
Eric Fiselier5c74b482015-12-30 20:57:591506 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161507 __hold->__prev_ = __e.__ptr_;
1508 __hold.release();
1509 }
1510#ifndef _LIBCPP_NO_EXCEPTIONS
1511 }
1512 catch (...)
1513 {
1514 while (true)
1515 {
Howard Hinnant0949eed2011-06-30 21:18:191516 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591517 __link_pointer __prev = __e.__ptr_->__prev_;
1518 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161519 if (__prev == 0)
1520 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031521#if _LIBCPP_DEBUG_LEVEL >= 2
1522 __e = iterator(__prev, this);
1523#else
Howard Hinnantbc8d3f92010-05-11 19:42:161524 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031525#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161526 }
1527 throw;
1528 }
Howard Hinnant324bb032010-08-22 00:02:431529#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnant29f74322013-06-25 16:08:471530 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161531 base::__sz() += __ds;
1532 }
1533 return __r;
1534}
1535
1536template <class _Tp, class _Alloc>
1537void
1538list<_Tp, _Alloc>::push_front(const value_type& __x)
1539{
1540 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501541 typedef __allocator_destructor<__node_allocator> _Dp;
1542 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191543 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591544 __link_pointer __nl = __hold->__as_link();
1545 __link_nodes_at_front(__nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161546 ++base::__sz();
1547 __hold.release();
1548}
1549
1550template <class _Tp, class _Alloc>
1551void
1552list<_Tp, _Alloc>::push_back(const value_type& __x)
1553{
1554 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501555 typedef __allocator_destructor<__node_allocator> _Dp;
1556 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191557 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591558 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161559 ++base::__sz();
1560 __hold.release();
1561}
1562
Eric Fiselier55ff80e2017-04-16 03:45:351563#ifndef _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161564
1565template <class _Tp, class _Alloc>
1566void
1567list<_Tp, _Alloc>::push_front(value_type&& __x)
1568{
1569 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501570 typedef __allocator_destructor<__node_allocator> _Dp;
1571 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191572 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselier5c74b482015-12-30 20:57:591573 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161574 ++base::__sz();
1575 __hold.release();
1576}
1577
1578template <class _Tp, class _Alloc>
1579void
1580list<_Tp, _Alloc>::push_back(value_type&& __x)
1581{
1582 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501583 typedef __allocator_destructor<__node_allocator> _Dp;
1584 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191585 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselier5c74b482015-12-30 20:57:591586 __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161587 ++base::__sz();
1588 __hold.release();
1589}
1590
Howard Hinnantbc8d3f92010-05-11 19:42:161591template <class _Tp, class _Alloc>
1592template <class... _Args>
Marshall Clow4e42dc92017-01-24 23:09:121593#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:171594typename list<_Tp, _Alloc>::reference
Marshall Clow4e42dc92017-01-24 23:09:121595#else
1596void
1597#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161598list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
1599{
1600 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501601 typedef __allocator_destructor<__node_allocator> _Dp;
1602 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191603 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselier5c74b482015-12-30 20:57:591604 __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
Howard Hinnantbc8d3f92010-05-11 19:42:161605 ++base::__sz();
Marshall Clow4e42dc92017-01-24 23:09:121606#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:171607 return __hold.release()->__value_;
Marshall Clow4e42dc92017-01-24 23:09:121608#else
1609 __hold.release();
1610#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161611}
1612
1613template <class _Tp, class _Alloc>
1614template <class... _Args>
Marshall Clow4e42dc92017-01-24 23:09:121615#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:171616typename list<_Tp, _Alloc>::reference
Marshall Clow4e42dc92017-01-24 23:09:121617#else
1618void
1619#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161620list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
1621{
1622 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501623 typedef __allocator_destructor<__node_allocator> _Dp;
1624 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191625 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselier5c74b482015-12-30 20:57:591626 __link_pointer __nl = __hold->__as_link();
1627 __link_nodes_at_back(__nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161628 ++base::__sz();
Marshall Clow4e42dc92017-01-24 23:09:121629#if _LIBCPP_STD_VER > 14
Eric Fiselier3816ef92016-07-21 03:20:171630 return __hold.release()->__value_;
Marshall Clow4e42dc92017-01-24 23:09:121631#else
1632 __hold.release();
1633#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161634}
1635
1636template <class _Tp, class _Alloc>
1637template <class... _Args>
1638typename list<_Tp, _Alloc>::iterator
1639list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
1640{
Howard Hinnant79a35572013-04-05 00:18:491641#if _LIBCPP_DEBUG_LEVEL >= 2
1642 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1643 "list::emplace(iterator, args...) called with an iterator not"
1644 " referring to this list");
1645#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161646 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501647 typedef __allocator_destructor<__node_allocator> _Dp;
1648 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161649 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191650 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
Eric Fiselier5c74b482015-12-30 20:57:591651 __link_pointer __nl = __hold.get()->__as_link();
1652 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161653 ++base::__sz();
Eric Fiselier5c74b482015-12-30 20:57:591654 __hold.release();
Howard Hinnant1c3ec6d2011-09-27 23:55:031655#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591656 return iterator(__nl, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031657#else
Eric Fiselier5c74b482015-12-30 20:57:591658 return iterator(__nl);
Howard Hinnant1c3ec6d2011-09-27 23:55:031659#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161660}
1661
Howard Hinnantbc8d3f92010-05-11 19:42:161662template <class _Tp, class _Alloc>
1663typename list<_Tp, _Alloc>::iterator
1664list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x)
1665{
Howard Hinnant1c3ec6d2011-09-27 23:55:031666#if _LIBCPP_DEBUG_LEVEL >= 2
1667 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1668 "list::insert(iterator, x) called with an iterator not"
1669 " referring to this list");
1670#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161671 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501672 typedef __allocator_destructor<__node_allocator> _Dp;
1673 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161674 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191675 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x));
Eric Fiselier5c74b482015-12-30 20:57:591676 __link_pointer __nl = __hold->__as_link();
1677 __link_nodes(__p.__ptr_, __nl, __nl);
Howard Hinnantbc8d3f92010-05-11 19:42:161678 ++base::__sz();
Eric Fiselier5c74b482015-12-30 20:57:591679 __hold.release();
Howard Hinnant1c3ec6d2011-09-27 23:55:031680#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591681 return iterator(__nl, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031682#else
Eric Fiselier5c74b482015-12-30 20:57:591683 return iterator(__nl);
Howard Hinnant1c3ec6d2011-09-27 23:55:031684#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161685}
1686
Eric Fiselier55ff80e2017-04-16 03:45:351687#endif // _LIBCPP_CXX03_LANG
Howard Hinnantbc8d3f92010-05-11 19:42:161688
1689template <class _Tp, class _Alloc>
1690void
1691list<_Tp, _Alloc>::pop_front()
1692{
Howard Hinnant1c3ec6d2011-09-27 23:55:031693 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161694 __node_allocator& __na = base::__node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:591695 __link_pointer __n = base::__end_.__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161696 base::__unlink_nodes(__n, __n);
1697 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031698#if _LIBCPP_DEBUG_LEVEL >= 2
1699 __c_node* __c = __get_db()->__find_c_and_lock(this);
1700 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1701 {
1702 --__p;
1703 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471704 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031705 {
1706 (*__p)->__c_ = nullptr;
1707 if (--__c->end_ != __p)
1708 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1709 }
1710 }
1711 __get_db()->unlock();
1712#endif
Eric Fiselier5c74b482015-12-30 20:57:591713 __node_pointer __np = __n->__as_node();
1714 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1715 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161716}
1717
1718template <class _Tp, class _Alloc>
1719void
1720list<_Tp, _Alloc>::pop_back()
1721{
Dmitri Gribenkoc7a39cf2013-06-24 06:15:571722 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list");
Howard Hinnantbc8d3f92010-05-11 19:42:161723 __node_allocator& __na = base::__node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:591724 __link_pointer __n = base::__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161725 base::__unlink_nodes(__n, __n);
1726 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031727#if _LIBCPP_DEBUG_LEVEL >= 2
1728 __c_node* __c = __get_db()->__find_c_and_lock(this);
1729 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1730 {
1731 --__p;
1732 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471733 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031734 {
1735 (*__p)->__c_ = nullptr;
1736 if (--__c->end_ != __p)
1737 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1738 }
1739 }
1740 __get_db()->unlock();
1741#endif
Eric Fiselier5c74b482015-12-30 20:57:591742 __node_pointer __np = __n->__as_node();
1743 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1744 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161745}
1746
1747template <class _Tp, class _Alloc>
1748typename list<_Tp, _Alloc>::iterator
1749list<_Tp, _Alloc>::erase(const_iterator __p)
1750{
Howard Hinnant1c3ec6d2011-09-27 23:55:031751#if _LIBCPP_DEBUG_LEVEL >= 2
1752 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1753 "list::erase(iterator) called with an iterator not"
1754 " referring to this list");
1755#endif
Howard Hinnant79a35572013-04-05 00:18:491756 _LIBCPP_ASSERT(__p != end(),
1757 "list::erase(iterator) called with a non-dereferenceable iterator");
Howard Hinnantbc8d3f92010-05-11 19:42:161758 __node_allocator& __na = base::__node_alloc();
Eric Fiselier5c74b482015-12-30 20:57:591759 __link_pointer __n = __p.__ptr_;
1760 __link_pointer __r = __n->__next_;
Howard Hinnantbc8d3f92010-05-11 19:42:161761 base::__unlink_nodes(__n, __n);
1762 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031763#if _LIBCPP_DEBUG_LEVEL >= 2
1764 __c_node* __c = __get_db()->__find_c_and_lock(this);
Eric Fiselier1e836f02016-10-23 19:26:391765 for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
Howard Hinnant1c3ec6d2011-09-27 23:55:031766 {
Eric Fiselier1e836f02016-10-23 19:26:391767 --__ip;
1768 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471769 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031770 {
Eric Fiselier1e836f02016-10-23 19:26:391771 (*__ip)->__c_ = nullptr;
1772 if (--__c->end_ != __ip)
1773 memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:031774 }
1775 }
1776 __get_db()->unlock();
1777#endif
Eric Fiselier5c74b482015-12-30 20:57:591778 __node_pointer __np = __n->__as_node();
1779 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1780 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnant1c3ec6d2011-09-27 23:55:031781#if _LIBCPP_DEBUG_LEVEL >= 2
1782 return iterator(__r, this);
1783#else
Howard Hinnantbc8d3f92010-05-11 19:42:161784 return iterator(__r);
Howard Hinnant1c3ec6d2011-09-27 23:55:031785#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161786}
1787
1788template <class _Tp, class _Alloc>
1789typename list<_Tp, _Alloc>::iterator
1790list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
1791{
Howard Hinnant1c3ec6d2011-09-27 23:55:031792#if _LIBCPP_DEBUG_LEVEL >= 2
1793 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
1794 "list::erase(iterator, iterator) called with an iterator not"
1795 " referring to this list");
Eric Fiselierfb342382016-12-28 06:06:091796 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
1797 "list::erase(iterator, iterator) called with an iterator not"
1798 " referring to this list");
Howard Hinnant1c3ec6d2011-09-27 23:55:031799#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161800 if (__f != __l)
1801 {
1802 __node_allocator& __na = base::__node_alloc();
Howard Hinnant29f74322013-06-25 16:08:471803 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_);
Howard Hinnantbc8d3f92010-05-11 19:42:161804 while (__f != __l)
1805 {
Eric Fiselier5c74b482015-12-30 20:57:591806 __link_pointer __n = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:161807 ++__f;
1808 --base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:031809#if _LIBCPP_DEBUG_LEVEL >= 2
1810 __c_node* __c = __get_db()->__find_c_and_lock(this);
1811 for (__i_node** __p = __c->end_; __p != __c->beg_; )
1812 {
1813 --__p;
1814 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Howard Hinnant29f74322013-06-25 16:08:471815 if (__i->__ptr_ == __n)
Howard Hinnant1c3ec6d2011-09-27 23:55:031816 {
1817 (*__p)->__c_ = nullptr;
1818 if (--__c->end_ != __p)
1819 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
1820 }
1821 }
1822 __get_db()->unlock();
1823#endif
Eric Fiselier5c74b482015-12-30 20:57:591824 __node_pointer __np = __n->__as_node();
1825 __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
1826 __node_alloc_traits::deallocate(__na, __np, 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161827 }
1828 }
Howard Hinnant1c3ec6d2011-09-27 23:55:031829#if _LIBCPP_DEBUG_LEVEL >= 2
Howard Hinnant29f74322013-06-25 16:08:471830 return iterator(__l.__ptr_, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031831#else
Howard Hinnant29f74322013-06-25 16:08:471832 return iterator(__l.__ptr_);
Howard Hinnant1c3ec6d2011-09-27 23:55:031833#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161834}
1835
1836template <class _Tp, class _Alloc>
1837void
1838list<_Tp, _Alloc>::resize(size_type __n)
1839{
1840 if (__n < base::__sz())
1841 erase(__iterator(__n), end());
1842 else if (__n > base::__sz())
1843 {
1844 __n -= base::__sz();
1845 size_type __ds = 0;
1846 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501847 typedef __allocator_destructor<__node_allocator> _Dp;
1848 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161849 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191850 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Howard Hinnantbc8d3f92010-05-11 19:42:161851 ++__ds;
Howard Hinnant1c3ec6d2011-09-27 23:55:031852#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591853 iterator __r = iterator(__hold.release()->__as_link(), this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031854#else
Eric Fiselier5c74b482015-12-30 20:57:591855 iterator __r = iterator(__hold.release()->__as_link());
Howard Hinnant1c3ec6d2011-09-27 23:55:031856#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161857 iterator __e = __r;
1858#ifndef _LIBCPP_NO_EXCEPTIONS
1859 try
1860 {
Howard Hinnant324bb032010-08-22 00:02:431861#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161862 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1863 {
1864 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191865 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_));
Eric Fiselier5c74b482015-12-30 20:57:591866 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161867 __hold->__prev_ = __e.__ptr_;
1868 __hold.release();
1869 }
1870#ifndef _LIBCPP_NO_EXCEPTIONS
1871 }
1872 catch (...)
1873 {
1874 while (true)
1875 {
Howard Hinnant0949eed2011-06-30 21:18:191876 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591877 __link_pointer __prev = __e.__ptr_->__prev_;
1878 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161879 if (__prev == 0)
1880 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031881#if _LIBCPP_DEBUG_LEVEL >= 2
1882 __e = iterator(__prev, this);
1883#else
Howard Hinnantbc8d3f92010-05-11 19:42:161884 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031885#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161886 }
1887 throw;
1888 }
Howard Hinnant324bb032010-08-22 00:02:431889#endif // _LIBCPP_NO_EXCEPTIONS
Marshall Clowea8ed832014-08-05 01:34:121890 __link_nodes_at_back(__r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161891 base::__sz() += __ds;
1892 }
1893}
1894
1895template <class _Tp, class _Alloc>
1896void
1897list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x)
1898{
1899 if (__n < base::__sz())
1900 erase(__iterator(__n), end());
1901 else if (__n > base::__sz())
1902 {
1903 __n -= base::__sz();
1904 size_type __ds = 0;
1905 __node_allocator& __na = base::__node_alloc();
Howard Hinnant99968442011-11-29 18:15:501906 typedef __allocator_destructor<__node_allocator> _Dp;
1907 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1));
Howard Hinnantbc8d3f92010-05-11 19:42:161908 __hold->__prev_ = 0;
Howard Hinnant0949eed2011-06-30 21:18:191909 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Howard Hinnantbc8d3f92010-05-11 19:42:161910 ++__ds;
Eric Fiselier5c74b482015-12-30 20:57:591911 __link_pointer __nl = __hold.release()->__as_link();
Howard Hinnant1c3ec6d2011-09-27 23:55:031912#if _LIBCPP_DEBUG_LEVEL >= 2
Eric Fiselier5c74b482015-12-30 20:57:591913 iterator __r = iterator(__nl, this);
Howard Hinnant1c3ec6d2011-09-27 23:55:031914#else
Eric Fiselier5c74b482015-12-30 20:57:591915 iterator __r = iterator(__nl);
Howard Hinnant1c3ec6d2011-09-27 23:55:031916#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161917 iterator __e = __r;
1918#ifndef _LIBCPP_NO_EXCEPTIONS
1919 try
1920 {
Howard Hinnant324bb032010-08-22 00:02:431921#endif // _LIBCPP_NO_EXCEPTIONS
Howard Hinnantbc8d3f92010-05-11 19:42:161922 for (--__n; __n != 0; --__n, ++__e, ++__ds)
1923 {
1924 __hold.reset(__node_alloc_traits::allocate(__na, 1));
Howard Hinnant0949eed2011-06-30 21:18:191925 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x);
Eric Fiselier5c74b482015-12-30 20:57:591926 __e.__ptr_->__next_ = __hold.get()->__as_link();
Howard Hinnantbc8d3f92010-05-11 19:42:161927 __hold->__prev_ = __e.__ptr_;
1928 __hold.release();
1929 }
1930#ifndef _LIBCPP_NO_EXCEPTIONS
1931 }
1932 catch (...)
1933 {
1934 while (true)
1935 {
Howard Hinnant0949eed2011-06-30 21:18:191936 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e));
Eric Fiselier5c74b482015-12-30 20:57:591937 __link_pointer __prev = __e.__ptr_->__prev_;
1938 __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1);
Howard Hinnantbc8d3f92010-05-11 19:42:161939 if (__prev == 0)
1940 break;
Howard Hinnant1c3ec6d2011-09-27 23:55:031941#if _LIBCPP_DEBUG_LEVEL >= 2
1942 __e = iterator(__prev, this);
1943#else
Howard Hinnantbc8d3f92010-05-11 19:42:161944 __e = iterator(__prev);
Howard Hinnant1c3ec6d2011-09-27 23:55:031945#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161946 }
1947 throw;
1948 }
Howard Hinnant324bb032010-08-22 00:02:431949#endif // _LIBCPP_NO_EXCEPTIONS
Eric Fiselier8e7bd4f2016-01-04 03:27:521950 __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_);
Howard Hinnantbc8d3f92010-05-11 19:42:161951 base::__sz() += __ds;
Howard Hinnant324bb032010-08-22 00:02:431952 }
Howard Hinnantbc8d3f92010-05-11 19:42:161953}
1954
1955template <class _Tp, class _Alloc>
1956void
1957list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
1958{
Howard Hinnant1c3ec6d2011-09-27 23:55:031959 _LIBCPP_ASSERT(this != &__c,
1960 "list::splice(iterator, list) called with this == &list");
1961#if _LIBCPP_DEBUG_LEVEL >= 2
1962 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
1963 "list::splice(iterator, list) called with an iterator not"
1964 " referring to this list");
1965#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161966 if (!__c.empty())
1967 {
Eric Fiselier5c74b482015-12-30 20:57:591968 __link_pointer __f = __c.__end_.__next_;
1969 __link_pointer __l = __c.__end_.__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:161970 base::__unlink_nodes(__f, __l);
Howard Hinnant29f74322013-06-25 16:08:471971 __link_nodes(__p.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:161972 base::__sz() += __c.__sz();
1973 __c.__sz() = 0;
Howard Hinnant1c3ec6d2011-09-27 23:55:031974#if _LIBCPP_DEBUG_LEVEL >= 2
1975 __libcpp_db* __db = __get_db();
1976 __c_node* __cn1 = __db->__find_c_and_lock(this);
1977 __c_node* __cn2 = __db->__find_c(&__c);
Eric Fiselier1e836f02016-10-23 19:26:391978 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
Howard Hinnant1c3ec6d2011-09-27 23:55:031979 {
Eric Fiselier1e836f02016-10-23 19:26:391980 --__ip;
1981 iterator* __i = static_cast<iterator*>((*__ip)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:521982 if (__i->__ptr_ != __c.__end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:031983 {
Eric Fiselier1e836f02016-10-23 19:26:391984 __cn1->__add(*__ip);
1985 (*__ip)->__c_ = __cn1;
1986 if (--__cn2->end_ != __ip)
1987 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:031988 }
1989 }
1990 __db->unlock();
1991#endif
Howard Hinnantbc8d3f92010-05-11 19:42:161992 }
1993}
1994
1995template <class _Tp, class _Alloc>
1996void
1997list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
1998{
Howard Hinnant1c3ec6d2011-09-27 23:55:031999#if _LIBCPP_DEBUG_LEVEL >= 2
2000 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2001 "list::splice(iterator, list, iterator) called with first iterator not"
2002 " referring to this list");
2003 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c,
2004 "list::splice(iterator, list, iterator) called with second iterator not"
2005 " referring to list argument");
2006 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i),
2007 "list::splice(iterator, list, iterator) called with second iterator not"
2008 " derefereceable");
2009#endif
2010 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_)
Howard Hinnantbc8d3f92010-05-11 19:42:162011 {
Eric Fiselier5c74b482015-12-30 20:57:592012 __link_pointer __f = __i.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162013 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:472014 __link_nodes(__p.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:162015 --__c.__sz();
2016 ++base::__sz();
Howard Hinnant1c3ec6d2011-09-27 23:55:032017#if _LIBCPP_DEBUG_LEVEL >= 2
2018 __libcpp_db* __db = __get_db();
2019 __c_node* __cn1 = __db->__find_c_and_lock(this);
2020 __c_node* __cn2 = __db->__find_c(&__c);
Eric Fiselier1e836f02016-10-23 19:26:392021 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
Howard Hinnant1c3ec6d2011-09-27 23:55:032022 {
Eric Fiselier1e836f02016-10-23 19:26:392023 --__ip;
2024 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
Howard Hinnant29f74322013-06-25 16:08:472025 if (__j->__ptr_ == __f)
Howard Hinnant1c3ec6d2011-09-27 23:55:032026 {
Eric Fiselier1e836f02016-10-23 19:26:392027 __cn1->__add(*__ip);
2028 (*__ip)->__c_ = __cn1;
2029 if (--__cn2->end_ != __ip)
2030 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:032031 }
2032 }
2033 __db->unlock();
2034#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162035 }
2036}
2037
2038template <class _Tp, class _Alloc>
2039void
2040list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l)
2041{
Howard Hinnant1c3ec6d2011-09-27 23:55:032042#if _LIBCPP_DEBUG_LEVEL >= 2
2043 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this,
2044 "list::splice(iterator, list, iterator, iterator) called with first iterator not"
2045 " referring to this list");
2046 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c,
2047 "list::splice(iterator, list, iterator, iterator) called with second iterator not"
2048 " referring to list argument");
2049 if (this == &__c)
2050 {
2051 for (const_iterator __i = __f; __i != __l; ++__i)
2052 _LIBCPP_ASSERT(__i != __p,
2053 "list::splice(iterator, list, iterator, iterator)"
2054 " called with the first iterator within the range"
2055 " of the second and third iterators");
2056 }
2057#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162058 if (__f != __l)
2059 {
2060 if (this != &__c)
2061 {
Howard Hinnant0949eed2011-06-30 21:18:192062 size_type __s = _VSTD::distance(__f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162063 __c.__sz() -= __s;
2064 base::__sz() += __s;
2065 }
Eric Fiselier5c74b482015-12-30 20:57:592066 __link_pointer __first = __f.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162067 --__l;
Eric Fiselier5c74b482015-12-30 20:57:592068 __link_pointer __last = __l.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162069 base::__unlink_nodes(__first, __last);
Howard Hinnant29f74322013-06-25 16:08:472070 __link_nodes(__p.__ptr_, __first, __last);
Howard Hinnant1c3ec6d2011-09-27 23:55:032071#if _LIBCPP_DEBUG_LEVEL >= 2
2072 __libcpp_db* __db = __get_db();
2073 __c_node* __cn1 = __db->__find_c_and_lock(this);
2074 __c_node* __cn2 = __db->__find_c(&__c);
Eric Fiselier1e836f02016-10-23 19:26:392075 for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
Howard Hinnant1c3ec6d2011-09-27 23:55:032076 {
Eric Fiselier1e836f02016-10-23 19:26:392077 --__ip;
2078 iterator* __j = static_cast<iterator*>((*__ip)->__i_);
Eric Fiselier5c74b482015-12-30 20:57:592079 for (__link_pointer __k = __f.__ptr_;
Howard Hinnant1c3ec6d2011-09-27 23:55:032080 __k != __l.__ptr_; __k = __k->__next_)
2081 {
2082 if (__j->__ptr_ == __k)
2083 {
Eric Fiselier1e836f02016-10-23 19:26:392084 __cn1->__add(*__ip);
2085 (*__ip)->__c_ = __cn1;
2086 if (--__cn2->end_ != __ip)
2087 memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
Howard Hinnant1c3ec6d2011-09-27 23:55:032088 }
2089 }
2090 }
2091 __db->unlock();
2092#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162093 }
2094}
2095
2096template <class _Tp, class _Alloc>
2097void
2098list<_Tp, _Alloc>::remove(const value_type& __x)
2099{
Eric Fiselierbad1d6c2016-12-14 22:48:382100 list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
Marshall Clowfca038e2014-08-08 15:35:522101 for (const_iterator __i = begin(), __e = end(); __i != __e;)
Howard Hinnantbc8d3f92010-05-11 19:42:162102 {
2103 if (*__i == __x)
2104 {
Marshall Clowfca038e2014-08-08 15:35:522105 const_iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162106 for (; __j != __e && *__j == __x; ++__j)
2107 ;
Marshall Clowfca038e2014-08-08 15:35:522108 __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j);
2109 __i = __j;
Marshall Clowf0f1bca2014-08-04 17:32:252110 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122111 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162112 }
2113 else
2114 ++__i;
2115 }
2116}
2117
2118template <class _Tp, class _Alloc>
2119template <class _Pred>
2120void
2121list<_Tp, _Alloc>::remove_if(_Pred __pred)
2122{
2123 for (iterator __i = begin(), __e = end(); __i != __e;)
2124 {
2125 if (__pred(*__i))
2126 {
Howard Hinnant0949eed2011-06-30 21:18:192127 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162128 for (; __j != __e && __pred(*__j); ++__j)
2129 ;
2130 __i = erase(__i, __j);
Marshall Clowf0f1bca2014-08-04 17:32:252131 if (__i != __e)
Marshall Clowea8ed832014-08-05 01:34:122132 ++__i;
Howard Hinnantbc8d3f92010-05-11 19:42:162133 }
2134 else
2135 ++__i;
2136 }
2137}
2138
2139template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552140inline
Howard Hinnantbc8d3f92010-05-11 19:42:162141void
2142list<_Tp, _Alloc>::unique()
2143{
2144 unique(__equal_to<value_type>());
2145}
2146
2147template <class _Tp, class _Alloc>
2148template <class _BinaryPred>
2149void
2150list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred)
2151{
2152 for (iterator __i = begin(), __e = end(); __i != __e;)
2153 {
Howard Hinnant0949eed2011-06-30 21:18:192154 iterator __j = _VSTD::next(__i);
Howard Hinnantbc8d3f92010-05-11 19:42:162155 for (; __j != __e && __binary_pred(*__i, *__j); ++__j)
2156 ;
2157 if (++__i != __j)
2158 __i = erase(__i, __j);
2159 }
2160}
2161
2162template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552163inline
Howard Hinnantbc8d3f92010-05-11 19:42:162164void
2165list<_Tp, _Alloc>::merge(list& __c)
2166{
2167 merge(__c, __less<value_type>());
2168}
2169
2170template <class _Tp, class _Alloc>
2171template <class _Comp>
2172void
2173list<_Tp, _Alloc>::merge(list& __c, _Comp __comp)
2174{
2175 if (this != &__c)
2176 {
2177 iterator __f1 = begin();
2178 iterator __e1 = end();
2179 iterator __f2 = __c.begin();
2180 iterator __e2 = __c.end();
2181 while (__f1 != __e1 && __f2 != __e2)
2182 {
2183 if (__comp(*__f2, *__f1))
2184 {
2185 size_type __ds = 1;
Howard Hinnant0949eed2011-06-30 21:18:192186 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162187 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds)
2188 ;
2189 base::__sz() += __ds;
2190 __c.__sz() -= __ds;
Eric Fiselier5c74b482015-12-30 20:57:592191 __link_pointer __f = __f2.__ptr_;
2192 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162193 __f2 = __m2;
2194 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192195 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472196 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162197 __f1 = __m2;
2198 }
2199 else
2200 ++__f1;
2201 }
2202 splice(__e1, __c);
Howard Hinnant1c3ec6d2011-09-27 23:55:032203#if _LIBCPP_DEBUG_LEVEL >= 2
2204 __libcpp_db* __db = __get_db();
2205 __c_node* __cn1 = __db->__find_c_and_lock(this);
2206 __c_node* __cn2 = __db->__find_c(&__c);
2207 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
2208 {
2209 --__p;
2210 iterator* __i = static_cast<iterator*>((*__p)->__i_);
Eric Fiselier8e7bd4f2016-01-04 03:27:522211 if (__i->__ptr_ != __c.__end_as_link())
Howard Hinnant1c3ec6d2011-09-27 23:55:032212 {
2213 __cn1->__add(*__p);
2214 (*__p)->__c_ = __cn1;
2215 if (--__cn2->end_ != __p)
2216 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
2217 }
2218 }
2219 __db->unlock();
2220#endif
Howard Hinnantbc8d3f92010-05-11 19:42:162221 }
2222}
2223
2224template <class _Tp, class _Alloc>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552225inline
Howard Hinnantbc8d3f92010-05-11 19:42:162226void
2227list<_Tp, _Alloc>::sort()
2228{
2229 sort(__less<value_type>());
2230}
2231
2232template <class _Tp, class _Alloc>
2233template <class _Comp>
Evgeniy Stepanov9341a8a2016-04-22 01:04:552234inline
Howard Hinnantbc8d3f92010-05-11 19:42:162235void
2236list<_Tp, _Alloc>::sort(_Comp __comp)
2237{
2238 __sort(begin(), end(), base::__sz(), __comp);
2239}
2240
2241template <class _Tp, class _Alloc>
2242template <class _Comp>
Howard Hinnantbc8d3f92010-05-11 19:42:162243typename list<_Tp, _Alloc>::iterator
2244list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp)
2245{
2246 switch (__n)
2247 {
2248 case 0:
2249 case 1:
2250 return __f1;
2251 case 2:
2252 if (__comp(*--__e2, *__f1))
2253 {
Eric Fiselier5c74b482015-12-30 20:57:592254 __link_pointer __f = __e2.__ptr_;
Howard Hinnantbc8d3f92010-05-11 19:42:162255 base::__unlink_nodes(__f, __f);
Howard Hinnant29f74322013-06-25 16:08:472256 __link_nodes(__f1.__ptr_, __f, __f);
Howard Hinnantbc8d3f92010-05-11 19:42:162257 return __e2;
2258 }
2259 return __f1;
2260 }
2261 size_type __n2 = __n / 2;
Howard Hinnant0949eed2011-06-30 21:18:192262 iterator __e1 = _VSTD::next(__f1, __n2);
Howard Hinnantbc8d3f92010-05-11 19:42:162263 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp);
2264 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp);
2265 if (__comp(*__f2, *__f1))
2266 {
Howard Hinnant0949eed2011-06-30 21:18:192267 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162268 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2269 ;
Eric Fiselier5c74b482015-12-30 20:57:592270 __link_pointer __f = __f2.__ptr_;
2271 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162272 __r = __f2;
2273 __e1 = __f2 = __m2;
2274 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192275 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472276 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162277 __f1 = __m2;
2278 }
2279 else
2280 ++__f1;
2281 while (__f1 != __e1 && __f2 != __e2)
2282 {
2283 if (__comp(*__f2, *__f1))
2284 {
Howard Hinnant0949eed2011-06-30 21:18:192285 iterator __m2 = _VSTD::next(__f2);
Howard Hinnantbc8d3f92010-05-11 19:42:162286 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2)
2287 ;
Eric Fiselier5c74b482015-12-30 20:57:592288 __link_pointer __f = __f2.__ptr_;
2289 __link_pointer __l = __m2.__ptr_->__prev_;
Howard Hinnantbc8d3f92010-05-11 19:42:162290 if (__e1 == __f2)
2291 __e1 = __m2;
2292 __f2 = __m2;
2293 base::__unlink_nodes(__f, __l);
Howard Hinnant0949eed2011-06-30 21:18:192294 __m2 = _VSTD::next(__f1);
Howard Hinnant29f74322013-06-25 16:08:472295 __link_nodes(__f1.__ptr_, __f, __l);
Howard Hinnantbc8d3f92010-05-11 19:42:162296 __f1 = __m2;
2297 }
2298 else
2299 ++__f1;
2300 }
2301 return __r;
2302}
2303
2304template <class _Tp, class _Alloc>
2305void
Howard Hinnantc5607272011-06-03 17:30:282306list<_Tp, _Alloc>::reverse() _NOEXCEPT
Howard Hinnantbc8d3f92010-05-11 19:42:162307{
2308 if (base::__sz() > 1)
2309 {
2310 iterator __e = end();
Howard Hinnant1c3ec6d2011-09-27 23:55:032311 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;)
2312 {
Howard Hinnant0949eed2011-06-30 21:18:192313 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_);
Howard Hinnant1c3ec6d2011-09-27 23:55:032314 __i.__ptr_ = __i.__ptr_->__prev_;
2315 }
Howard Hinnant0949eed2011-06-30 21:18:192316 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_);
Howard Hinnantbc8d3f92010-05-11 19:42:162317 }
2318}
2319
2320template <class _Tp, class _Alloc>
Howard Hinnant1c3ec6d2011-09-27 23:55:032321bool
2322list<_Tp, _Alloc>::__invariants() const
2323{
2324 return size() == _VSTD::distance(begin(), end());
2325}
2326
2327#if _LIBCPP_DEBUG_LEVEL >= 2
2328
2329template <class _Tp, class _Alloc>
2330bool
2331list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const
2332{
Eric Fiselier8e7bd4f2016-01-04 03:27:522333 return __i->__ptr_ != this->__end_as_link();
Howard Hinnant1c3ec6d2011-09-27 23:55:032334}
2335
2336template <class _Tp, class _Alloc>
2337bool
2338list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
2339{
2340 return !empty() && __i->__ptr_ != base::__end_.__next_;
2341}
2342
2343template <class _Tp, class _Alloc>
2344bool
Eric Fiselier0e5ebbc2016-12-23 23:37:522345list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
Howard Hinnant1c3ec6d2011-09-27 23:55:032346{
2347 return false;
2348}
2349
2350template <class _Tp, class _Alloc>
2351bool
Eric Fiselier0e5ebbc2016-12-23 23:37:522352list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
Howard Hinnant1c3ec6d2011-09-27 23:55:032353{
2354 return false;
2355}
2356
2357#endif // _LIBCPP_DEBUG_LEVEL >= 2
2358
2359template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342360inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162361bool
2362operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2363{
Howard Hinnant0949eed2011-06-30 21:18:192364 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin());
Howard Hinnantbc8d3f92010-05-11 19:42:162365}
2366
2367template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342368inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162369bool
2370operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2371{
Howard Hinnant0949eed2011-06-30 21:18:192372 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end());
Howard Hinnantbc8d3f92010-05-11 19:42:162373}
2374
2375template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342376inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162377bool
2378operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2379{
2380 return !(__x == __y);
2381}
2382
2383template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342384inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162385bool
2386operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2387{
2388 return __y < __x;
2389}
2390
2391template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342392inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162393bool
2394operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2395{
2396 return !(__x < __y);
2397}
2398
2399template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342400inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162401bool
2402operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y)
2403{
2404 return !(__y < __x);
2405}
2406
2407template <class _Tp, class _Alloc>
Howard Hinnant82894812010-09-22 16:48:342408inline _LIBCPP_INLINE_VISIBILITY
Howard Hinnantbc8d3f92010-05-11 19:42:162409void
2410swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y)
Howard Hinnantc5607272011-06-03 17:30:282411 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y)))
Howard Hinnantbc8d3f92010-05-11 19:42:162412{
2413 __x.swap(__y);
2414}
2415
2416_LIBCPP_END_NAMESPACE_STD
2417
2418#endif // _LIBCPP_LIST