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