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