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