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