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