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