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