Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | // -*- C++ -*- |
| 2 | //===---------------------------- list ------------------------------------===// |
| 3 | // |
Howard Hinnant | 5b08a8a | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 4 | // The LLVM Compiler Infrastructure |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 5 | // |
Howard Hinnant | 412dbeb | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 6 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 7 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 8 | // |
| 9 | //===----------------------------------------------------------------------===// |
| 10 | |
| 11 | #ifndef _LIBCPP_LIST |
| 12 | #define _LIBCPP_LIST |
| 13 | |
| 14 | /* |
| 15 | list synopsis |
| 16 | |
| 17 | namespace std |
| 18 | { |
| 19 | |
| 20 | template <class T, class Alloc = allocator<T> > |
| 21 | class list |
| 22 | { |
| 23 | public: |
| 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 Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 39 | list() |
| 40 | noexcept(is_nothrow_default_constructible<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 41 | explicit list(const allocator_type& a); |
| 42 | explicit list(size_type n); |
Marshall Clow | f1b6d1b | 2013-09-09 18:19:45 +0000 | [diff] [blame] | 43 | explicit list(size_type n, const allocator_type& a); // C++14 |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 44 | 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 Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 52 | list(list&& x) |
| 53 | noexcept(is_nothrow_move_constructible<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 54 | 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 Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 61 | list& operator=(list&& x) |
| 62 | noexcept( |
| 63 | allocator_type::propagate_on_container_move_assignment::value && |
| 64 | is_nothrow_move_assignable<allocator_type>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 65 | 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 Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 71 | allocator_type get_allocator() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 72 | |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 73 | 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 Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 85 | |
| 86 | reference front(); |
| 87 | const_reference front() const; |
| 88 | reference back(); |
| 89 | const_reference back() const; |
| 90 | |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 91 | bool empty() const noexcept; |
| 92 | size_type size() const noexcept; |
| 93 | size_type max_size() const noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 94 | |
| 95 | template <class... Args> |
| 96 | void emplace_front(Args&&... args); |
| 97 | void pop_front(); |
| 98 | template <class... Args> |
| 99 | void emplace_back(Args&&... args); |
| 100 | void pop_back(); |
| 101 | void push_front(const value_type& x); |
| 102 | void push_front(value_type&& x); |
| 103 | void push_back(const value_type& x); |
| 104 | void push_back(value_type&& x); |
| 105 | template <class... Args> |
| 106 | iterator emplace(const_iterator position, Args&&... args); |
| 107 | iterator insert(const_iterator position, const value_type& x); |
| 108 | iterator insert(const_iterator position, value_type&& x); |
| 109 | iterator insert(const_iterator position, size_type n, const value_type& x); |
| 110 | template <class Iter> |
| 111 | iterator insert(const_iterator position, Iter first, Iter last); |
| 112 | iterator insert(const_iterator position, initializer_list<value_type> il); |
| 113 | |
| 114 | iterator erase(const_iterator position); |
| 115 | iterator erase(const_iterator position, const_iterator last); |
| 116 | |
| 117 | void resize(size_type sz); |
| 118 | void resize(size_type sz, const value_type& c); |
| 119 | |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 120 | void swap(list&) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 121 | noexcept(allocator_traits<allocator_type>::is_always_equal::value); // C++17 |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 122 | void clear() noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 123 | |
| 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 Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 147 | void reverse() noexcept; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | template <class T, class Alloc> |
| 151 | bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 152 | template <class T, class Alloc> |
| 153 | bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 154 | template <class T, class Alloc> |
| 155 | bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 156 | template <class T, class Alloc> |
| 157 | bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 158 | template <class T, class Alloc> |
| 159 | bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 160 | template <class T, class Alloc> |
| 161 | bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); |
| 162 | |
| 163 | template <class T, class Alloc> |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 164 | void swap(list<T,Alloc>& x, list<T,Alloc>& y) |
| 165 | noexcept(noexcept(x.swap(y))); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 166 | |
| 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 Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 178 | #include <type_traits> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 179 | |
Howard Hinnant | ab4f438 | 2011-11-29 16:45:27 +0000 | [diff] [blame] | 180 | #include <__undef_min_max> |
| 181 | |
Eric Fiselier | c1bd919 | 2014-08-10 23:53:08 +0000 | [diff] [blame] | 182 | #include <__debug> |
Howard Hinnant | 42a3046 | 2013-08-02 00:26:35 +0000 | [diff] [blame] | 183 | |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 184 | #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 185 | #pragma GCC system_header |
Howard Hinnant | 073458b | 2011-10-17 20:05:10 +0000 | [diff] [blame] | 186 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 187 | |
| 188 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 189 | |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 190 | template <class _Tp, class _VoidPtr> struct __list_node; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 191 | template <class _Tp, class _VoidPtr> struct __list_node_base; |
| 192 | |
| 193 | template <class _Tp, class _VoidPtr> |
| 194 | struct __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 Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 210 | 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 Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 226 | }; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 227 | |
| 228 | template <class _Tp, class _VoidPtr> |
| 229 | struct __list_node_base |
| 230 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 231 | 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 Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 235 | |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 236 | __link_pointer __prev_; |
| 237 | __link_pointer __next_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 238 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 239 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 240 | __list_node_base() : __prev_(_NodeTraits::__unsafe_link_pointer_cast(__self())), |
| 241 | __next_(_NodeTraits::__unsafe_link_pointer_cast(__self())) {} |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 242 | |
| 243 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 244 | __base_pointer __self() { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 245 | return pointer_traits<__base_pointer>::pointer_to(*this); |
| 246 | } |
| 247 | |
| 248 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 249 | __node_pointer __as_node() { |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 250 | return static_cast<__node_pointer>(__self()); |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 251 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 252 | }; |
| 253 | |
| 254 | template <class _Tp, class _VoidPtr> |
| 255 | struct __list_node |
| 256 | : public __list_node_base<_Tp, _VoidPtr> |
| 257 | { |
| 258 | _Tp __value_; |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 259 | |
| 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 Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 267 | }; |
| 268 | |
Marshall Clow | b5d34aa | 2015-02-18 17:24:08 +0000 | [diff] [blame] | 269 | template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list; |
Howard Hinnant | ce53420 | 2011-06-14 19:58:17 +0000 | [diff] [blame] | 270 | template <class _Tp, class _Alloc> class __list_imp; |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 271 | template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 272 | |
| 273 | template <class _Tp, class _VoidPtr> |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 274 | class _LIBCPP_TYPE_VIS_ONLY __list_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 275 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 276 | typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; |
| 277 | typedef typename _NodeTraits::__link_pointer __link_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 278 | |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 279 | __link_pointer __ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 280 | |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 281 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 282 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 283 | explicit __list_iterator(__link_pointer __p, const void* __c) _NOEXCEPT |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 284 | : __ptr_(__p) |
| 285 | { |
| 286 | __get_db()->__insert_ic(this, __c); |
| 287 | } |
| 288 | #else |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 289 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 290 | explicit __list_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 291 | #endif |
| 292 | |
| 293 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 294 | |
| 295 | template<class, class> friend class list; |
| 296 | template<class, class> friend class __list_imp; |
| 297 | template<class, class> friend class __list_const_iterator; |
| 298 | public: |
| 299 | typedef bidirectional_iterator_tag iterator_category; |
| 300 | typedef _Tp value_type; |
| 301 | typedef value_type& reference; |
Eric Fiselier | 1c81340 | 2015-08-23 02:56:05 +0000 | [diff] [blame] | 302 | typedef typename __rebind_pointer<_VoidPtr, value_type>::type pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 303 | typedef typename pointer_traits<pointer>::difference_type difference_type; |
| 304 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 305 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 0c37cfd | 2013-08-05 21:23:28 +0000 | [diff] [blame] | 306 | __list_iterator() _NOEXCEPT : __ptr_(nullptr) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 307 | { |
| 308 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 309 | __get_db()->__insert_i(this); |
| 310 | #endif |
| 311 | } |
| 312 | |
| 313 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 314 | |
Howard Hinnant | 2774545 | 2011-01-28 23:46:28 +0000 | [diff] [blame] | 315 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 316 | __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 Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 348 | return __ptr_->__as_node()->__value_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 349 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 350 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 351 | 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 Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 357 | return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 358 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 359 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 360 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 361 | __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 Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 370 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 371 | __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} |
| 372 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 373 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 374 | __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 Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 383 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 384 | __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} |
| 385 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 386 | friend _LIBCPP_INLINE_VISIBILITY |
| 387 | bool operator==(const __list_iterator& __x, const __list_iterator& __y) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 388 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 389 | return __x.__ptr_ == __y.__ptr_; |
| 390 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 391 | friend _LIBCPP_INLINE_VISIBILITY |
| 392 | bool operator!=(const __list_iterator& __x, const __list_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 393 | {return !(__x == __y);} |
| 394 | }; |
| 395 | |
| 396 | template <class _Tp, class _VoidPtr> |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 397 | class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 398 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 399 | typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits; |
| 400 | typedef typename _NodeTraits::__link_pointer __link_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 401 | |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 402 | __link_pointer __ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 403 | |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 404 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 405 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 406 | explicit __list_const_iterator(__link_pointer __p, const void* __c) _NOEXCEPT |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 407 | : __ptr_(__p) |
| 408 | { |
| 409 | __get_db()->__insert_ic(this, __c); |
| 410 | } |
| 411 | #else |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 412 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 413 | explicit __list_const_iterator(__link_pointer __p) _NOEXCEPT : __ptr_(__p) {} |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 414 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 415 | |
| 416 | template<class, class> friend class list; |
| 417 | template<class, class> friend class __list_imp; |
| 418 | public: |
| 419 | typedef bidirectional_iterator_tag iterator_category; |
| 420 | typedef _Tp value_type; |
| 421 | typedef const value_type& reference; |
Eric Fiselier | 1c81340 | 2015-08-23 02:56:05 +0000 | [diff] [blame] | 422 | typedef typename __rebind_pointer<_VoidPtr, const value_type>::type pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 423 | typedef typename pointer_traits<pointer>::difference_type difference_type; |
| 424 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 425 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | 0c37cfd | 2013-08-05 21:23:28 +0000 | [diff] [blame] | 426 | __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 427 | { |
| 428 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 429 | __get_db()->__insert_i(this); |
| 430 | #endif |
| 431 | } |
Howard Hinnant | 2774545 | 2011-01-28 23:46:28 +0000 | [diff] [blame] | 432 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | f750923 | 2013-04-05 17:58:52 +0000 | [diff] [blame] | 433 | __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 434 | : __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 Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 442 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 443 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 444 | __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 Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 475 | return __ptr_->__as_node()->__value_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 476 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 477 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 478 | 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 Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 484 | return pointer_traits<pointer>::pointer_to(__ptr_->__as_node()->__value_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 485 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 486 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 487 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 488 | __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 Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 497 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 498 | __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} |
| 499 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 500 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 501 | __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 Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 510 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 511 | __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} |
| 512 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 513 | friend _LIBCPP_INLINE_VISIBILITY |
| 514 | bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 515 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 516 | return __x.__ptr_ == __y.__ptr_; |
| 517 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 518 | friend _LIBCPP_INLINE_VISIBILITY |
| 519 | bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 520 | {return !(__x == __y);} |
| 521 | }; |
| 522 | |
| 523 | template <class _Tp, class _Alloc> |
| 524 | class __list_imp |
| 525 | { |
| 526 | __list_imp(const __list_imp&); |
| 527 | __list_imp& operator=(const __list_imp&); |
| 528 | protected: |
| 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 Clow | 1f50801 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 538 | typedef typename __rebind_alloc_helper<__alloc_traits, __node>::type __node_allocator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 539 | typedef allocator_traits<__node_allocator> __node_alloc_traits; |
| 540 | typedef typename __node_alloc_traits::pointer __node_pointer; |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 541 | typedef typename __node_alloc_traits::pointer __node_const_pointer; |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 542 | typedef __list_node_pointer_traits<value_type, __void_pointer> __node_pointer_traits; |
| 543 | typedef typename __node_pointer_traits::__link_pointer __link_pointer; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 544 | typedef __link_pointer __link_const_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 545 | 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 Clow | 1f50801 | 2015-04-07 05:21:38 +0000 | [diff] [blame] | 549 | typedef typename __rebind_alloc_helper<__alloc_traits, __node_base>::type __node_base_allocator; |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 550 | typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; |
| 551 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 552 | __node_base __end_; |
| 553 | __compressed_pair<size_type, __node_allocator> __size_alloc_; |
| 554 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 555 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 556 | __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 Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 562 | size_type& __sz() _NOEXCEPT {return __size_alloc_.first();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 563 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 564 | const size_type& __sz() const _NOEXCEPT |
| 565 | {return __size_alloc_.first();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 566 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 567 | __node_allocator& __node_alloc() _NOEXCEPT |
| 568 | {return __size_alloc_.second();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 569 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 570 | const __node_allocator& __node_alloc() const _NOEXCEPT |
| 571 | {return __size_alloc_.second();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 572 | |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 573 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 574 | static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 575 | |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 576 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 577 | __list_imp() |
| 578 | _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 579 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 580 | __list_imp(const allocator_type& __a); |
| 581 | ~__list_imp(); |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 582 | void clear() _NOEXCEPT; |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 583 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 584 | bool empty() const _NOEXCEPT {return __sz() == 0;} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 585 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 586 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 587 | iterator begin() _NOEXCEPT |
| 588 | { |
| 589 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 590 | return iterator(__end_.__next_, this); |
| 591 | #else |
| 592 | return iterator(__end_.__next_); |
| 593 | #endif |
| 594 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 595 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 596 | const_iterator begin() const _NOEXCEPT |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 597 | { |
| 598 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 599 | return const_iterator(__end_.__next_, this); |
| 600 | #else |
| 601 | return const_iterator(__end_.__next_); |
| 602 | #endif |
| 603 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 604 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 605 | iterator end() _NOEXCEPT |
| 606 | { |
| 607 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 608 | return iterator(__end_as_link(), this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 609 | #else |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 610 | return iterator(__end_as_link()); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 611 | #endif |
| 612 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 613 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 614 | const_iterator end() const _NOEXCEPT |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 615 | { |
| 616 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 617 | return const_iterator(__end_as_link(), this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 618 | #else |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 619 | return const_iterator(__end_as_link()); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 620 | #endif |
| 621 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 622 | |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 623 | void swap(__list_imp& __c) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 624 | #if _LIBCPP_STD_VER >= 14 |
| 625 | _NOEXCEPT; |
| 626 | #else |
| 627 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 628 | __is_nothrow_swappable<allocator_type>::value); |
| 629 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 630 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 631 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 632 | void __copy_assign_alloc(const __list_imp& __c) |
| 633 | {__copy_assign_alloc(__c, integral_constant<bool, |
| 634 | __node_alloc_traits::propagate_on_container_copy_assignment::value>());} |
| 635 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 636 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 637 | void __move_assign_alloc(__list_imp& __c) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 638 | _NOEXCEPT_( |
| 639 | !__node_alloc_traits::propagate_on_container_move_assignment::value || |
| 640 | is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 641 | {__move_assign_alloc(__c, integral_constant<bool, |
| 642 | __node_alloc_traits::propagate_on_container_move_assignment::value>());} |
| 643 | |
| 644 | private: |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 645 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 646 | void __copy_assign_alloc(const __list_imp& __c, true_type) |
| 647 | { |
| 648 | if (__node_alloc() != __c.__node_alloc()) |
| 649 | clear(); |
| 650 | __node_alloc() = __c.__node_alloc(); |
| 651 | } |
| 652 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 653 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 654 | void __copy_assign_alloc(const __list_imp& __c, false_type) |
| 655 | {} |
| 656 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 657 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8668139 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 658 | void __move_assign_alloc(__list_imp& __c, true_type) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 659 | _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 660 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 661 | __node_alloc() = _VSTD::move(__c.__node_alloc()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 664 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 8668139 | 2011-09-02 20:42:31 +0000 | [diff] [blame] | 665 | void __move_assign_alloc(__list_imp& __c, false_type) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 666 | _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 667 | {} |
| 668 | }; |
| 669 | |
| 670 | // Unlink nodes [__f, __l] |
| 671 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 672 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 673 | void |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 674 | __list_imp<_Tp, _Alloc>::__unlink_nodes(__link_pointer __f, __link_pointer __l) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 675 | _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 676 | { |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 677 | __f->__prev_->__next_ = __l->__next_; |
| 678 | __l->__next_->__prev_ = __f->__prev_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 682 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 683 | __list_imp<_Tp, _Alloc>::__list_imp() |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 684 | _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 685 | : __size_alloc_(0) |
| 686 | { |
| 687 | } |
| 688 | |
| 689 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 690 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 691 | __list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) |
| 692 | : __size_alloc_(0, __node_allocator(__a)) |
| 693 | { |
| 694 | } |
| 695 | |
| 696 | template <class _Tp, class _Alloc> |
| 697 | __list_imp<_Tp, _Alloc>::~__list_imp() |
| 698 | { |
| 699 | clear(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 700 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 701 | __get_db()->__erase_c(this); |
| 702 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 703 | } |
| 704 | |
| 705 | template <class _Tp, class _Alloc> |
| 706 | void |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 707 | __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 708 | { |
| 709 | if (!empty()) |
| 710 | { |
| 711 | __node_allocator& __na = __node_alloc(); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 712 | __link_pointer __f = __end_.__next_; |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 713 | __link_pointer __l = __end_as_link(); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 714 | __unlink_nodes(__f, __l->__prev_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 715 | __sz() = 0; |
| 716 | while (__f != __l) |
| 717 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 718 | __node_pointer __np = __f->__as_node(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 719 | __f = __f->__next_; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 720 | __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); |
| 721 | __node_alloc_traits::deallocate(__na, __np, 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 722 | } |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 723 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 724 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 725 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 726 | { |
| 727 | --__p; |
| 728 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
| 729 | if (__i->__ptr_ != __l) |
| 730 | { |
| 731 | (*__p)->__c_ = nullptr; |
| 732 | if (--__c->end_ != __p) |
| 733 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 734 | } |
| 735 | } |
| 736 | __get_db()->unlock(); |
| 737 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 738 | } |
| 739 | } |
| 740 | |
| 741 | template <class _Tp, class _Alloc> |
| 742 | void |
| 743 | __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 744 | #if _LIBCPP_STD_VER >= 14 |
| 745 | _NOEXCEPT |
| 746 | #else |
| 747 | _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value || |
| 748 | __is_nothrow_swappable<allocator_type>::value) |
| 749 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 750 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 751 | _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || |
| 752 | this->__node_alloc() == __c.__node_alloc(), |
| 753 | "list::swap: Either propagate_on_container_swap must be true" |
| 754 | " or the allocators must compare equal"); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 755 | using _VSTD::swap; |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 756 | __swap_allocator(__node_alloc(), __c.__node_alloc()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 757 | swap(__sz(), __c.__sz()); |
| 758 | swap(__end_, __c.__end_); |
| 759 | if (__sz() == 0) |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 760 | __end_.__next_ = __end_.__prev_ = __end_as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 761 | else |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 762 | __end_.__prev_->__next_ = __end_.__next_->__prev_ = __end_as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 763 | if (__c.__sz() == 0) |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 764 | __c.__end_.__next_ = __c.__end_.__prev_ = __c.__end_as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 765 | else |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 766 | __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ = __c.__end_as_link(); |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 767 | |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 768 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 769 | __libcpp_db* __db = __get_db(); |
| 770 | __c_node* __cn1 = __db->__find_c_and_lock(this); |
| 771 | __c_node* __cn2 = __db->__find_c(&__c); |
| 772 | std::swap(__cn1->beg_, __cn2->beg_); |
| 773 | std::swap(__cn1->end_, __cn2->end_); |
| 774 | std::swap(__cn1->cap_, __cn2->cap_); |
| 775 | for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;) |
| 776 | { |
| 777 | --__p; |
| 778 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 779 | if (__i->__ptr_ == __c.__end_as_link()) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 780 | { |
| 781 | __cn2->__add(*__p); |
| 782 | if (--__cn1->end_ != __p) |
| 783 | memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*)); |
| 784 | } |
| 785 | else |
| 786 | (*__p)->__c_ = __cn1; |
| 787 | } |
| 788 | for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) |
| 789 | { |
| 790 | --__p; |
| 791 | const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 792 | if (__i->__ptr_ == __end_as_link()) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 793 | { |
| 794 | __cn1->__add(*__p); |
| 795 | if (--__cn2->end_ != __p) |
| 796 | memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); |
| 797 | } |
| 798 | else |
| 799 | (*__p)->__c_ = __cn2; |
| 800 | } |
| 801 | __db->unlock(); |
| 802 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Marshall Clow | b5d34aa | 2015-02-18 17:24:08 +0000 | [diff] [blame] | 805 | template <class _Tp, class _Alloc /*= allocator<_Tp>*/> |
Howard Hinnant | f0544c2 | 2013-08-12 18:38:34 +0000 | [diff] [blame] | 806 | class _LIBCPP_TYPE_VIS_ONLY list |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 807 | : private __list_imp<_Tp, _Alloc> |
| 808 | { |
| 809 | typedef __list_imp<_Tp, _Alloc> base; |
| 810 | typedef typename base::__node __node; |
| 811 | typedef typename base::__node_allocator __node_allocator; |
| 812 | typedef typename base::__node_pointer __node_pointer; |
| 813 | typedef typename base::__node_alloc_traits __node_alloc_traits; |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 814 | typedef typename base::__node_base __node_base; |
| 815 | typedef typename base::__node_base_pointer __node_base_pointer; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 816 | typedef typename base::__link_pointer __link_pointer; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 817 | |
| 818 | public: |
| 819 | typedef _Tp value_type; |
| 820 | typedef _Alloc allocator_type; |
| 821 | static_assert((is_same<value_type, typename allocator_type::value_type>::value), |
| 822 | "Invalid allocator::value_type"); |
| 823 | typedef value_type& reference; |
| 824 | typedef const value_type& const_reference; |
| 825 | typedef typename base::pointer pointer; |
| 826 | typedef typename base::const_pointer const_pointer; |
| 827 | typedef typename base::size_type size_type; |
| 828 | typedef typename base::difference_type difference_type; |
| 829 | typedef typename base::iterator iterator; |
| 830 | typedef typename base::const_iterator const_iterator; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 831 | typedef _VSTD::reverse_iterator<iterator> reverse_iterator; |
| 832 | typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 833 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 834 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 835 | list() |
| 836 | _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 837 | { |
| 838 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 839 | __get_db()->__insert_c(this); |
| 840 | #endif |
| 841 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 842 | _LIBCPP_INLINE_VISIBILITY |
Marshall Clow | fb82976 | 2013-09-08 19:11:51 +0000 | [diff] [blame] | 843 | explicit list(const allocator_type& __a) : base(__a) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 844 | { |
| 845 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 846 | __get_db()->__insert_c(this); |
| 847 | #endif |
| 848 | } |
Marshall Clow | fb82976 | 2013-09-08 19:11:51 +0000 | [diff] [blame] | 849 | explicit list(size_type __n); |
| 850 | #if _LIBCPP_STD_VER > 11 |
| 851 | explicit list(size_type __n, const allocator_type& __a); |
| 852 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 853 | list(size_type __n, const value_type& __x); |
| 854 | list(size_type __n, const value_type& __x, const allocator_type& __a); |
| 855 | template <class _InpIter> |
| 856 | list(_InpIter __f, _InpIter __l, |
| 857 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 858 | template <class _InpIter> |
| 859 | list(_InpIter __f, _InpIter __l, const allocator_type& __a, |
| 860 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 861 | |
| 862 | list(const list& __c); |
| 863 | list(const list& __c, const allocator_type& __a); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 864 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 865 | list& operator=(const list& __c); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 866 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 867 | list(initializer_list<value_type> __il); |
| 868 | list(initializer_list<value_type> __il, const allocator_type& __a); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 869 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 870 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 871 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 872 | list(list&& __c) |
| 873 | _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 874 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 875 | list(list&& __c, const allocator_type& __a); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 876 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 877 | list& operator=(list&& __c) |
| 878 | _NOEXCEPT_( |
| 879 | __node_alloc_traits::propagate_on_container_move_assignment::value && |
| 880 | is_nothrow_move_assignable<__node_allocator>::value); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 881 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 882 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 883 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 884 | list& operator=(initializer_list<value_type> __il) |
| 885 | {assign(__il.begin(), __il.end()); return *this;} |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 886 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 887 | |
| 888 | template <class _InpIter> |
| 889 | void assign(_InpIter __f, _InpIter __l, |
| 890 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
| 891 | void assign(size_type __n, const value_type& __x); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 892 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 893 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 894 | void assign(initializer_list<value_type> __il) |
| 895 | {assign(__il.begin(), __il.end());} |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 896 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 897 | |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 898 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 899 | allocator_type get_allocator() const _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 900 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 901 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 902 | size_type size() const _NOEXCEPT {return base::__sz();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 903 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 904 | bool empty() const _NOEXCEPT {return base::empty();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 905 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 906 | size_type max_size() const _NOEXCEPT |
| 907 | {return numeric_limits<difference_type>::max();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 908 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 909 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 910 | iterator begin() _NOEXCEPT {return base::begin();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 911 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 912 | const_iterator begin() const _NOEXCEPT {return base::begin();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 913 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 914 | iterator end() _NOEXCEPT {return base::end();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 915 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 916 | const_iterator end() const _NOEXCEPT {return base::end();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 917 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 918 | const_iterator cbegin() const _NOEXCEPT {return base::begin();} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 919 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 920 | const_iterator cend() const _NOEXCEPT {return base::end();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 921 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 922 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 923 | reverse_iterator rbegin() _NOEXCEPT |
| 924 | {return reverse_iterator(end());} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 925 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 926 | const_reverse_iterator rbegin() const _NOEXCEPT |
| 927 | {return const_reverse_iterator(end());} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 928 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 929 | reverse_iterator rend() _NOEXCEPT |
| 930 | {return reverse_iterator(begin());} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 931 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 932 | const_reverse_iterator rend() const _NOEXCEPT |
| 933 | {return const_reverse_iterator(begin());} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 934 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 935 | const_reverse_iterator crbegin() const _NOEXCEPT |
| 936 | {return const_reverse_iterator(end());} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 937 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 938 | const_reverse_iterator crend() const _NOEXCEPT |
| 939 | {return const_reverse_iterator(begin());} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 940 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 941 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 942 | reference front() |
| 943 | { |
| 944 | _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 945 | return base::__end_.__next_->__as_node()->__value_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 946 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 947 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 948 | const_reference front() const |
| 949 | { |
| 950 | _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 951 | return base::__end_.__next_->__as_node()->__value_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 952 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 953 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 954 | reference back() |
| 955 | { |
| 956 | _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 957 | return base::__end_.__prev_->__as_node()->__value_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 958 | } |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 959 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 960 | const_reference back() const |
| 961 | { |
| 962 | _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 963 | return base::__end_.__prev_->__as_node()->__value_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 964 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 965 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 966 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 967 | void push_front(value_type&& __x); |
| 968 | void push_back(value_type&& __x); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 969 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 970 | template <class... _Args> |
| 971 | void emplace_front(_Args&&... __args); |
| 972 | template <class... _Args> |
| 973 | void emplace_back(_Args&&... __args); |
| 974 | template <class... _Args> |
| 975 | iterator emplace(const_iterator __p, _Args&&... __args); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 976 | #endif // _LIBCPP_HAS_NO_VARIADICS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 977 | iterator insert(const_iterator __p, value_type&& __x); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 978 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 979 | |
| 980 | void push_front(const value_type& __x); |
| 981 | void push_back(const value_type& __x); |
| 982 | |
| 983 | iterator insert(const_iterator __p, const value_type& __x); |
| 984 | iterator insert(const_iterator __p, size_type __n, const value_type& __x); |
| 985 | template <class _InpIter> |
| 986 | iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, |
| 987 | typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 988 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 989 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 990 | iterator insert(const_iterator __p, initializer_list<value_type> __il) |
| 991 | {return insert(__p, __il.begin(), __il.end());} |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 992 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 993 | |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 994 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 995 | void swap(list& __c) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 996 | #if _LIBCPP_STD_VER >= 14 |
| 997 | _NOEXCEPT |
| 998 | #else |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 999 | _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || |
| 1000 | __is_nothrow_swappable<__node_allocator>::value) |
Marshall Clow | e3fbe14 | 2015-07-13 20:04:56 +0000 | [diff] [blame] | 1001 | #endif |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1002 | {base::swap(__c);} |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1003 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1004 | void clear() _NOEXCEPT {base::clear();} |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1005 | |
| 1006 | void pop_front(); |
| 1007 | void pop_back(); |
| 1008 | |
| 1009 | iterator erase(const_iterator __p); |
| 1010 | iterator erase(const_iterator __f, const_iterator __l); |
| 1011 | |
| 1012 | void resize(size_type __n); |
| 1013 | void resize(size_type __n, const value_type& __x); |
| 1014 | |
| 1015 | void splice(const_iterator __p, list& __c); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1016 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1017 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1018 | void splice(const_iterator __p, list&& __c) {splice(__p, __c);} |
| 1019 | #endif |
| 1020 | void splice(const_iterator __p, list& __c, const_iterator __i); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1021 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1022 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1023 | void splice(const_iterator __p, list&& __c, const_iterator __i) |
| 1024 | {splice(__p, __c, __i);} |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1025 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1026 | void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1027 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1028 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1029 | void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) |
| 1030 | {splice(__p, __c, __f, __l);} |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1031 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1032 | |
| 1033 | void remove(const value_type& __x); |
| 1034 | template <class _Pred> void remove_if(_Pred __pred); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1035 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1036 | void unique(); |
| 1037 | template <class _BinaryPred> |
| 1038 | void unique(_BinaryPred __binary_pred); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1039 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1040 | void merge(list& __c); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1041 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1042 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1043 | void merge(list&& __c) {merge(__c);} |
| 1044 | #endif |
| 1045 | template <class _Comp> |
| 1046 | void merge(list& __c, _Comp __comp); |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1047 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1048 | template <class _Comp> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 1049 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1050 | void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1051 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1052 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1053 | void sort(); |
| 1054 | template <class _Comp> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1055 | _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1056 | void sort(_Comp __comp); |
| 1057 | |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1058 | void reverse() _NOEXCEPT; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1059 | |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1060 | bool __invariants() const; |
| 1061 | |
| 1062 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1063 | |
| 1064 | bool __dereferenceable(const const_iterator* __i) const; |
| 1065 | bool __decrementable(const const_iterator* __i) const; |
| 1066 | bool __addable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1067 | bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; |
| 1068 | |
| 1069 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 1070 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1071 | private: |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1072 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1073 | static void __link_nodes (__link_pointer __p, __link_pointer __f, __link_pointer __l); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1074 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1075 | void __link_nodes_at_front(__link_pointer __f, __link_pointer __l); |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1076 | _LIBCPP_INLINE_VISIBILITY |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1077 | void __link_nodes_at_back (__link_pointer __f, __link_pointer __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1078 | iterator __iterator(size_type __n); |
| 1079 | template <class _Comp> |
| 1080 | static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); |
| 1081 | |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1082 | void __move_assign(list& __c, true_type) |
| 1083 | _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1084 | void __move_assign(list& __c, false_type); |
| 1085 | }; |
| 1086 | |
| 1087 | // Link in nodes [__f, __l] just prior to __p |
| 1088 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1089 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1090 | void |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1091 | list<_Tp, _Alloc>::__link_nodes(__link_pointer __p, __link_pointer __f, __link_pointer __l) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1092 | { |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1093 | __p->__prev_->__next_ = __f; |
| 1094 | __f->__prev_ = __p->__prev_; |
| 1095 | __p->__prev_ = __l; |
| 1096 | __l->__next_ = __p; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1097 | } |
| 1098 | |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1099 | // Link in nodes [__f, __l] at the front of the list |
| 1100 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1101 | inline |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1102 | void |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1103 | list<_Tp, _Alloc>::__link_nodes_at_front(__link_pointer __f, __link_pointer __l) |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1104 | { |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 1105 | __f->__prev_ = base::__end_as_link(); |
Marshall Clow | ced7006 | 2014-08-08 15:35:52 +0000 | [diff] [blame] | 1106 | __l->__next_ = base::__end_.__next_; |
| 1107 | __l->__next_->__prev_ = __l; |
| 1108 | base::__end_.__next_ = __f; |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | // Link in nodes [__f, __l] at the front of the list |
| 1112 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1113 | inline |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1114 | void |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1115 | list<_Tp, _Alloc>::__link_nodes_at_back(__link_pointer __f, __link_pointer __l) |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1116 | { |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 1117 | __l->__next_ = base::__end_as_link(); |
Marshall Clow | ced7006 | 2014-08-08 15:35:52 +0000 | [diff] [blame] | 1118 | __f->__prev_ = base::__end_.__prev_; |
| 1119 | __f->__prev_->__next_ = __f; |
| 1120 | base::__end_.__prev_ = __l; |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1121 | } |
| 1122 | |
| 1123 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1124 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1125 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1126 | typename list<_Tp, _Alloc>::iterator |
| 1127 | list<_Tp, _Alloc>::__iterator(size_type __n) |
| 1128 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1129 | return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n) |
| 1130 | : _VSTD::prev(end(), base::__sz() - __n); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | template <class _Tp, class _Alloc> |
| 1134 | list<_Tp, _Alloc>::list(size_type __n) |
| 1135 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1136 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1137 | __get_db()->__insert_c(this); |
| 1138 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1139 | for (; __n > 0; --__n) |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1140 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1141 | emplace_back(); |
| 1142 | #else |
| 1143 | push_back(value_type()); |
| 1144 | #endif |
| 1145 | } |
| 1146 | |
Marshall Clow | fb82976 | 2013-09-08 19:11:51 +0000 | [diff] [blame] | 1147 | #if _LIBCPP_STD_VER > 11 |
| 1148 | template <class _Tp, class _Alloc> |
| 1149 | list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a) |
| 1150 | { |
| 1151 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1152 | __get_db()->__insert_c(this); |
| 1153 | #endif |
| 1154 | for (; __n > 0; --__n) |
| 1155 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
| 1156 | emplace_back(); |
| 1157 | #else |
| 1158 | push_back(value_type()); |
| 1159 | #endif |
| 1160 | } |
| 1161 | #endif |
| 1162 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1163 | template <class _Tp, class _Alloc> |
| 1164 | list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) |
| 1165 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1166 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1167 | __get_db()->__insert_c(this); |
| 1168 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1169 | for (; __n > 0; --__n) |
| 1170 | push_back(__x); |
| 1171 | } |
| 1172 | |
| 1173 | template <class _Tp, class _Alloc> |
| 1174 | list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) |
| 1175 | : base(__a) |
| 1176 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1177 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1178 | __get_db()->__insert_c(this); |
| 1179 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1180 | for (; __n > 0; --__n) |
| 1181 | push_back(__x); |
| 1182 | } |
| 1183 | |
| 1184 | template <class _Tp, class _Alloc> |
| 1185 | template <class _InpIter> |
| 1186 | list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, |
| 1187 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 1188 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1189 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1190 | __get_db()->__insert_c(this); |
| 1191 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1192 | for (; __f != __l; ++__f) |
| 1193 | push_back(*__f); |
| 1194 | } |
| 1195 | |
| 1196 | template <class _Tp, class _Alloc> |
| 1197 | template <class _InpIter> |
| 1198 | list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, |
| 1199 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 1200 | : base(__a) |
| 1201 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1202 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1203 | __get_db()->__insert_c(this); |
| 1204 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1205 | for (; __f != __l; ++__f) |
| 1206 | push_back(*__f); |
| 1207 | } |
| 1208 | |
| 1209 | template <class _Tp, class _Alloc> |
| 1210 | list<_Tp, _Alloc>::list(const list& __c) |
| 1211 | : base(allocator_type( |
| 1212 | __node_alloc_traits::select_on_container_copy_construction( |
| 1213 | __c.__node_alloc()))) |
| 1214 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1215 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1216 | __get_db()->__insert_c(this); |
| 1217 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1218 | for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) |
| 1219 | push_back(*__i); |
| 1220 | } |
| 1221 | |
| 1222 | template <class _Tp, class _Alloc> |
| 1223 | list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) |
| 1224 | : base(__a) |
| 1225 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1226 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1227 | __get_db()->__insert_c(this); |
| 1228 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1229 | for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) |
| 1230 | push_back(*__i); |
| 1231 | } |
| 1232 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1233 | #ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1234 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1235 | template <class _Tp, class _Alloc> |
| 1236 | list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) |
| 1237 | : base(__a) |
| 1238 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1239 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1240 | __get_db()->__insert_c(this); |
| 1241 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1242 | for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), |
| 1243 | __e = __il.end(); __i != __e; ++__i) |
| 1244 | push_back(*__i); |
| 1245 | } |
| 1246 | |
| 1247 | template <class _Tp, class _Alloc> |
| 1248 | list<_Tp, _Alloc>::list(initializer_list<value_type> __il) |
| 1249 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1250 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1251 | __get_db()->__insert_c(this); |
| 1252 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1253 | for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), |
| 1254 | __e = __il.end(); __i != __e; ++__i) |
| 1255 | push_back(*__i); |
| 1256 | } |
| 1257 | |
Howard Hinnant | 54976f2 | 2011-08-12 21:56:02 +0000 | [diff] [blame] | 1258 | #endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS |
| 1259 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1260 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1261 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1262 | list<_Tp, _Alloc>& |
| 1263 | list<_Tp, _Alloc>::operator=(const list& __c) |
| 1264 | { |
| 1265 | if (this != &__c) |
| 1266 | { |
| 1267 | base::__copy_assign_alloc(__c); |
| 1268 | assign(__c.begin(), __c.end()); |
| 1269 | } |
| 1270 | return *this; |
| 1271 | } |
| 1272 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1273 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1274 | |
| 1275 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1276 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1277 | list<_Tp, _Alloc>::list(list&& __c) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1278 | _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1279 | : base(allocator_type(_VSTD::move(__c.__node_alloc()))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1280 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1281 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1282 | __get_db()->__insert_c(this); |
| 1283 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1284 | splice(end(), __c); |
| 1285 | } |
| 1286 | |
| 1287 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1288 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1289 | list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) |
| 1290 | : base(__a) |
| 1291 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1292 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1293 | __get_db()->__insert_c(this); |
| 1294 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1295 | if (__a == __c.get_allocator()) |
| 1296 | splice(end(), __c); |
| 1297 | else |
| 1298 | { |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1299 | typedef move_iterator<iterator> _Ip; |
| 1300 | assign(_Ip(__c.begin()), _Ip(__c.end())); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1305 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1306 | list<_Tp, _Alloc>& |
| 1307 | list<_Tp, _Alloc>::operator=(list&& __c) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1308 | _NOEXCEPT_( |
| 1309 | __node_alloc_traits::propagate_on_container_move_assignment::value && |
| 1310 | is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1311 | { |
| 1312 | __move_assign(__c, integral_constant<bool, |
| 1313 | __node_alloc_traits::propagate_on_container_move_assignment::value>()); |
| 1314 | return *this; |
| 1315 | } |
| 1316 | |
| 1317 | template <class _Tp, class _Alloc> |
| 1318 | void |
| 1319 | list<_Tp, _Alloc>::__move_assign(list& __c, false_type) |
| 1320 | { |
| 1321 | if (base::__node_alloc() != __c.__node_alloc()) |
| 1322 | { |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1323 | typedef move_iterator<iterator> _Ip; |
| 1324 | assign(_Ip(__c.begin()), _Ip(__c.end())); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1325 | } |
| 1326 | else |
| 1327 | __move_assign(__c, true_type()); |
| 1328 | } |
| 1329 | |
| 1330 | template <class _Tp, class _Alloc> |
| 1331 | void |
| 1332 | list<_Tp, _Alloc>::__move_assign(list& __c, true_type) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1333 | _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1334 | { |
| 1335 | clear(); |
| 1336 | base::__move_assign_alloc(__c); |
| 1337 | splice(end(), __c); |
| 1338 | } |
| 1339 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1340 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1341 | |
| 1342 | template <class _Tp, class _Alloc> |
| 1343 | template <class _InpIter> |
| 1344 | void |
| 1345 | list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, |
| 1346 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 1347 | { |
| 1348 | iterator __i = begin(); |
| 1349 | iterator __e = end(); |
| 1350 | for (; __f != __l && __i != __e; ++__f, ++__i) |
| 1351 | *__i = *__f; |
| 1352 | if (__i == __e) |
| 1353 | insert(__e, __f, __l); |
| 1354 | else |
| 1355 | erase(__i, __e); |
| 1356 | } |
| 1357 | |
| 1358 | template <class _Tp, class _Alloc> |
| 1359 | void |
| 1360 | list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) |
| 1361 | { |
| 1362 | iterator __i = begin(); |
| 1363 | iterator __e = end(); |
| 1364 | for (; __n > 0 && __i != __e; --__n, ++__i) |
| 1365 | *__i = __x; |
| 1366 | if (__i == __e) |
| 1367 | insert(__e, __n, __x); |
| 1368 | else |
| 1369 | erase(__i, __e); |
| 1370 | } |
| 1371 | |
| 1372 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 1373 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1374 | _Alloc |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 1375 | list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1376 | { |
| 1377 | return allocator_type(base::__node_alloc()); |
| 1378 | } |
| 1379 | |
| 1380 | template <class _Tp, class _Alloc> |
| 1381 | typename list<_Tp, _Alloc>::iterator |
| 1382 | list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) |
| 1383 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1384 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1385 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1386 | "list::insert(iterator, x) called with an iterator not" |
| 1387 | " referring to this list"); |
| 1388 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1389 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1390 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1391 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1392 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1393 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1394 | __link_nodes(__p.__ptr_, __hold->__as_link(), __hold->__as_link()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1395 | ++base::__sz(); |
Howard Hinnant | b0e4c9d | 2013-04-05 00:18:49 +0000 | [diff] [blame] | 1396 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1397 | return iterator(__hold.release()->__as_link(), this); |
Howard Hinnant | b0e4c9d | 2013-04-05 00:18:49 +0000 | [diff] [blame] | 1398 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1399 | return iterator(__hold.release()->__as_link()); |
Howard Hinnant | b0e4c9d | 2013-04-05 00:18:49 +0000 | [diff] [blame] | 1400 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | template <class _Tp, class _Alloc> |
| 1404 | typename list<_Tp, _Alloc>::iterator |
| 1405 | list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) |
| 1406 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1407 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1408 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1409 | "list::insert(iterator, n, x) called with an iterator not" |
| 1410 | " referring to this list"); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1411 | iterator __r(__p.__ptr_, this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1412 | #else |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1413 | iterator __r(__p.__ptr_); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1414 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1415 | if (__n > 0) |
| 1416 | { |
| 1417 | size_type __ds = 0; |
| 1418 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1419 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1420 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1421 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1422 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1423 | ++__ds; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1424 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1425 | __r = iterator(__hold->__as_link(), this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1426 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1427 | __r = iterator(__hold->__as_link()); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1428 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1429 | __hold.release(); |
| 1430 | iterator __e = __r; |
| 1431 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1432 | try |
| 1433 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1434 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1435 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1436 | { |
| 1437 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1438 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1439 | __e.__ptr_->__next_ = __hold->__as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1440 | __hold->__prev_ = __e.__ptr_; |
| 1441 | __hold.release(); |
| 1442 | } |
| 1443 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1444 | } |
| 1445 | catch (...) |
| 1446 | { |
| 1447 | while (true) |
| 1448 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1449 | __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1450 | __link_pointer __prev = __e.__ptr_->__prev_; |
| 1451 | __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1452 | if (__prev == 0) |
| 1453 | break; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1454 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1455 | __e = iterator(__prev, this); |
| 1456 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1457 | __e = iterator(__prev); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1458 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1459 | } |
| 1460 | throw; |
| 1461 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1462 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1463 | __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1464 | base::__sz() += __ds; |
| 1465 | } |
| 1466 | return __r; |
| 1467 | } |
| 1468 | |
| 1469 | template <class _Tp, class _Alloc> |
| 1470 | template <class _InpIter> |
| 1471 | typename list<_Tp, _Alloc>::iterator |
| 1472 | list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, |
| 1473 | typename enable_if<__is_input_iterator<_InpIter>::value>::type*) |
| 1474 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1475 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1476 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1477 | "list::insert(iterator, range) called with an iterator not" |
| 1478 | " referring to this list"); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1479 | iterator __r(__p.__ptr_, this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1480 | #else |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1481 | iterator __r(__p.__ptr_); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1482 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1483 | if (__f != __l) |
| 1484 | { |
| 1485 | size_type __ds = 0; |
| 1486 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1487 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1488 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1489 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1490 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1491 | ++__ds; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1492 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1493 | __r = iterator(__hold.get()->__as_link(), this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1494 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1495 | __r = iterator(__hold.get()->__as_link()); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1496 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1497 | __hold.release(); |
| 1498 | iterator __e = __r; |
| 1499 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1500 | try |
| 1501 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1502 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | 61bff61 | 2015-03-19 03:20:02 +0000 | [diff] [blame] | 1503 | for (++__f; __f != __l; ++__f, (void) ++__e, (void) ++__ds) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1504 | { |
| 1505 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1506 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1507 | __e.__ptr_->__next_ = __hold.get()->__as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1508 | __hold->__prev_ = __e.__ptr_; |
| 1509 | __hold.release(); |
| 1510 | } |
| 1511 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1512 | } |
| 1513 | catch (...) |
| 1514 | { |
| 1515 | while (true) |
| 1516 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1517 | __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1518 | __link_pointer __prev = __e.__ptr_->__prev_; |
| 1519 | __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1520 | if (__prev == 0) |
| 1521 | break; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1522 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1523 | __e = iterator(__prev, this); |
| 1524 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1525 | __e = iterator(__prev); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1526 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1527 | } |
| 1528 | throw; |
| 1529 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1530 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1531 | __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1532 | base::__sz() += __ds; |
| 1533 | } |
| 1534 | return __r; |
| 1535 | } |
| 1536 | |
| 1537 | template <class _Tp, class _Alloc> |
| 1538 | void |
| 1539 | list<_Tp, _Alloc>::push_front(const value_type& __x) |
| 1540 | { |
| 1541 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1542 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1543 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1544 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1545 | __link_pointer __nl = __hold->__as_link(); |
| 1546 | __link_nodes_at_front(__nl, __nl); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1547 | ++base::__sz(); |
| 1548 | __hold.release(); |
| 1549 | } |
| 1550 | |
| 1551 | template <class _Tp, class _Alloc> |
| 1552 | void |
| 1553 | list<_Tp, _Alloc>::push_back(const value_type& __x) |
| 1554 | { |
| 1555 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1556 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1557 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1558 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1559 | __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1560 | ++base::__sz(); |
| 1561 | __hold.release(); |
| 1562 | } |
| 1563 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1564 | #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1565 | |
| 1566 | template <class _Tp, class _Alloc> |
| 1567 | void |
| 1568 | list<_Tp, _Alloc>::push_front(value_type&& __x) |
| 1569 | { |
| 1570 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1571 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1572 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1573 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1574 | __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1575 | ++base::__sz(); |
| 1576 | __hold.release(); |
| 1577 | } |
| 1578 | |
| 1579 | template <class _Tp, class _Alloc> |
| 1580 | void |
| 1581 | list<_Tp, _Alloc>::push_back(value_type&& __x) |
| 1582 | { |
| 1583 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1584 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1585 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1586 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1587 | __link_nodes_at_back(__hold.get()->__as_link(), __hold.get()->__as_link()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1588 | ++base::__sz(); |
| 1589 | __hold.release(); |
| 1590 | } |
| 1591 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1592 | #ifndef _LIBCPP_HAS_NO_VARIADICS |
| 1593 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1594 | template <class _Tp, class _Alloc> |
| 1595 | template <class... _Args> |
| 1596 | void |
| 1597 | list<_Tp, _Alloc>::emplace_front(_Args&&... __args) |
| 1598 | { |
| 1599 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1600 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1601 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1602 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1603 | __link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1604 | ++base::__sz(); |
| 1605 | __hold.release(); |
| 1606 | } |
| 1607 | |
| 1608 | template <class _Tp, class _Alloc> |
| 1609 | template <class... _Args> |
| 1610 | void |
| 1611 | list<_Tp, _Alloc>::emplace_back(_Args&&... __args) |
| 1612 | { |
| 1613 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1614 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1615 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1616 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1617 | __link_pointer __nl = __hold->__as_link(); |
| 1618 | __link_nodes_at_back(__nl, __nl); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1619 | ++base::__sz(); |
| 1620 | __hold.release(); |
| 1621 | } |
| 1622 | |
| 1623 | template <class _Tp, class _Alloc> |
| 1624 | template <class... _Args> |
| 1625 | typename list<_Tp, _Alloc>::iterator |
| 1626 | list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) |
| 1627 | { |
Howard Hinnant | b0e4c9d | 2013-04-05 00:18:49 +0000 | [diff] [blame] | 1628 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1629 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1630 | "list::emplace(iterator, args...) called with an iterator not" |
| 1631 | " referring to this list"); |
| 1632 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1633 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1634 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1635 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1636 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1637 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1638 | __link_pointer __nl = __hold.get()->__as_link(); |
| 1639 | __link_nodes(__p.__ptr_, __nl, __nl); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1640 | ++base::__sz(); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1641 | __hold.release(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1642 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1643 | return iterator(__nl, this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1644 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1645 | return iterator(__nl); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1646 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1647 | } |
| 1648 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1649 | #endif // _LIBCPP_HAS_NO_VARIADICS |
| 1650 | |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1651 | template <class _Tp, class _Alloc> |
| 1652 | typename list<_Tp, _Alloc>::iterator |
| 1653 | list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) |
| 1654 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1655 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1656 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1657 | "list::insert(iterator, x) called with an iterator not" |
| 1658 | " referring to this list"); |
| 1659 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1660 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1661 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1662 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1663 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1664 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1665 | __link_pointer __nl = __hold->__as_link(); |
| 1666 | __link_nodes(__p.__ptr_, __nl, __nl); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1667 | ++base::__sz(); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1668 | __hold.release(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1669 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1670 | return iterator(__nl, this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1671 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1672 | return iterator(__nl); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1673 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
Howard Hinnant | 7609c9b | 2010-09-04 23:28:19 +0000 | [diff] [blame] | 1676 | #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1677 | |
| 1678 | template <class _Tp, class _Alloc> |
| 1679 | void |
| 1680 | list<_Tp, _Alloc>::pop_front() |
| 1681 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1682 | _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1683 | __node_allocator& __na = base::__node_alloc(); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1684 | __link_pointer __n = base::__end_.__next_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1685 | base::__unlink_nodes(__n, __n); |
| 1686 | --base::__sz(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1687 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1688 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1689 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 1690 | { |
| 1691 | --__p; |
| 1692 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1693 | if (__i->__ptr_ == __n) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1694 | { |
| 1695 | (*__p)->__c_ = nullptr; |
| 1696 | if (--__c->end_ != __p) |
| 1697 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1698 | } |
| 1699 | } |
| 1700 | __get_db()->unlock(); |
| 1701 | #endif |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1702 | __node_pointer __np = __n->__as_node(); |
| 1703 | __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); |
| 1704 | __node_alloc_traits::deallocate(__na, __np, 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1705 | } |
| 1706 | |
| 1707 | template <class _Tp, class _Alloc> |
| 1708 | void |
| 1709 | list<_Tp, _Alloc>::pop_back() |
| 1710 | { |
Dmitri Gribenko | c3f9c80 | 2013-06-24 06:15:57 +0000 | [diff] [blame] | 1711 | _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1712 | __node_allocator& __na = base::__node_alloc(); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1713 | __link_pointer __n = base::__end_.__prev_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1714 | base::__unlink_nodes(__n, __n); |
| 1715 | --base::__sz(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1716 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1717 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1718 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 1719 | { |
| 1720 | --__p; |
| 1721 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1722 | if (__i->__ptr_ == __n) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1723 | { |
| 1724 | (*__p)->__c_ = nullptr; |
| 1725 | if (--__c->end_ != __p) |
| 1726 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1727 | } |
| 1728 | } |
| 1729 | __get_db()->unlock(); |
| 1730 | #endif |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1731 | __node_pointer __np = __n->__as_node(); |
| 1732 | __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); |
| 1733 | __node_alloc_traits::deallocate(__na, __np, 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
| 1736 | template <class _Tp, class _Alloc> |
| 1737 | typename list<_Tp, _Alloc>::iterator |
| 1738 | list<_Tp, _Alloc>::erase(const_iterator __p) |
| 1739 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1740 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1741 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1742 | "list::erase(iterator) called with an iterator not" |
| 1743 | " referring to this list"); |
| 1744 | #endif |
Howard Hinnant | b0e4c9d | 2013-04-05 00:18:49 +0000 | [diff] [blame] | 1745 | _LIBCPP_ASSERT(__p != end(), |
| 1746 | "list::erase(iterator) called with a non-dereferenceable iterator"); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1747 | __node_allocator& __na = base::__node_alloc(); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1748 | __link_pointer __n = __p.__ptr_; |
| 1749 | __link_pointer __r = __n->__next_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1750 | base::__unlink_nodes(__n, __n); |
| 1751 | --base::__sz(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1752 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1753 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1754 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 1755 | { |
| 1756 | --__p; |
| 1757 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1758 | if (__i->__ptr_ == __n) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1759 | { |
| 1760 | (*__p)->__c_ = nullptr; |
| 1761 | if (--__c->end_ != __p) |
| 1762 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1763 | } |
| 1764 | } |
| 1765 | __get_db()->unlock(); |
| 1766 | #endif |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1767 | __node_pointer __np = __n->__as_node(); |
| 1768 | __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); |
| 1769 | __node_alloc_traits::deallocate(__na, __np, 1); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1770 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1771 | return iterator(__r, this); |
| 1772 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1773 | return iterator(__r); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1774 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
| 1777 | template <class _Tp, class _Alloc> |
| 1778 | typename list<_Tp, _Alloc>::iterator |
| 1779 | list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) |
| 1780 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1781 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1782 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this, |
| 1783 | "list::erase(iterator, iterator) called with an iterator not" |
| 1784 | " referring to this list"); |
| 1785 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1786 | if (__f != __l) |
| 1787 | { |
| 1788 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1789 | base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1790 | while (__f != __l) |
| 1791 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1792 | __link_pointer __n = __f.__ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1793 | ++__f; |
| 1794 | --base::__sz(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1795 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1796 | __c_node* __c = __get_db()->__find_c_and_lock(this); |
| 1797 | for (__i_node** __p = __c->end_; __p != __c->beg_; ) |
| 1798 | { |
| 1799 | --__p; |
| 1800 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1801 | if (__i->__ptr_ == __n) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1802 | { |
| 1803 | (*__p)->__c_ = nullptr; |
| 1804 | if (--__c->end_ != __p) |
| 1805 | memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); |
| 1806 | } |
| 1807 | } |
| 1808 | __get_db()->unlock(); |
| 1809 | #endif |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1810 | __node_pointer __np = __n->__as_node(); |
| 1811 | __node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_)); |
| 1812 | __node_alloc_traits::deallocate(__na, __np, 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1813 | } |
| 1814 | } |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1815 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1816 | return iterator(__l.__ptr_, this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1817 | #else |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1818 | return iterator(__l.__ptr_); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1819 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | template <class _Tp, class _Alloc> |
| 1823 | void |
| 1824 | list<_Tp, _Alloc>::resize(size_type __n) |
| 1825 | { |
| 1826 | if (__n < base::__sz()) |
| 1827 | erase(__iterator(__n), end()); |
| 1828 | else if (__n > base::__sz()) |
| 1829 | { |
| 1830 | __n -= base::__sz(); |
| 1831 | size_type __ds = 0; |
| 1832 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1833 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1834 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1835 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1836 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1837 | ++__ds; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1838 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1839 | iterator __r = iterator(__hold.release()->__as_link(), this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1840 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1841 | iterator __r = iterator(__hold.release()->__as_link()); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1842 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1843 | iterator __e = __r; |
| 1844 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1845 | try |
| 1846 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1847 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1848 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1849 | { |
| 1850 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1851 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1852 | __e.__ptr_->__next_ = __hold.get()->__as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1853 | __hold->__prev_ = __e.__ptr_; |
| 1854 | __hold.release(); |
| 1855 | } |
| 1856 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1857 | } |
| 1858 | catch (...) |
| 1859 | { |
| 1860 | while (true) |
| 1861 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1862 | __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1863 | __link_pointer __prev = __e.__ptr_->__prev_; |
| 1864 | __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1865 | if (__prev == 0) |
| 1866 | break; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1867 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1868 | __e = iterator(__prev, this); |
| 1869 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1870 | __e = iterator(__prev); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1871 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1872 | } |
| 1873 | throw; |
| 1874 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1875 | #endif // _LIBCPP_NO_EXCEPTIONS |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 1876 | __link_nodes_at_back(__r.__ptr_, __e.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1877 | base::__sz() += __ds; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | template <class _Tp, class _Alloc> |
| 1882 | void |
| 1883 | list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) |
| 1884 | { |
| 1885 | if (__n < base::__sz()) |
| 1886 | erase(__iterator(__n), end()); |
| 1887 | else if (__n > base::__sz()) |
| 1888 | { |
| 1889 | __n -= base::__sz(); |
| 1890 | size_type __ds = 0; |
| 1891 | __node_allocator& __na = base::__node_alloc(); |
Howard Hinnant | c003db1 | 2011-11-29 18:15:50 +0000 | [diff] [blame] | 1892 | typedef __allocator_destructor<__node_allocator> _Dp; |
| 1893 | unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1894 | __hold->__prev_ = 0; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1895 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1896 | ++__ds; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1897 | __link_pointer __nl = __hold.release()->__as_link(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1898 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1899 | iterator __r = iterator(__nl, this); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1900 | #else |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1901 | iterator __r = iterator(__nl); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1902 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1903 | iterator __e = __r; |
| 1904 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1905 | try |
| 1906 | { |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1907 | #endif // _LIBCPP_NO_EXCEPTIONS |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1908 | for (--__n; __n != 0; --__n, ++__e, ++__ds) |
| 1909 | { |
| 1910 | __hold.reset(__node_alloc_traits::allocate(__na, 1)); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1911 | __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1912 | __e.__ptr_->__next_ = __hold.get()->__as_link(); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1913 | __hold->__prev_ = __e.__ptr_; |
| 1914 | __hold.release(); |
| 1915 | } |
| 1916 | #ifndef _LIBCPP_NO_EXCEPTIONS |
| 1917 | } |
| 1918 | catch (...) |
| 1919 | { |
| 1920 | while (true) |
| 1921 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 1922 | __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1923 | __link_pointer __prev = __e.__ptr_->__prev_; |
| 1924 | __node_alloc_traits::deallocate(__na, __e.__ptr_->__as_node(), 1); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1925 | if (__prev == 0) |
| 1926 | break; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1927 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1928 | __e = iterator(__prev, this); |
| 1929 | #else |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1930 | __e = iterator(__prev); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1931 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1932 | } |
| 1933 | throw; |
| 1934 | } |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1935 | #endif // _LIBCPP_NO_EXCEPTIONS |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 1936 | __link_nodes(base::__end_as_link(), __r.__ptr_, __e.__ptr_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1937 | base::__sz() += __ds; |
Howard Hinnant | b3371f6 | 2010-08-22 00:02:43 +0000 | [diff] [blame] | 1938 | } |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1939 | } |
| 1940 | |
| 1941 | template <class _Tp, class _Alloc> |
| 1942 | void |
| 1943 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) |
| 1944 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1945 | _LIBCPP_ASSERT(this != &__c, |
| 1946 | "list::splice(iterator, list) called with this == &list"); |
| 1947 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1948 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1949 | "list::splice(iterator, list) called with an iterator not" |
| 1950 | " referring to this list"); |
| 1951 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1952 | if (!__c.empty()) |
| 1953 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1954 | __link_pointer __f = __c.__end_.__next_; |
| 1955 | __link_pointer __l = __c.__end_.__prev_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1956 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 1957 | __link_nodes(__p.__ptr_, __f, __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1958 | base::__sz() += __c.__sz(); |
| 1959 | __c.__sz() = 0; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1960 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1961 | __libcpp_db* __db = __get_db(); |
| 1962 | __c_node* __cn1 = __db->__find_c_and_lock(this); |
| 1963 | __c_node* __cn2 = __db->__find_c(&__c); |
| 1964 | for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) |
| 1965 | { |
| 1966 | --__p; |
| 1967 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 1968 | if (__i->__ptr_ != __c.__end_as_link()) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1969 | { |
| 1970 | __cn1->__add(*__p); |
| 1971 | (*__p)->__c_ = __cn1; |
| 1972 | if (--__cn2->end_ != __p) |
| 1973 | memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); |
| 1974 | } |
| 1975 | } |
| 1976 | __db->unlock(); |
| 1977 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | template <class _Tp, class _Alloc> |
| 1982 | void |
| 1983 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) |
| 1984 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 1985 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 1986 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 1987 | "list::splice(iterator, list, iterator) called with first iterator not" |
| 1988 | " referring to this list"); |
| 1989 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c, |
| 1990 | "list::splice(iterator, list, iterator) called with second iterator not" |
| 1991 | " referring to list argument"); |
| 1992 | _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i), |
| 1993 | "list::splice(iterator, list, iterator) called with second iterator not" |
| 1994 | " derefereceable"); |
| 1995 | #endif |
| 1996 | if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1997 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 1998 | __link_pointer __f = __i.__ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1999 | base::__unlink_nodes(__f, __f); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2000 | __link_nodes(__p.__ptr_, __f, __f); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2001 | --__c.__sz(); |
| 2002 | ++base::__sz(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2003 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2004 | __libcpp_db* __db = __get_db(); |
| 2005 | __c_node* __cn1 = __db->__find_c_and_lock(this); |
| 2006 | __c_node* __cn2 = __db->__find_c(&__c); |
| 2007 | for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) |
| 2008 | { |
| 2009 | --__p; |
| 2010 | iterator* __j = static_cast<iterator*>((*__p)->__i_); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2011 | if (__j->__ptr_ == __f) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2012 | { |
| 2013 | __cn1->__add(*__p); |
| 2014 | (*__p)->__c_ = __cn1; |
| 2015 | if (--__cn2->end_ != __p) |
| 2016 | memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); |
| 2017 | } |
| 2018 | } |
| 2019 | __db->unlock(); |
| 2020 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2021 | } |
| 2022 | } |
| 2023 | |
| 2024 | template <class _Tp, class _Alloc> |
| 2025 | void |
| 2026 | list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) |
| 2027 | { |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2028 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2029 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, |
| 2030 | "list::splice(iterator, list, iterator, iterator) called with first iterator not" |
| 2031 | " referring to this list"); |
| 2032 | _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c, |
| 2033 | "list::splice(iterator, list, iterator, iterator) called with second iterator not" |
| 2034 | " referring to list argument"); |
| 2035 | if (this == &__c) |
| 2036 | { |
| 2037 | for (const_iterator __i = __f; __i != __l; ++__i) |
| 2038 | _LIBCPP_ASSERT(__i != __p, |
| 2039 | "list::splice(iterator, list, iterator, iterator)" |
| 2040 | " called with the first iterator within the range" |
| 2041 | " of the second and third iterators"); |
| 2042 | } |
| 2043 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2044 | if (__f != __l) |
| 2045 | { |
| 2046 | if (this != &__c) |
| 2047 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2048 | size_type __s = _VSTD::distance(__f, __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2049 | __c.__sz() -= __s; |
| 2050 | base::__sz() += __s; |
| 2051 | } |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2052 | __link_pointer __first = __f.__ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2053 | --__l; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2054 | __link_pointer __last = __l.__ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2055 | base::__unlink_nodes(__first, __last); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2056 | __link_nodes(__p.__ptr_, __first, __last); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2057 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2058 | __libcpp_db* __db = __get_db(); |
| 2059 | __c_node* __cn1 = __db->__find_c_and_lock(this); |
| 2060 | __c_node* __cn2 = __db->__find_c(&__c); |
| 2061 | for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) |
| 2062 | { |
| 2063 | --__p; |
| 2064 | iterator* __j = static_cast<iterator*>((*__p)->__i_); |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2065 | for (__link_pointer __k = __f.__ptr_; |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2066 | __k != __l.__ptr_; __k = __k->__next_) |
| 2067 | { |
| 2068 | if (__j->__ptr_ == __k) |
| 2069 | { |
| 2070 | __cn1->__add(*__p); |
| 2071 | (*__p)->__c_ = __cn1; |
| 2072 | if (--__cn2->end_ != __p) |
| 2073 | memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); |
| 2074 | } |
| 2075 | } |
| 2076 | } |
| 2077 | __db->unlock(); |
| 2078 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | template <class _Tp, class _Alloc> |
| 2083 | void |
| 2084 | list<_Tp, _Alloc>::remove(const value_type& __x) |
| 2085 | { |
Marshall Clow | ced7006 | 2014-08-08 15:35:52 +0000 | [diff] [blame] | 2086 | list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing |
| 2087 | for (const_iterator __i = begin(), __e = end(); __i != __e;) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2088 | { |
| 2089 | if (*__i == __x) |
| 2090 | { |
Marshall Clow | ced7006 | 2014-08-08 15:35:52 +0000 | [diff] [blame] | 2091 | const_iterator __j = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2092 | for (; __j != __e && *__j == __x; ++__j) |
| 2093 | ; |
Marshall Clow | ced7006 | 2014-08-08 15:35:52 +0000 | [diff] [blame] | 2094 | __deleted_nodes.splice(__deleted_nodes.end(), *this, __i, __j); |
| 2095 | __i = __j; |
Marshall Clow | 90ba0533 | 2014-08-04 17:32:25 +0000 | [diff] [blame] | 2096 | if (__i != __e) |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 2097 | ++__i; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2098 | } |
| 2099 | else |
| 2100 | ++__i; |
| 2101 | } |
| 2102 | } |
| 2103 | |
| 2104 | template <class _Tp, class _Alloc> |
| 2105 | template <class _Pred> |
| 2106 | void |
| 2107 | list<_Tp, _Alloc>::remove_if(_Pred __pred) |
| 2108 | { |
| 2109 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 2110 | { |
| 2111 | if (__pred(*__i)) |
| 2112 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2113 | iterator __j = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2114 | for (; __j != __e && __pred(*__j); ++__j) |
| 2115 | ; |
| 2116 | __i = erase(__i, __j); |
Marshall Clow | 90ba0533 | 2014-08-04 17:32:25 +0000 | [diff] [blame] | 2117 | if (__i != __e) |
Marshall Clow | 28d65da | 2014-08-05 01:34:12 +0000 | [diff] [blame] | 2118 | ++__i; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2119 | } |
| 2120 | else |
| 2121 | ++__i; |
| 2122 | } |
| 2123 | } |
| 2124 | |
| 2125 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 2126 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2127 | void |
| 2128 | list<_Tp, _Alloc>::unique() |
| 2129 | { |
| 2130 | unique(__equal_to<value_type>()); |
| 2131 | } |
| 2132 | |
| 2133 | template <class _Tp, class _Alloc> |
| 2134 | template <class _BinaryPred> |
| 2135 | void |
| 2136 | list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) |
| 2137 | { |
| 2138 | for (iterator __i = begin(), __e = end(); __i != __e;) |
| 2139 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2140 | iterator __j = _VSTD::next(__i); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2141 | for (; __j != __e && __binary_pred(*__i, *__j); ++__j) |
| 2142 | ; |
| 2143 | if (++__i != __j) |
| 2144 | __i = erase(__i, __j); |
| 2145 | } |
| 2146 | } |
| 2147 | |
| 2148 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 2149 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2150 | void |
| 2151 | list<_Tp, _Alloc>::merge(list& __c) |
| 2152 | { |
| 2153 | merge(__c, __less<value_type>()); |
| 2154 | } |
| 2155 | |
| 2156 | template <class _Tp, class _Alloc> |
| 2157 | template <class _Comp> |
| 2158 | void |
| 2159 | list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) |
| 2160 | { |
| 2161 | if (this != &__c) |
| 2162 | { |
| 2163 | iterator __f1 = begin(); |
| 2164 | iterator __e1 = end(); |
| 2165 | iterator __f2 = __c.begin(); |
| 2166 | iterator __e2 = __c.end(); |
| 2167 | while (__f1 != __e1 && __f2 != __e2) |
| 2168 | { |
| 2169 | if (__comp(*__f2, *__f1)) |
| 2170 | { |
| 2171 | size_type __ds = 1; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2172 | iterator __m2 = _VSTD::next(__f2); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2173 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) |
| 2174 | ; |
| 2175 | base::__sz() += __ds; |
| 2176 | __c.__sz() -= __ds; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2177 | __link_pointer __f = __f2.__ptr_; |
| 2178 | __link_pointer __l = __m2.__ptr_->__prev_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2179 | __f2 = __m2; |
| 2180 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2181 | __m2 = _VSTD::next(__f1); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2182 | __link_nodes(__f1.__ptr_, __f, __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2183 | __f1 = __m2; |
| 2184 | } |
| 2185 | else |
| 2186 | ++__f1; |
| 2187 | } |
| 2188 | splice(__e1, __c); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2189 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2190 | __libcpp_db* __db = __get_db(); |
| 2191 | __c_node* __cn1 = __db->__find_c_and_lock(this); |
| 2192 | __c_node* __cn2 = __db->__find_c(&__c); |
| 2193 | for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) |
| 2194 | { |
| 2195 | --__p; |
| 2196 | iterator* __i = static_cast<iterator*>((*__p)->__i_); |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 2197 | if (__i->__ptr_ != __c.__end_as_link()) |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2198 | { |
| 2199 | __cn1->__add(*__p); |
| 2200 | (*__p)->__c_ = __cn1; |
| 2201 | if (--__cn2->end_ != __p) |
| 2202 | memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); |
| 2203 | } |
| 2204 | } |
| 2205 | __db->unlock(); |
| 2206 | #endif |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2207 | } |
| 2208 | } |
| 2209 | |
| 2210 | template <class _Tp, class _Alloc> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 2211 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2212 | void |
| 2213 | list<_Tp, _Alloc>::sort() |
| 2214 | { |
| 2215 | sort(__less<value_type>()); |
| 2216 | } |
| 2217 | |
| 2218 | template <class _Tp, class _Alloc> |
| 2219 | template <class _Comp> |
Evgeniy Stepanov | cd31b43 | 2016-04-22 01:04:55 +0000 | [diff] [blame^] | 2220 | inline |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2221 | void |
| 2222 | list<_Tp, _Alloc>::sort(_Comp __comp) |
| 2223 | { |
| 2224 | __sort(begin(), end(), base::__sz(), __comp); |
| 2225 | } |
| 2226 | |
| 2227 | template <class _Tp, class _Alloc> |
| 2228 | template <class _Comp> |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2229 | typename list<_Tp, _Alloc>::iterator |
| 2230 | list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) |
| 2231 | { |
| 2232 | switch (__n) |
| 2233 | { |
| 2234 | case 0: |
| 2235 | case 1: |
| 2236 | return __f1; |
| 2237 | case 2: |
| 2238 | if (__comp(*--__e2, *__f1)) |
| 2239 | { |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2240 | __link_pointer __f = __e2.__ptr_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2241 | base::__unlink_nodes(__f, __f); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2242 | __link_nodes(__f1.__ptr_, __f, __f); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2243 | return __e2; |
| 2244 | } |
| 2245 | return __f1; |
| 2246 | } |
| 2247 | size_type __n2 = __n / 2; |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2248 | iterator __e1 = _VSTD::next(__f1, __n2); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2249 | iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); |
| 2250 | iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); |
| 2251 | if (__comp(*__f2, *__f1)) |
| 2252 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2253 | iterator __m2 = _VSTD::next(__f2); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2254 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) |
| 2255 | ; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2256 | __link_pointer __f = __f2.__ptr_; |
| 2257 | __link_pointer __l = __m2.__ptr_->__prev_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2258 | __r = __f2; |
| 2259 | __e1 = __f2 = __m2; |
| 2260 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2261 | __m2 = _VSTD::next(__f1); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2262 | __link_nodes(__f1.__ptr_, __f, __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2263 | __f1 = __m2; |
| 2264 | } |
| 2265 | else |
| 2266 | ++__f1; |
| 2267 | while (__f1 != __e1 && __f2 != __e2) |
| 2268 | { |
| 2269 | if (__comp(*__f2, *__f1)) |
| 2270 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2271 | iterator __m2 = _VSTD::next(__f2); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2272 | for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) |
| 2273 | ; |
Eric Fiselier | b88ea35 | 2015-12-30 20:57:59 +0000 | [diff] [blame] | 2274 | __link_pointer __f = __f2.__ptr_; |
| 2275 | __link_pointer __l = __m2.__ptr_->__prev_; |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2276 | if (__e1 == __f2) |
| 2277 | __e1 = __m2; |
| 2278 | __f2 = __m2; |
| 2279 | base::__unlink_nodes(__f, __l); |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2280 | __m2 = _VSTD::next(__f1); |
Howard Hinnant | 866d4ef | 2013-06-25 16:08:47 +0000 | [diff] [blame] | 2281 | __link_nodes(__f1.__ptr_, __f, __l); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2282 | __f1 = __m2; |
| 2283 | } |
| 2284 | else |
| 2285 | ++__f1; |
| 2286 | } |
| 2287 | return __r; |
| 2288 | } |
| 2289 | |
| 2290 | template <class _Tp, class _Alloc> |
| 2291 | void |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 2292 | list<_Tp, _Alloc>::reverse() _NOEXCEPT |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2293 | { |
| 2294 | if (base::__sz() > 1) |
| 2295 | { |
| 2296 | iterator __e = end(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2297 | for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) |
| 2298 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2299 | _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2300 | __i.__ptr_ = __i.__ptr_->__prev_; |
| 2301 | } |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2302 | _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2303 | } |
| 2304 | } |
| 2305 | |
| 2306 | template <class _Tp, class _Alloc> |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2307 | bool |
| 2308 | list<_Tp, _Alloc>::__invariants() const |
| 2309 | { |
| 2310 | return size() == _VSTD::distance(begin(), end()); |
| 2311 | } |
| 2312 | |
| 2313 | #if _LIBCPP_DEBUG_LEVEL >= 2 |
| 2314 | |
| 2315 | template <class _Tp, class _Alloc> |
| 2316 | bool |
| 2317 | list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const |
| 2318 | { |
Eric Fiselier | 5243e19 | 2016-01-04 03:27:52 +0000 | [diff] [blame] | 2319 | return __i->__ptr_ != this->__end_as_link(); |
Howard Hinnant | 920b56c | 2011-09-27 23:55:03 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | template <class _Tp, class _Alloc> |
| 2323 | bool |
| 2324 | list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const |
| 2325 | { |
| 2326 | return !empty() && __i->__ptr_ != base::__end_.__next_; |
| 2327 | } |
| 2328 | |
| 2329 | template <class _Tp, class _Alloc> |
| 2330 | bool |
| 2331 | list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const |
| 2332 | { |
| 2333 | return false; |
| 2334 | } |
| 2335 | |
| 2336 | template <class _Tp, class _Alloc> |
| 2337 | bool |
| 2338 | list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const |
| 2339 | { |
| 2340 | return false; |
| 2341 | } |
| 2342 | |
| 2343 | #endif // _LIBCPP_DEBUG_LEVEL >= 2 |
| 2344 | |
| 2345 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2346 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2347 | bool |
| 2348 | operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 2349 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2350 | return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2351 | } |
| 2352 | |
| 2353 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2354 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2355 | bool |
| 2356 | operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 2357 | { |
Howard Hinnant | ce48a11 | 2011-06-30 21:18:19 +0000 | [diff] [blame] | 2358 | return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2359 | } |
| 2360 | |
| 2361 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2362 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2363 | bool |
| 2364 | operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 2365 | { |
| 2366 | return !(__x == __y); |
| 2367 | } |
| 2368 | |
| 2369 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2370 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2371 | bool |
| 2372 | operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 2373 | { |
| 2374 | return __y < __x; |
| 2375 | } |
| 2376 | |
| 2377 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2378 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2379 | bool |
| 2380 | operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 2381 | { |
| 2382 | return !(__x < __y); |
| 2383 | } |
| 2384 | |
| 2385 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2386 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2387 | bool |
| 2388 | operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 2389 | { |
| 2390 | return !(__y < __x); |
| 2391 | } |
| 2392 | |
| 2393 | template <class _Tp, class _Alloc> |
Howard Hinnant | 848a537 | 2010-09-22 16:48:34 +0000 | [diff] [blame] | 2394 | inline _LIBCPP_INLINE_VISIBILITY |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2395 | void |
| 2396 | swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) |
Howard Hinnant | 4590010 | 2011-06-03 17:30:28 +0000 | [diff] [blame] | 2397 | _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) |
Howard Hinnant | 3e51952 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 2398 | { |
| 2399 | __x.swap(__y); |
| 2400 | } |
| 2401 | |
| 2402 | _LIBCPP_END_NAMESPACE_STD |
| 2403 | |
| 2404 | #endif // _LIBCPP_LIST |