| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 | |
| 31 | |
| 32 | |
| 33 | |
| 34 | |
| 35 | |
| 36 | |
| 37 | |
| 38 | |
| 39 | |
| 40 | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 | |
| 46 | |
| 47 | |
| 48 | |
| 49 | |
| 50 | |
| 51 | |
| 52 | |
| 53 | |
| 54 | |
| 55 | |
| 56 | #ifndef _STL_LIST_H |
| 57 | #define _STL_LIST_H 1 |
| 58 | |
| 59 | #include <bits/concept_check.h> |
| 60 | #include <ext/alloc_traits.h> |
| 61 | #if __cplusplus >= 201103L |
| 62 | #include <initializer_list> |
| 63 | #include <bits/allocated_ptr.h> |
| 64 | #include <ext/aligned_buffer.h> |
| 65 | #endif |
| 66 | |
| 67 | namespace std _GLIBCXX_VISIBILITY(default) |
| 68 | { |
| 69 | namespace __detail |
| 70 | { |
| 71 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 72 | |
| 73 | |
| 74 | |
| 75 | |
| 76 | |
| 77 | |
| 78 | |
| 79 | |
| 80 | struct _List_node_base |
| 81 | { |
| 82 | _List_node_base* _M_next; |
| 83 | _List_node_base* _M_prev; |
| 84 | |
| 85 | static void |
| 86 | swap(_List_node_base& __x, _List_node_base& __y) _GLIBCXX_USE_NOEXCEPT; |
| 87 | |
| 88 | void |
| 89 | _M_transfer(_List_node_base* const __first, |
| 90 | _List_node_base* const __last) _GLIBCXX_USE_NOEXCEPT; |
| 91 | |
| 92 | void |
| 93 | _M_reverse() _GLIBCXX_USE_NOEXCEPT; |
| 94 | |
| 95 | void |
| 96 | _M_hook(_List_node_base* const __position) _GLIBCXX_USE_NOEXCEPT; |
| 97 | |
| 98 | void |
| 99 | _M_unhook() _GLIBCXX_USE_NOEXCEPT; |
| 100 | }; |
| 101 | |
| 102 | _GLIBCXX_END_NAMESPACE_VERSION |
| 103 | } |
| 104 | |
| 105 | _GLIBCXX_BEGIN_NAMESPACE_CONTAINER |
| 106 | |
| 107 | |
| 108 | template<typename _Tp> |
| 109 | struct _List_node : public __detail::_List_node_base |
| 110 | { |
| 111 | #if __cplusplus >= 201103L |
| 112 | __gnu_cxx::__aligned_membuf<_Tp> _M_storage; |
| 113 | _Tp* _M_valptr() { return _M_storage._M_ptr(); } |
| 114 | _Tp const* _M_valptr() const { return _M_storage._M_ptr(); } |
| 115 | #else |
| 116 | _Tp _M_data; |
| 117 | _Tp* _M_valptr() { return std::__addressof(_M_data); } |
| 118 | _Tp const* _M_valptr() const { return std::__addressof(_M_data); } |
| 119 | #endif |
| 120 | }; |
| 121 | |
| 122 | |
| 123 | |
| 124 | |
| 125 | |
| 126 | |
| 127 | template<typename _Tp> |
| 128 | struct _List_iterator |
| 129 | { |
| 130 | typedef _List_iterator<_Tp> _Self; |
| 131 | typedef _List_node<_Tp> _Node; |
| 132 | |
| 133 | typedef ptrdiff_t difference_type; |
| 134 | typedef std::bidirectional_iterator_tag iterator_category; |
| 135 | typedef _Tp value_type; |
| 136 | typedef _Tp* pointer; |
| 137 | typedef _Tp& reference; |
| 138 | |
| 139 | _List_iterator() _GLIBCXX_NOEXCEPT |
| 140 | : _M_node() { } |
| 141 | |
| 142 | explicit |
| 143 | _List_iterator(__detail::_List_node_base* __x) _GLIBCXX_NOEXCEPT |
| 144 | : _M_node(__x) { } |
| 145 | |
| 146 | _Self |
| 147 | _M_const_cast() const _GLIBCXX_NOEXCEPT |
| 148 | { return *this; } |
| 149 | |
| 150 | |
| 151 | reference |
| 152 | operator*() const _GLIBCXX_NOEXCEPT |
| 153 | { return *static_cast<_Node*>(_M_node)->_M_valptr(); } |
| 154 | |
| 155 | pointer |
| 156 | operator->() const _GLIBCXX_NOEXCEPT |
| 157 | { return static_cast<_Node*>(_M_node)->_M_valptr(); } |
| 158 | |
| 159 | _Self& |
| 160 | operator++() _GLIBCXX_NOEXCEPT |
| 161 | { |
| 162 | _M_node = _M_node->_M_next; |
| 163 | return *this; |
| 164 | } |
| 165 | |
| 166 | _Self |
| 167 | operator++(int) _GLIBCXX_NOEXCEPT |
| 168 | { |
| 169 | _Self __tmp = *this; |
| 170 | _M_node = _M_node->_M_next; |
| 171 | return __tmp; |
| 172 | } |
| 173 | |
| 174 | _Self& |
| 175 | operator--() _GLIBCXX_NOEXCEPT |
| 176 | { |
| 177 | _M_node = _M_node->_M_prev; |
| 178 | return *this; |
| 179 | } |
| 180 | |
| 181 | _Self |
| 182 | operator--(int) _GLIBCXX_NOEXCEPT |
| 183 | { |
| 184 | _Self __tmp = *this; |
| 185 | _M_node = _M_node->_M_prev; |
| 186 | return __tmp; |
| 187 | } |
| 188 | |
| 189 | bool |
| 190 | operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT |
| 191 | { return _M_node == __x._M_node; } |
| 192 | |
| 193 | bool |
| 194 | operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT |
| 195 | { return _M_node != __x._M_node; } |
| 196 | |
| 197 | |
| 198 | __detail::_List_node_base* _M_node; |
| 199 | }; |
| 200 | |
| 201 | |
| 202 | |
| 203 | |
| 204 | |
| 205 | |
| 206 | template<typename _Tp> |
| 207 | struct _List_const_iterator |
| 208 | { |
| 209 | typedef _List_const_iterator<_Tp> _Self; |
| 210 | typedef const _List_node<_Tp> _Node; |
| 211 | typedef _List_iterator<_Tp> iterator; |
| 212 | |
| 213 | typedef ptrdiff_t difference_type; |
| 214 | typedef std::bidirectional_iterator_tag iterator_category; |
| 215 | typedef _Tp value_type; |
| 216 | typedef const _Tp* pointer; |
| 217 | typedef const _Tp& reference; |
| 218 | |
| 219 | _List_const_iterator() _GLIBCXX_NOEXCEPT |
| 220 | : _M_node() { } |
| 221 | |
| 222 | explicit |
| 223 | _List_const_iterator(const __detail::_List_node_base* __x) |
| 224 | _GLIBCXX_NOEXCEPT |
| 225 | : _M_node(__x) { } |
| 226 | |
| 227 | _List_const_iterator(const iterator& __x) _GLIBCXX_NOEXCEPT |
| 228 | : _M_node(__x._M_node) { } |
| 229 | |
| 230 | iterator |
| 231 | _M_const_cast() const _GLIBCXX_NOEXCEPT |
| 232 | { return iterator(const_cast<__detail::_List_node_base*>(_M_node)); } |
| 233 | |
| 234 | |
| 235 | reference |
| 236 | operator*() const _GLIBCXX_NOEXCEPT |
| 237 | { return *static_cast<_Node*>(_M_node)->_M_valptr(); } |
| 238 | |
| 239 | pointer |
| 240 | operator->() const _GLIBCXX_NOEXCEPT |
| 241 | { return static_cast<_Node*>(_M_node)->_M_valptr(); } |
| 242 | |
| 243 | _Self& |
| 244 | operator++() _GLIBCXX_NOEXCEPT |
| 245 | { |
| 246 | _M_node = _M_node->_M_next; |
| 247 | return *this; |
| 248 | } |
| 249 | |
| 250 | _Self |
| 251 | operator++(int) _GLIBCXX_NOEXCEPT |
| 252 | { |
| 253 | _Self __tmp = *this; |
| 254 | _M_node = _M_node->_M_next; |
| 255 | return __tmp; |
| 256 | } |
| 257 | |
| 258 | _Self& |
| 259 | operator--() _GLIBCXX_NOEXCEPT |
| 260 | { |
| 261 | _M_node = _M_node->_M_prev; |
| 262 | return *this; |
| 263 | } |
| 264 | |
| 265 | _Self |
| 266 | operator--(int) _GLIBCXX_NOEXCEPT |
| 267 | { |
| 268 | _Self __tmp = *this; |
| 269 | _M_node = _M_node->_M_prev; |
| 270 | return __tmp; |
| 271 | } |
| 272 | |
| 273 | bool |
| 274 | operator==(const _Self& __x) const _GLIBCXX_NOEXCEPT |
| 275 | { return _M_node == __x._M_node; } |
| 276 | |
| 277 | bool |
| 278 | operator!=(const _Self& __x) const _GLIBCXX_NOEXCEPT |
| 279 | { return _M_node != __x._M_node; } |
| 280 | |
| 281 | |
| 282 | const __detail::_List_node_base* _M_node; |
| 283 | }; |
| 284 | |
| 285 | template<typename _Val> |
| 286 | inline bool |
| 287 | operator==(const _List_iterator<_Val>& __x, |
| 288 | const _List_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT |
| 289 | { return __x._M_node == __y._M_node; } |
| 290 | |
| 291 | template<typename _Val> |
| 292 | inline bool |
| 293 | operator!=(const _List_iterator<_Val>& __x, |
| 294 | const _List_const_iterator<_Val>& __y) _GLIBCXX_NOEXCEPT |
| 295 | { return __x._M_node != __y._M_node; } |
| 296 | |
| 297 | _GLIBCXX_BEGIN_NAMESPACE_CXX11 |
| 298 | |
| 299 | template<typename _Tp, typename _Alloc> |
| 300 | class _List_base |
| 301 | { |
| 302 | protected: |
| 303 | typedef typename __gnu_cxx::__alloc_traits<_Alloc>::template |
| 304 | rebind<_Tp>::other _Tp_alloc_type; |
| 305 | typedef __gnu_cxx::__alloc_traits<_Tp_alloc_type> _Tp_alloc_traits; |
| 306 | typedef typename _Tp_alloc_traits::template |
| 307 | rebind<_List_node<_Tp> >::other _Node_alloc_type; |
| 308 | typedef __gnu_cxx::__alloc_traits<_Node_alloc_type> _Node_alloc_traits; |
| 309 | |
| 310 | static size_t |
| 311 | _S_distance(const __detail::_List_node_base* __first, |
| 312 | const __detail::_List_node_base* __last) |
| 313 | { |
| 314 | size_t __n = 0; |
| 315 | while (__first != __last) |
| 316 | { |
| 317 | __first = __first->_M_next; |
| 318 | ++__n; |
| 319 | } |
| 320 | return __n; |
| 321 | } |
| 322 | |
| 323 | struct _List_impl |
| 324 | : public _Node_alloc_type |
| 325 | { |
| 326 | #if _GLIBCXX_USE_CXX11_ABI |
| 327 | _List_node<size_t> _M_node; |
| 328 | #else |
| 329 | __detail::_List_node_base _M_node; |
| 330 | #endif |
| 331 | |
| 332 | _List_impl() _GLIBCXX_NOEXCEPT |
| 333 | : _Node_alloc_type(), _M_node() |
| 334 | { } |
| 335 | |
| 336 | _List_impl(const _Node_alloc_type& __a) _GLIBCXX_NOEXCEPT |
| 337 | : _Node_alloc_type(__a), _M_node() |
| 338 | { } |
| 339 | |
| 340 | #if __cplusplus >= 201103L |
| 341 | _List_impl(_Node_alloc_type&& __a) noexcept |
| 342 | : _Node_alloc_type(std::move(__a)), _M_node() |
| 343 | { } |
| 344 | #endif |
| 345 | }; |
| 346 | |
| 347 | _List_impl _M_impl; |
| 348 | |
| 349 | #if _GLIBCXX_USE_CXX11_ABI |
| 350 | size_t _M_get_size() const { return *_M_impl._M_node._M_valptr(); } |
| 351 | |
| 352 | void _M_set_size(size_t __n) { *_M_impl._M_node._M_valptr() = __n; } |
| 353 | |
| 354 | void _M_inc_size(size_t __n) { *_M_impl._M_node._M_valptr() += __n; } |
| 355 | |
| 356 | void _M_dec_size(size_t __n) { *_M_impl._M_node._M_valptr() -= __n; } |
| 357 | |
| 358 | size_t |
| 359 | _M_distance(const __detail::_List_node_base* __first, |
| 360 | const __detail::_List_node_base* __last) const |
| 361 | { return _S_distance(__first, __last); } |
| 362 | |
| 363 | |
| 364 | size_t _M_node_count() const { return *_M_impl._M_node._M_valptr(); } |
| 365 | #else |
| 366 | |
| 367 | size_t _M_get_size() const { return 0; } |
| 368 | void _M_set_size(size_t) { } |
| 369 | void _M_inc_size(size_t) { } |
| 370 | void _M_dec_size(size_t) { } |
| 371 | size_t _M_distance(const void*, const void*) const { return 0; } |
| 372 | |
| 373 | |
| 374 | size_t _M_node_count() const |
| 375 | { |
| 376 | return _S_distance(_M_impl._M_node._M_next, |
| 377 | std::__addressof(_M_impl._M_node)); |
| 378 | } |
| 379 | #endif |
| 380 | |
| 381 | typename _Node_alloc_traits::pointer |
| 382 | _M_get_node() |
| 383 | { return _Node_alloc_traits::allocate(_M_impl, 1); } |
| 384 | |
| 385 | void |
| 386 | _M_put_node(typename _Node_alloc_traits::pointer __p) _GLIBCXX_NOEXCEPT |
| 387 | { _Node_alloc_traits::deallocate(_M_impl, __p, 1); } |
| 388 | |
| 389 | public: |
| 390 | typedef _Alloc allocator_type; |
| 391 | |
| 392 | _Node_alloc_type& |
| 393 | _M_get_Node_allocator() _GLIBCXX_NOEXCEPT |
| 394 | { return _M_impl; } |
| 395 | |
| 396 | const _Node_alloc_type& |
| 397 | _M_get_Node_allocator() const _GLIBCXX_NOEXCEPT |
| 398 | { return _M_impl; } |
| 399 | |
| 400 | _List_base() |
| 401 | : _M_impl() |
| 402 | { _M_init(); } |
| 403 | |
| 404 | _List_base(const _Node_alloc_type& __a) _GLIBCXX_NOEXCEPT |
| 405 | : _M_impl(__a) |
| 406 | { _M_init(); } |
| 407 | |
| 408 | #if __cplusplus >= 201103L |
| 409 | _List_base(_List_base&& __x) noexcept |
| 410 | : _M_impl(std::move(__x._M_get_Node_allocator())) |
| 411 | { _M_move_nodes(std::move(__x)); } |
| 412 | |
| 413 | _List_base(_List_base&& __x, _Node_alloc_type&& __a) |
| 414 | : _M_impl(std::move(__a)) |
| 415 | { |
| 416 | if (__x._M_get_Node_allocator() == _M_get_Node_allocator()) |
| 417 | _M_move_nodes(std::move(__x)); |
| 418 | else |
| 419 | _M_init(); |
| 420 | } |
| 421 | |
| 422 | void |
| 423 | _M_move_nodes(_List_base&& __x) |
| 424 | { |
| 425 | auto* const __xnode = std::__addressof(__x._M_impl._M_node); |
| 426 | if (__xnode->_M_next == __xnode) |
| 427 | _M_init(); |
| 428 | else |
| 429 | { |
| 430 | auto* const __node = std::__addressof(_M_impl._M_node); |
| 431 | __node->_M_next = __xnode->_M_next; |
| 432 | __node->_M_prev = __xnode->_M_prev; |
| 433 | __node->_M_next->_M_prev = __node->_M_prev->_M_next = __node; |
| 434 | _M_set_size(__x._M_get_size()); |
| 435 | __x._M_init(); |
| 436 | } |
| 437 | } |
| 438 | #endif |
| 439 | |
| 440 | |
| 441 | ~_List_base() _GLIBCXX_NOEXCEPT |
| 442 | { _M_clear(); } |
| 443 | |
| 444 | void |
| 445 | _M_clear() _GLIBCXX_NOEXCEPT; |
| 446 | |
| 447 | void |
| 448 | _M_init() _GLIBCXX_NOEXCEPT |
| 449 | { |
| 450 | this->_M_impl._M_node._M_next = &this->_M_impl._M_node; |
| 451 | this->_M_impl._M_node._M_prev = &this->_M_impl._M_node; |
| 452 | _M_set_size(0); |
| 453 | } |
| 454 | }; |
| 455 | |
| 456 | |
| 457 | |
| 458 | |
| 459 | |
| 460 | |
| 461 | |
| 462 | |
| 463 | |
| 464 | |
| 465 | |
| 466 | |
| 467 | |
| 468 | |
| 469 | |
| 470 | |
| 471 | |
| 472 | |
| 473 | |
| 474 | |
| 475 | |
| 476 | |
| 477 | |
| 478 | |
| 479 | |
| 480 | |
| 481 | |
| 482 | |
| 483 | |
| 484 | |
| 485 | |
| 486 | |
| 487 | |
| 488 | |
| 489 | |
| 490 | |
| 491 | |
| 492 | |
| 493 | |
| 494 | |
| 495 | |
| 496 | |
| 497 | |
| 498 | |
| 499 | |
| 500 | |
| 501 | |
| 502 | template<typename _Tp, typename _Alloc = std::allocator<_Tp> > |
| 503 | class list : protected _List_base<_Tp, _Alloc> |
| 504 | { |
| 505 | #ifdef _GLIBCXX_CONCEPT_CHECKS |
| 506 | |
| 507 | typedef typename _Alloc::value_type _Alloc_value_type; |
| 508 | # if __cplusplus < 201103L |
| 509 | __glibcxx_class_requires(_Tp, _SGIAssignableConcept) |
| 510 | # endif |
| 511 | __glibcxx_class_requires2(_Tp, _Alloc_value_type, _SameTypeConcept) |
| 512 | #endif |
| 513 | |
| 514 | typedef _List_base<_Tp, _Alloc> _Base; |
| 515 | typedef typename _Base::_Tp_alloc_type _Tp_alloc_type; |
| 516 | typedef typename _Base::_Tp_alloc_traits _Tp_alloc_traits; |
| 517 | typedef typename _Base::_Node_alloc_type _Node_alloc_type; |
| 518 | typedef typename _Base::_Node_alloc_traits _Node_alloc_traits; |
| 519 | |
| 520 | public: |
| 521 | typedef _Tp value_type; |
| 522 | typedef typename _Tp_alloc_traits::pointer pointer; |
| 523 | typedef typename _Tp_alloc_traits::const_pointer const_pointer; |
| 524 | typedef typename _Tp_alloc_traits::reference reference; |
| 525 | typedef typename _Tp_alloc_traits::const_reference const_reference; |
| 526 | typedef _List_iterator<_Tp> iterator; |
| 527 | typedef _List_const_iterator<_Tp> const_iterator; |
| 528 | typedef std::reverse_iterator<const_iterator> const_reverse_iterator; |
| 529 | typedef std::reverse_iterator<iterator> reverse_iterator; |
| 530 | typedef size_t size_type; |
| 531 | typedef ptrdiff_t difference_type; |
| 532 | typedef _Alloc allocator_type; |
| 533 | |
| 534 | protected: |
| 535 | |
| 536 | |
| 537 | typedef _List_node<_Tp> _Node; |
| 538 | |
| 539 | using _Base::_M_impl; |
| 540 | using _Base::_M_put_node; |
| 541 | using _Base::_M_get_node; |
| 542 | using _Base::_M_get_Node_allocator; |
| 543 | |
| 544 | |
| 545 | |
| 546 | |
| 547 | |
| 548 | |
| 549 | |
| 550 | #if __cplusplus < 201103L |
| 551 | _Node* |
| 552 | _M_create_node(const value_type& __x) |
| 553 | { |
| 554 | _Node* __p = this->_M_get_node(); |
| 555 | __try |
| 556 | { |
| 557 | _Tp_alloc_type __alloc(_M_get_Node_allocator()); |
| 558 | __alloc.construct(__p->_M_valptr(), __x); |
| 559 | } |
| 560 | __catch(...) |
| 561 | { |
| 562 | _M_put_node(__p); |
| 563 | __throw_exception_again; |
| 564 | } |
| 565 | return __p; |
| 566 | } |
| 567 | #else |
| 568 | template<typename... _Args> |
| 569 | _Node* |
| 570 | _M_create_node(_Args&&... __args) |
| 571 | { |
| 572 | auto __p = this->_M_get_node(); |
| 573 | auto& __alloc = _M_get_Node_allocator(); |
| 574 | __allocated_ptr<_Node_alloc_type> __guard{__alloc, __p}; |
| 575 | _Node_alloc_traits::construct(__alloc, __p->_M_valptr(), |
| 576 | std::forward<_Args>(__args)...); |
| 577 | __guard = nullptr; |
| 578 | return __p; |
| 579 | } |
| 580 | #endif |
| 581 | |
| 582 | public: |
| 583 | |
| 584 | |
| 585 | |
| 586 | |
| 587 | |
| 588 | |
| 589 | list() |
| 590 | #if __cplusplus >= 201103L |
| 591 | noexcept(is_nothrow_default_constructible<_Node_alloc_type>::value) |
| 592 | #endif |
| 593 | : _Base() { } |
| 594 | |
| 595 | |
| 596 | |
| 597 | |
| 598 | |
| 599 | explicit |
| 600 | list(const allocator_type& __a) _GLIBCXX_NOEXCEPT |
| 601 | : _Base(_Node_alloc_type(__a)) { } |
| 602 | |
| 603 | #if __cplusplus >= 201103L |
| 604 | |
| 605 | |
| 606 | |
| 607 | |
| 608 | |
| 609 | |
| 610 | |
| 611 | |
| 612 | explicit |
| 613 | list(size_type __n, const allocator_type& __a = allocator_type()) |
| 614 | : _Base(_Node_alloc_type(__a)) |
| 615 | { _M_default_initialize(__n); } |
| 616 | |
| 617 | |
| 618 | |
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | |
| 624 | |
| 625 | list(size_type __n, const value_type& __value, |
| 626 | const allocator_type& __a = allocator_type()) |
| 627 | : _Base(_Node_alloc_type(__a)) |
| 628 | { _M_fill_initialize(__n, __value); } |
| 629 | #else |
| 630 | |
| 631 | |
| 632 | |
| 633 | |
| 634 | |
| 635 | |
| 636 | |
| 637 | |
| 638 | explicit |
| 639 | list(size_type __n, const value_type& __value = value_type(), |
| 640 | const allocator_type& __a = allocator_type()) |
| 641 | : _Base(_Node_alloc_type(__a)) |
| 642 | { _M_fill_initialize(__n, __value); } |
| 643 | #endif |
| 644 | |
| 645 | |
| 646 | |
| 647 | |
| 648 | |
| 649 | |
| 650 | |
| 651 | |
| 652 | list(const list& __x) |
| 653 | : _Base(_Node_alloc_traits:: |
| 654 | _S_select_on_copy(__x._M_get_Node_allocator())) |
| 655 | { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); } |
| 656 | |
| 657 | #if __cplusplus >= 201103L |
| 658 | |
| 659 | |
| 660 | |
| 661 | |
| 662 | |
| 663 | |
| 664 | |
| 665 | list(list&& __x) noexcept |
| 666 | : _Base(std::move(__x)) { } |
| 667 | |
| 668 | |
| 669 | |
| 670 | |
| 671 | |
| 672 | |
| 673 | |
| 674 | |
| 675 | |
| 676 | list(initializer_list<value_type> __l, |
| 677 | const allocator_type& __a = allocator_type()) |
| 678 | : _Base(_Node_alloc_type(__a)) |
| 679 | { _M_initialize_dispatch(__l.begin(), __l.end(), __false_type()); } |
| 680 | |
| 681 | list(const list& __x, const allocator_type& __a) |
| 682 | : _Base(_Node_alloc_type(__a)) |
| 683 | { _M_initialize_dispatch(__x.begin(), __x.end(), __false_type()); } |
| 684 | |
| 685 | list(list&& __x, const allocator_type& __a) |
| 686 | noexcept(_Node_alloc_traits::_S_always_equal()) |
| 687 | : _Base(std::move(__x), _Node_alloc_type(__a)) |
| 688 | { |
| 689 | |
| 690 | |
| 691 | insert(begin(), std::__make_move_if_noexcept_iterator(__x.begin()), |
| 692 | std::__make_move_if_noexcept_iterator(__x.end())); |
| 693 | } |
| 694 | #endif |
| 695 | |
| 696 | |
| 697 | |
| 698 | |
| 699 | |
| 700 | |
| 701 | |
| 702 | |
| 703 | |
| 704 | |
| 705 | |
| 706 | #if __cplusplus >= 201103L |
| 707 | template<typename _InputIterator, |
| 708 | typename = std::_RequireInputIter<_InputIterator>> |
| 709 | list(_InputIterator __first, _InputIterator __last, |
| 710 | const allocator_type& __a = allocator_type()) |
| 711 | : _Base(_Node_alloc_type(__a)) |
| 712 | { _M_initialize_dispatch(__first, __last, __false_type()); } |
| 713 | #else |
| 714 | template<typename _InputIterator> |
| 715 | list(_InputIterator __first, _InputIterator __last, |
| 716 | const allocator_type& __a = allocator_type()) |
| 717 | : _Base(_Node_alloc_type(__a)) |
| 718 | { |
| 719 | |
| 720 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 721 | _M_initialize_dispatch(__first, __last, _Integral()); |
| 722 | } |
| 723 | #endif |
| 724 | |
| 725 | #if __cplusplus >= 201103L |
| 726 | |
| 727 | |
| 728 | |
| 729 | |
| 730 | |
| 731 | |
| 732 | |
| 733 | ~list() = default; |
| 734 | #endif |
| 735 | |
| 736 | |
| 737 | |
| 738 | |
| 739 | |
| 740 | |
| 741 | |
| 742 | |
| 743 | |
| 744 | list& |
| 745 | operator=(const list& __x); |
| 746 | |
| 747 | #if __cplusplus >= 201103L |
| 748 | |
| 749 | |
| 750 | |
| 751 | |
| 752 | |
| 753 | |
| 754 | |
| 755 | |
| 756 | |
| 757 | |
| 758 | list& |
| 759 | operator=(list&& __x) |
| 760 | noexcept(_Node_alloc_traits::_S_nothrow_move()) |
| 761 | { |
| 762 | constexpr bool __move_storage = |
| 763 | _Node_alloc_traits::_S_propagate_on_move_assign() |
| 764 | || _Node_alloc_traits::_S_always_equal(); |
| 765 | _M_move_assign(std::move(__x), __bool_constant<__move_storage>()); |
| 766 | return *this; |
| 767 | } |
| 768 | |
| 769 | |
| 770 | |
| 771 | |
| 772 | |
| 773 | |
| 774 | |
| 775 | |
| 776 | list& |
| 777 | operator=(initializer_list<value_type> __l) |
| 778 | { |
| 779 | this->assign(__l.begin(), __l.end()); |
| 780 | return *this; |
| 781 | } |
| 782 | #endif |
| 783 | |
| 784 | |
| 785 | |
| 786 | |
| 787 | |
| 788 | |
| 789 | |
| 790 | |
| 791 | |
| 792 | |
| 793 | |
| 794 | void |
| 795 | assign(size_type __n, const value_type& __val) |
| 796 | { _M_fill_assign(__n, __val); } |
| 797 | |
| 798 | |
| 799 | |
| 800 | |
| 801 | |
| 802 | |
| 803 | |
| 804 | |
| 805 | |
| 806 | |
| 807 | |
| 808 | |
| 809 | |
| 810 | #if __cplusplus >= 201103L |
| 811 | template<typename _InputIterator, |
| 812 | typename = std::_RequireInputIter<_InputIterator>> |
| 813 | void |
| 814 | assign(_InputIterator __first, _InputIterator __last) |
| 815 | { _M_assign_dispatch(__first, __last, __false_type()); } |
| 816 | #else |
| 817 | template<typename _InputIterator> |
| 818 | void |
| 819 | assign(_InputIterator __first, _InputIterator __last) |
| 820 | { |
| 821 | |
| 822 | typedef typename std::__is_integer<_InputIterator>::__type _Integral; |
| 823 | _M_assign_dispatch(__first, __last, _Integral()); |
| 824 | } |
| 825 | #endif |
| 826 | |
| 827 | #if __cplusplus >= 201103L |
| 828 | |
| 829 | |
| 830 | |
| 831 | |
| 832 | |
| 833 | |
| 834 | |
| 835 | void |
| 836 | assign(initializer_list<value_type> __l) |
| 837 | { this->_M_assign_dispatch(__l.begin(), __l.end(), __false_type()); } |
| 838 | #endif |
| 839 | |
| 840 | |
| 841 | allocator_type |
| 842 | get_allocator() const _GLIBCXX_NOEXCEPT |
| 843 | { return allocator_type(_Base::_M_get_Node_allocator()); } |
| 844 | |
| 845 | |
| 846 | |
| 847 | |
| 848 | |
| 849 | |
| 850 | iterator |
| 851 | begin() _GLIBCXX_NOEXCEPT |
| 852 | { return iterator(this->_M_impl._M_node._M_next); } |
| 853 | |
| 854 | |
| 855 | |
| 856 | |
| 857 | |
| 858 | |
| 859 | const_iterator |
| 860 | begin() const _GLIBCXX_NOEXCEPT |
| 861 | { return const_iterator(this->_M_impl._M_node._M_next); } |
| 862 | |
| 863 | |
| 864 | |
| 865 | |
| 866 | |
| 867 | |
| 868 | iterator |
| 869 | end() _GLIBCXX_NOEXCEPT |
| 870 | { return iterator(&this->_M_impl._M_node); } |
| 871 | |
| 872 | |
| 873 | |
| 874 | |
| 875 | |
| 876 | |
| 877 | const_iterator |
| 878 | end() const _GLIBCXX_NOEXCEPT |
| 879 | { return const_iterator(&this->_M_impl._M_node); } |
| 880 | |
| 881 | |
| 882 | |
| 883 | |
| 884 | |
| 885 | |
| 886 | reverse_iterator |
| 887 | rbegin() _GLIBCXX_NOEXCEPT |
| 888 | { return reverse_iterator(end()); } |
| 889 | |
| 890 | |
| 891 | |
| 892 | |
| 893 | |
| 894 | |
| 895 | const_reverse_iterator |
| 896 | rbegin() const _GLIBCXX_NOEXCEPT |
| 897 | { return const_reverse_iterator(end()); } |
| 898 | |
| 899 | |
| 900 | |
| 901 | |
| 902 | |
| 903 | |
| 904 | reverse_iterator |
| 905 | rend() _GLIBCXX_NOEXCEPT |
| 906 | { return reverse_iterator(begin()); } |
| 907 | |
| 908 | |
| 909 | |
| 910 | |
| 911 | |
| 912 | |
| 913 | const_reverse_iterator |
| 914 | rend() const _GLIBCXX_NOEXCEPT |
| 915 | { return const_reverse_iterator(begin()); } |
| 916 | |
| 917 | #if __cplusplus >= 201103L |
| 918 | |
| 919 | |
| 920 | |
| 921 | |
| 922 | |
| 923 | const_iterator |
| 924 | cbegin() const noexcept |
| 925 | { return const_iterator(this->_M_impl._M_node._M_next); } |
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | |
| 931 | |
| 932 | const_iterator |
| 933 | cend() const noexcept |
| 934 | { return const_iterator(&this->_M_impl._M_node); } |
| 935 | |
| 936 | |
| 937 | |
| 938 | |
| 939 | |
| 940 | |
| 941 | const_reverse_iterator |
| 942 | crbegin() const noexcept |
| 943 | { return const_reverse_iterator(end()); } |
| 944 | |
| 945 | |
| 946 | |
| 947 | |
| 948 | |
| 949 | |
| 950 | const_reverse_iterator |
| 951 | crend() const noexcept |
| 952 | { return const_reverse_iterator(begin()); } |
| 953 | #endif |
| 954 | |
| 955 | |
| 956 | |
| 957 | |
| 958 | |
| 959 | |
| 960 | bool |
| 961 | empty() const _GLIBCXX_NOEXCEPT |
| 962 | { return this->_M_impl._M_node._M_next == &this->_M_impl._M_node; } |
| 963 | |
| 964 | |
| 965 | size_type |
| 966 | size() const _GLIBCXX_NOEXCEPT |
| 967 | { return this->_M_node_count(); } |
| 968 | |
| 969 | |
| 970 | size_type |
| 971 | max_size() const _GLIBCXX_NOEXCEPT |
| 972 | { return _Node_alloc_traits::max_size(_M_get_Node_allocator()); } |
| 973 | |
| 974 | #if __cplusplus >= 201103L |
| 975 | |
| 976 | |
| 977 | |
| 978 | |
| 979 | |
| 980 | |
| 981 | |
| 982 | |
| 983 | |
| 984 | void |
| 985 | resize(size_type __new_size); |
| 986 | |
| 987 | |
| 988 | |
| 989 | |
| 990 | |
| 991 | |
| 992 | |
| 993 | |
| 994 | |
| 995 | |
| 996 | |
| 997 | void |
| 998 | resize(size_type __new_size, const value_type& __x); |
| 999 | #else |
| 1000 | |
| 1001 | |
| 1002 | |
| 1003 | |
| 1004 | |
| 1005 | |
| 1006 | |
| 1007 | |
| 1008 | |
| 1009 | |
| 1010 | void |
| 1011 | resize(size_type __new_size, value_type __x = value_type()); |
| 1012 | #endif |
| 1013 | |
| 1014 | |
| 1015 | |
| 1016 | |
| 1017 | |
| 1018 | |
| 1019 | reference |
| 1020 | front() _GLIBCXX_NOEXCEPT |
| 1021 | { return *begin(); } |
| 1022 | |
| 1023 | |
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | const_reference |
| 1028 | front() const _GLIBCXX_NOEXCEPT |
| 1029 | { return *begin(); } |
| 1030 | |
| 1031 | |
| 1032 | |
| 1033 | |
| 1034 | |
| 1035 | reference |
| 1036 | back() _GLIBCXX_NOEXCEPT |
| 1037 | { |
| 1038 | iterator __tmp = end(); |
| 1039 | --__tmp; |
| 1040 | return *__tmp; |
| 1041 | } |
| 1042 | |
| 1043 | |
| 1044 | |
| 1045 | |
| 1046 | |
| 1047 | const_reference |
| 1048 | back() const _GLIBCXX_NOEXCEPT |
| 1049 | { |
| 1050 | const_iterator __tmp = end(); |
| 1051 | --__tmp; |
| 1052 | return *__tmp; |
| 1053 | } |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | |
| 1058 | |
| 1059 | |
| 1060 | |
| 1061 | |
| 1062 | |
| 1063 | |
| 1064 | |
| 1065 | |
| 1066 | void |
| 1067 | push_front(const value_type& __x) |
| 1068 | { this->_M_insert(begin(), __x); } |
| 1069 | |
| 1070 | #if __cplusplus >= 201103L |
| 1071 | void |
| 1072 | push_front(value_type&& __x) |
| 1073 | { this->_M_insert(begin(), std::move(__x)); } |
| 1074 | |
| 1075 | template<typename... _Args> |
| 1076 | #if __cplusplus > 201402L |
| 1077 | reference |
| 1078 | #else |
| 1079 | void |
| 1080 | #endif |
| 1081 | emplace_front(_Args&&... __args) |
| 1082 | { |
| 1083 | this->_M_insert(begin(), std::forward<_Args>(__args)...); |
| 1084 | #if __cplusplus > 201402L |
| 1085 | return front(); |
| 1086 | #endif |
| 1087 | } |
| 1088 | #endif |
| 1089 | |
| 1090 | |
| 1091 | |
| 1092 | |
| 1093 | |
| 1094 | |
| 1095 | |
| 1096 | |
| 1097 | |
| 1098 | |
| 1099 | |
| 1100 | |
| 1101 | |
| 1102 | void |
| 1103 | pop_front() _GLIBCXX_NOEXCEPT |
| 1104 | { this->_M_erase(begin()); } |
| 1105 | |
| 1106 | |
| 1107 | |
| 1108 | |
| 1109 | |
| 1110 | |
| 1111 | |
| 1112 | |
| 1113 | |
| 1114 | |
| 1115 | |
| 1116 | void |
| 1117 | push_back(const value_type& __x) |
| 1118 | { this->_M_insert(end(), __x); } |
| 1119 | |
| 1120 | #if __cplusplus >= 201103L |
| 1121 | void |
| 1122 | push_back(value_type&& __x) |
| 1123 | { this->_M_insert(end(), std::move(__x)); } |
| 1124 | |
| 1125 | template<typename... _Args> |
| 1126 | #if __cplusplus > 201402L |
| 1127 | reference |
| 1128 | #else |
| 1129 | void |
| 1130 | #endif |
| 1131 | emplace_back(_Args&&... __args) |
| 1132 | { |
| 1133 | this->_M_insert(end(), std::forward<_Args>(__args)...); |
| 1134 | #if __cplusplus > 201402L |
| 1135 | return back(); |
| 1136 | #endif |
| 1137 | } |
| 1138 | #endif |
| 1139 | |
| 1140 | |
| 1141 | |
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 | |
| 1146 | |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | |
| 1151 | void |
| 1152 | pop_back() _GLIBCXX_NOEXCEPT |
| 1153 | { this->_M_erase(iterator(this->_M_impl._M_node._M_prev)); } |
| 1154 | |
| 1155 | #if __cplusplus >= 201103L |
| 1156 | |
| 1157 | |
| 1158 | |
| 1159 | |
| 1160 | |
| 1161 | |
| 1162 | |
| 1163 | |
| 1164 | |
| 1165 | |
| 1166 | |
| 1167 | |
| 1168 | template<typename... _Args> |
| 1169 | iterator |
| 1170 | emplace(const_iterator __position, _Args&&... __args); |
| 1171 | |
| 1172 | |
| 1173 | |
| 1174 | |
| 1175 | |
| 1176 | |
| 1177 | |
| 1178 | |
| 1179 | |
| 1180 | |
| 1181 | |
| 1182 | |
| 1183 | iterator |
| 1184 | insert(const_iterator __position, const value_type& __x); |
| 1185 | #else |
| 1186 | |
| 1187 | |
| 1188 | |
| 1189 | |
| 1190 | |
| 1191 | |
| 1192 | |
| 1193 | |
| 1194 | |
| 1195 | |
| 1196 | |
| 1197 | iterator |
| 1198 | insert(iterator __position, const value_type& __x); |
| 1199 | #endif |
| 1200 | |
| 1201 | #if __cplusplus >= 201103L |
| 1202 | |
| 1203 | |
| 1204 | |
| 1205 | |
| 1206 | |
| 1207 | |
| 1208 | |
| 1209 | |
| 1210 | |
| 1211 | |
| 1212 | |
| 1213 | iterator |
| 1214 | insert(const_iterator __position, value_type&& __x) |
| 1215 | { return emplace(__position, std::move(__x)); } |
| 1216 | |
| 1217 | |
| 1218 | |
| 1219 | |
| 1220 | |
| 1221 | |
| 1222 | |
| 1223 | |
| 1224 | |
| 1225 | |
| 1226 | |
| 1227 | |
| 1228 | |
| 1229 | |
| 1230 | |
| 1231 | |
| 1232 | iterator |
| 1233 | insert(const_iterator __p, initializer_list<value_type> __l) |
| 1234 | { return this->insert(__p, __l.begin(), __l.end()); } |
| 1235 | #endif |
| 1236 | |
| 1237 | #if __cplusplus >= 201103L |
| 1238 | |
| 1239 | |
| 1240 | |
| 1241 | |
| 1242 | |
| 1243 | |
| 1244 | |
| 1245 | |
| 1246 | |
| 1247 | |
| 1248 | |
| 1249 | |
| 1250 | |
| 1251 | |
| 1252 | iterator |
| 1253 | insert(const_iterator __position, size_type __n, const value_type& __x); |
| 1254 | #else |
| 1255 | |
| 1256 | |
| 1257 | |
| 1258 | |
| 1259 | |
| 1260 | |
| 1261 | |
| 1262 | |
| 1263 | |
| 1264 | |
| 1265 | |
| 1266 | |
| 1267 | void |
| 1268 | insert(iterator __position, size_type __n, const value_type& __x) |
| 1269 | { |
| 1270 | list __tmp(__n, __x, get_allocator()); |
| 1271 | splice(__position, __tmp); |
| 1272 | } |
| 1273 | #endif |
| 1274 | |
| 1275 | #if __cplusplus >= 201103L |
| 1276 | |
| 1277 | |
| 1278 | |
| 1279 | |
| 1280 | |
| 1281 | |
| 1282 | |
| 1283 | |
| 1284 | |
| 1285 | |
| 1286 | |
| 1287 | |
| 1288 | |
| 1289 | |
| 1290 | |
| 1291 | template<typename _InputIterator, |
| 1292 | typename = std::_RequireInputIter<_InputIterator>> |
| 1293 | iterator |
| 1294 | insert(const_iterator __position, _InputIterator __first, |
| 1295 | _InputIterator __last); |
| 1296 | #else |
| 1297 | |
| 1298 | |
| 1299 | |
| 1300 | |
| 1301 | |
| 1302 | |
| 1303 | |
| 1304 | |
| 1305 | |
| 1306 | |
| 1307 | |
| 1308 | |
| 1309 | |
| 1310 | template<typename _InputIterator> |
| 1311 | void |
| 1312 | insert(iterator __position, _InputIterator __first, |
| 1313 | _InputIterator __last) |
| 1314 | { |
| 1315 | list __tmp(__first, __last, get_allocator()); |
| 1316 | splice(__position, __tmp); |
| 1317 | } |
| 1318 | #endif |
| 1319 | |
| 1320 | |
| 1321 | |
| 1322 | |
| 1323 | |
| 1324 | |
| 1325 | |
| 1326 | |
| 1327 | |
| 1328 | |
| 1329 | |
| 1330 | |
| 1331 | |
| 1332 | |
| 1333 | |
| 1334 | |
| 1335 | iterator |
| 1336 | #if __cplusplus >= 201103L |
| 1337 | erase(const_iterator __position) noexcept; |
| 1338 | #else |
| 1339 | erase(iterator __position); |
| 1340 | #endif |
| 1341 | |
| 1342 | |
| 1343 | |
| 1344 | |
| 1345 | |
| 1346 | |
| 1347 | |
| 1348 | |
| 1349 | |
| 1350 | |
| 1351 | |
| 1352 | |
| 1353 | |
| 1354 | |
| 1355 | |
| 1356 | |
| 1357 | |
| 1358 | |
| 1359 | |
| 1360 | iterator |
| 1361 | #if __cplusplus >= 201103L |
| 1362 | erase(const_iterator __first, const_iterator __last) noexcept |
| 1363 | #else |
| 1364 | erase(iterator __first, iterator __last) |
| 1365 | #endif |
| 1366 | { |
| 1367 | while (__first != __last) |
| 1368 | __first = erase(__first); |
| 1369 | return __last._M_const_cast(); |
| 1370 | } |
| 1371 | |
| 1372 | |
| 1373 | |
| 1374 | |
| 1375 | |
| 1376 | |
| 1377 | |
| 1378 | |
| 1379 | |
| 1380 | |
| 1381 | |
| 1382 | |
| 1383 | void |
| 1384 | swap(list& __x) _GLIBCXX_NOEXCEPT |
| 1385 | { |
| 1386 | __detail::_List_node_base::swap(this->_M_impl._M_node, |
| 1387 | __x._M_impl._M_node); |
| 1388 | |
| 1389 | size_t __xsize = __x._M_get_size(); |
| 1390 | __x._M_set_size(this->_M_get_size()); |
| 1391 | this->_M_set_size(__xsize); |
| 1392 | |
| 1393 | _Node_alloc_traits::_S_on_swap(this->_M_get_Node_allocator(), |
| 1394 | __x._M_get_Node_allocator()); |
| 1395 | } |
| 1396 | |
| 1397 | |
| 1398 | |
| 1399 | |
| 1400 | |
| 1401 | |
| 1402 | |
| 1403 | void |
| 1404 | clear() _GLIBCXX_NOEXCEPT |
| 1405 | { |
| 1406 | _Base::_M_clear(); |
| 1407 | _Base::_M_init(); |
| 1408 | } |
| 1409 | |
| 1410 | |
| 1411 | |
| 1412 | |
| 1413 | |
| 1414 | |
| 1415 | |
| 1416 | |
| 1417 | |
| 1418 | |
| 1419 | |
| 1420 | |
| 1421 | |
| 1422 | void |
| 1423 | #if __cplusplus >= 201103L |
| 1424 | splice(const_iterator __position, list&& __x) noexcept |
| 1425 | #else |
| 1426 | splice(iterator __position, list& __x) |
| 1427 | #endif |
| 1428 | { |
| 1429 | if (!__x.empty()) |
| 1430 | { |
| 1431 | _M_check_equal_allocators(__x); |
| 1432 | |
| 1433 | this->_M_transfer(__position._M_const_cast(), |
| 1434 | __x.begin(), __x.end()); |
| 1435 | |
| 1436 | this->_M_inc_size(__x._M_get_size()); |
| 1437 | __x._M_set_size(0); |
| 1438 | } |
| 1439 | } |
| 1440 | |
| 1441 | #if __cplusplus >= 201103L |
| 1442 | void |
| 1443 | splice(const_iterator __position, list& __x) noexcept |
| 1444 | { splice(__position, std::move(__x)); } |
| 1445 | #endif |
| 1446 | |
| 1447 | #if __cplusplus >= 201103L |
| 1448 | |
| 1449 | |
| 1450 | |
| 1451 | |
| 1452 | |
| 1453 | |
| 1454 | |
| 1455 | |
| 1456 | |
| 1457 | |
| 1458 | void |
| 1459 | splice(const_iterator __position, list&& __x, const_iterator __i) noexcept |
| 1460 | #else |
| 1461 | |
| 1462 | |
| 1463 | |
| 1464 | |
| 1465 | |
| 1466 | |
| 1467 | |
| 1468 | |
| 1469 | |
| 1470 | void |
| 1471 | splice(iterator __position, list& __x, iterator __i) |
| 1472 | #endif |
| 1473 | { |
| 1474 | iterator __j = __i._M_const_cast(); |
| 1475 | ++__j; |
| 1476 | if (__position == __i || __position == __j) |
| 1477 | return; |
| 1478 | |
| 1479 | if (this != std::__addressof(__x)) |
| 1480 | _M_check_equal_allocators(__x); |
| 1481 | |
| 1482 | this->_M_transfer(__position._M_const_cast(), |
| 1483 | __i._M_const_cast(), __j); |
| 1484 | |
| 1485 | this->_M_inc_size(1); |
| 1486 | __x._M_dec_size(1); |
| 1487 | } |
| 1488 | |
| 1489 | #if __cplusplus >= 201103L |
| 1490 | |
| 1491 | |
| 1492 | |
| 1493 | |
| 1494 | |
| 1495 | |
| 1496 | |
| 1497 | |
| 1498 | |
| 1499 | |
| 1500 | void |
| 1501 | splice(const_iterator __position, list& __x, const_iterator __i) noexcept |
| 1502 | { splice(__position, std::move(__x), __i); } |
| 1503 | #endif |
| 1504 | |
| 1505 | #if __cplusplus >= 201103L |
| 1506 | |
| 1507 | |
| 1508 | |
| 1509 | |
| 1510 | |
| 1511 | |
| 1512 | |
| 1513 | |
| 1514 | |
| 1515 | |
| 1516 | |
| 1517 | |
| 1518 | |
| 1519 | void |
| 1520 | splice(const_iterator __position, list&& __x, const_iterator __first, |
| 1521 | const_iterator __last) noexcept |
| 1522 | #else |
| 1523 | |
| 1524 | |
| 1525 | |
| 1526 | |
| 1527 | |
| 1528 | |
| 1529 | |
| 1530 | |
| 1531 | |
| 1532 | |
| 1533 | |
| 1534 | |
| 1535 | void |
| 1536 | splice(iterator __position, list& __x, iterator __first, |
| 1537 | iterator __last) |
| 1538 | #endif |
| 1539 | { |
| 1540 | if (__first != __last) |
| 1541 | { |
| 1542 | if (this != std::__addressof(__x)) |
| 1543 | _M_check_equal_allocators(__x); |
| 1544 | |
| 1545 | size_t __n = this->_M_distance(__first._M_node, __last._M_node); |
| 1546 | this->_M_inc_size(__n); |
| 1547 | __x._M_dec_size(__n); |
| 1548 | |
| 1549 | this->_M_transfer(__position._M_const_cast(), |
| 1550 | __first._M_const_cast(), |
| 1551 | __last._M_const_cast()); |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | #if __cplusplus >= 201103L |
| 1556 | |
| 1557 | |
| 1558 | |
| 1559 | |
| 1560 | |
| 1561 | |
| 1562 | |
| 1563 | |
| 1564 | |
| 1565 | |
| 1566 | |
| 1567 | |
| 1568 | |
| 1569 | void |
| 1570 | splice(const_iterator __position, list& __x, const_iterator __first, |
| 1571 | const_iterator __last) noexcept |
| 1572 | { splice(__position, std::move(__x), __first, __last); } |
| 1573 | #endif |
| 1574 | |
| 1575 | |
| 1576 | |
| 1577 | |
| 1578 | |
| 1579 | |
| 1580 | |
| 1581 | |
| 1582 | |
| 1583 | |
| 1584 | |
| 1585 | |
| 1586 | void |
| 1587 | remove(const _Tp& __value); |
| 1588 | |
| 1589 | |
| 1590 | |
| 1591 | |
| 1592 | |
| 1593 | |
| 1594 | |
| 1595 | |
| 1596 | |
| 1597 | |
| 1598 | |
| 1599 | |
| 1600 | template<typename _Predicate> |
| 1601 | void |
| 1602 | remove_if(_Predicate); |
| 1603 | |
| 1604 | |
| 1605 | |
| 1606 | |
| 1607 | |
| 1608 | |
| 1609 | |
| 1610 | |
| 1611 | |
| 1612 | |
| 1613 | |
| 1614 | void |
| 1615 | unique(); |
| 1616 | |
| 1617 | |
| 1618 | |
| 1619 | |
| 1620 | |
| 1621 | |
| 1622 | |
| 1623 | |
| 1624 | |
| 1625 | |
| 1626 | |
| 1627 | |
| 1628 | |
| 1629 | template<typename _BinaryPredicate> |
| 1630 | void |
| 1631 | unique(_BinaryPredicate); |
| 1632 | |
| 1633 | |
| 1634 | |
| 1635 | |
| 1636 | |
| 1637 | |
| 1638 | |
| 1639 | |
| 1640 | |
| 1641 | |
| 1642 | #if __cplusplus >= 201103L |
| 1643 | void |
| 1644 | merge(list&& __x); |
| 1645 | |
| 1646 | void |
| 1647 | merge(list& __x) |
| 1648 | { merge(std::move(__x)); } |
| 1649 | #else |
| 1650 | void |
| 1651 | merge(list& __x); |
| 1652 | #endif |
| 1653 | |
| 1654 | |
| 1655 | |
| 1656 | |
| 1657 | |
| 1658 | |
| 1659 | |
| 1660 | |
| 1661 | |
| 1662 | |
| 1663 | |
| 1664 | |
| 1665 | |
| 1666 | |
| 1667 | #if __cplusplus >= 201103L |
| 1668 | template<typename _StrictWeakOrdering> |
| 1669 | void |
| 1670 | merge(list&& __x, _StrictWeakOrdering __comp); |
| 1671 | |
| 1672 | template<typename _StrictWeakOrdering> |
| 1673 | void |
| 1674 | merge(list& __x, _StrictWeakOrdering __comp) |
| 1675 | { merge(std::move(__x), __comp); } |
| 1676 | #else |
| 1677 | template<typename _StrictWeakOrdering> |
| 1678 | void |
| 1679 | merge(list& __x, _StrictWeakOrdering __comp); |
| 1680 | #endif |
| 1681 | |
| 1682 | |
| 1683 | |
| 1684 | |
| 1685 | |
| 1686 | |
| 1687 | void |
| 1688 | reverse() _GLIBCXX_NOEXCEPT |
| 1689 | { this->_M_impl._M_node._M_reverse(); } |
| 1690 | |
| 1691 | |
| 1692 | |
| 1693 | |
| 1694 | |
| 1695 | |
| 1696 | |
| 1697 | void |
| 1698 | sort(); |
| 1699 | |
| 1700 | |
| 1701 | |
| 1702 | |
| 1703 | |
| 1704 | |
| 1705 | |
| 1706 | template<typename _StrictWeakOrdering> |
| 1707 | void |
| 1708 | sort(_StrictWeakOrdering); |
| 1709 | |
| 1710 | protected: |
| 1711 | |
| 1712 | |
| 1713 | |
| 1714 | |
| 1715 | |
| 1716 | |
| 1717 | template<typename _Integer> |
| 1718 | void |
| 1719 | _M_initialize_dispatch(_Integer __n, _Integer __x, __true_type) |
| 1720 | { _M_fill_initialize(static_cast<size_type>(__n), __x); } |
| 1721 | |
| 1722 | |
| 1723 | template<typename _InputIterator> |
| 1724 | void |
| 1725 | _M_initialize_dispatch(_InputIterator __first, _InputIterator __last, |
| 1726 | __false_type) |
| 1727 | { |
| 1728 | for (; __first != __last; ++__first) |
| 1729 | #if __cplusplus >= 201103L |
| 1730 | emplace_back(*__first); |
| 1731 | #else |
| 1732 | push_back(*__first); |
| 1733 | #endif |
| 1734 | } |
| 1735 | |
| 1736 | |
| 1737 | |
| 1738 | void |
| 1739 | _M_fill_initialize(size_type __n, const value_type& __x) |
| 1740 | { |
| 1741 | for (; __n; --__n) |
| 1742 | push_back(__x); |
| 1743 | } |
| 1744 | |
| 1745 | #if __cplusplus >= 201103L |
| 1746 | |
| 1747 | void |
| 1748 | _M_default_initialize(size_type __n) |
| 1749 | { |
| 1750 | for (; __n; --__n) |
| 1751 | emplace_back(); |
| 1752 | } |
| 1753 | |
| 1754 | |
| 1755 | void |
| 1756 | _M_default_append(size_type __n); |
| 1757 | #endif |
| 1758 | |
| 1759 | |
| 1760 | |
| 1761 | |
| 1762 | |
| 1763 | |
| 1764 | |
| 1765 | template<typename _Integer> |
| 1766 | void |
| 1767 | _M_assign_dispatch(_Integer __n, _Integer __val, __true_type) |
| 1768 | { _M_fill_assign(__n, __val); } |
| 1769 | |
| 1770 | |
| 1771 | template<typename _InputIterator> |
| 1772 | void |
| 1773 | _M_assign_dispatch(_InputIterator __first, _InputIterator __last, |
| 1774 | __false_type); |
| 1775 | |
| 1776 | |
| 1777 | |
| 1778 | void |
| 1779 | _M_fill_assign(size_type __n, const value_type& __val); |
| 1780 | |
| 1781 | |
| 1782 | |
| 1783 | void |
| 1784 | _M_transfer(iterator __position, iterator __first, iterator __last) |
| 1785 | { __position._M_node->_M_transfer(__first._M_node, __last._M_node); } |
| 1786 | |
| 1787 | |
| 1788 | #if __cplusplus < 201103L |
| 1789 | void |
| 1790 | _M_insert(iterator __position, const value_type& __x) |
| 1791 | { |
| 1792 | _Node* __tmp = _M_create_node(__x); |
| 1793 | __tmp->_M_hook(__position._M_node); |
| 1794 | this->_M_inc_size(1); |
| 1795 | } |
| 1796 | #else |
| 1797 | template<typename... _Args> |
| 1798 | void |
| 1799 | _M_insert(iterator __position, _Args&&... __args) |
| 1800 | { |
| 1801 | _Node* __tmp = _M_create_node(std::forward<_Args>(__args)...); |
| 1802 | __tmp->_M_hook(__position._M_node); |
| 1803 | this->_M_inc_size(1); |
| 1804 | } |
| 1805 | #endif |
| 1806 | |
| 1807 | |
| 1808 | void |
| 1809 | _M_erase(iterator __position) _GLIBCXX_NOEXCEPT |
| 1810 | { |
| 1811 | this->_M_dec_size(1); |
| 1812 | __position._M_node->_M_unhook(); |
| 1813 | _Node* __n = static_cast<_Node*>(__position._M_node); |
| 1814 | #if __cplusplus >= 201103L |
| 1815 | _Node_alloc_traits::destroy(_M_get_Node_allocator(), __n->_M_valptr()); |
| 1816 | #else |
| 1817 | _Tp_alloc_type(_M_get_Node_allocator()).destroy(__n->_M_valptr()); |
| 1818 | #endif |
| 1819 | |
| 1820 | _M_put_node(__n); |
| 1821 | } |
| 1822 | |
| 1823 | |
| 1824 | void |
| 1825 | _M_check_equal_allocators(list& __x) _GLIBCXX_NOEXCEPT |
| 1826 | { |
| 1827 | if (std::__alloc_neq<typename _Base::_Node_alloc_type>:: |
| 1828 | _S_do_it(_M_get_Node_allocator(), __x._M_get_Node_allocator())) |
| 1829 | __builtin_abort(); |
| 1830 | } |
| 1831 | |
| 1832 | |
| 1833 | const_iterator |
| 1834 | _M_resize_pos(size_type& __new_size) const; |
| 1835 | |
| 1836 | #if __cplusplus >= 201103L |
| 1837 | void |
| 1838 | _M_move_assign(list&& __x, true_type) noexcept |
| 1839 | { |
| 1840 | this->_M_clear(); |
| 1841 | if (__x.empty()) |
| 1842 | this->_M_init(); |
| 1843 | else |
| 1844 | { |
| 1845 | this->_M_impl._M_node._M_next = __x._M_impl._M_node._M_next; |
| 1846 | this->_M_impl._M_node._M_next->_M_prev = &this->_M_impl._M_node; |
| 1847 | this->_M_impl._M_node._M_prev = __x._M_impl._M_node._M_prev; |
| 1848 | this->_M_impl._M_node._M_prev->_M_next = &this->_M_impl._M_node; |
| 1849 | this->_M_set_size(__x._M_get_size()); |
| 1850 | __x._M_init(); |
| 1851 | } |
| 1852 | std::__alloc_on_move(this->_M_get_Node_allocator(), |
| 1853 | __x._M_get_Node_allocator()); |
| 1854 | } |
| 1855 | |
| 1856 | void |
| 1857 | _M_move_assign(list&& __x, false_type) |
| 1858 | { |
| 1859 | if (__x._M_get_Node_allocator() == this->_M_get_Node_allocator()) |
| 1860 | _M_move_assign(std::move(__x), true_type{}); |
| 1861 | else |
| 1862 | |
| 1863 | |
| 1864 | _M_assign_dispatch(std::__make_move_if_noexcept_iterator(__x.begin()), |
| 1865 | std::__make_move_if_noexcept_iterator(__x.end()), |
| 1866 | __false_type{}); |
| 1867 | } |
| 1868 | #endif |
| 1869 | }; |
| 1870 | _GLIBCXX_END_NAMESPACE_CXX11 |
| 1871 | |
| 1872 | |
| 1873 | |
| 1874 | |
| 1875 | |
| 1876 | |
| 1877 | |
| 1878 | |
| 1879 | |
| 1880 | |
| 1881 | |
| 1882 | template<typename _Tp, typename _Alloc> |
| 1883 | inline bool |
| 1884 | operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1885 | { |
| 1886 | #if _GLIBCXX_USE_CXX11_ABI |
| 1887 | if (__x.size() != __y.size()) |
| 1888 | return false; |
| 1889 | #endif |
| 1890 | |
| 1891 | typedef typename list<_Tp, _Alloc>::const_iterator const_iterator; |
| 1892 | const_iterator __end1 = __x.end(); |
| 1893 | const_iterator __end2 = __y.end(); |
| 1894 | |
| 1895 | const_iterator __i1 = __x.begin(); |
| 1896 | const_iterator __i2 = __y.begin(); |
| 1897 | while (__i1 != __end1 && __i2 != __end2 && *__i1 == *__i2) |
| 1898 | { |
| 1899 | ++__i1; |
| 1900 | ++__i2; |
| 1901 | } |
| 1902 | return __i1 == __end1 && __i2 == __end2; |
| 1903 | } |
| 1904 | |
| 1905 | |
| 1906 | |
| 1907 | |
| 1908 | |
| 1909 | |
| 1910 | |
| 1911 | |
| 1912 | |
| 1913 | |
| 1914 | |
| 1915 | |
| 1916 | template<typename _Tp, typename _Alloc> |
| 1917 | inline bool |
| 1918 | operator<(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1919 | { return std::lexicographical_compare(__x.begin(), __x.end(), |
| 1920 | __y.begin(), __y.end()); } |
| 1921 | |
| 1922 | |
| 1923 | template<typename _Tp, typename _Alloc> |
| 1924 | inline bool |
| 1925 | operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1926 | { return !(__x == __y); } |
| 1927 | |
| 1928 | |
| 1929 | template<typename _Tp, typename _Alloc> |
| 1930 | inline bool |
| 1931 | operator>(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1932 | { return __y < __x; } |
| 1933 | |
| 1934 | |
| 1935 | template<typename _Tp, typename _Alloc> |
| 1936 | inline bool |
| 1937 | operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1938 | { return !(__y < __x); } |
| 1939 | |
| 1940 | |
| 1941 | template<typename _Tp, typename _Alloc> |
| 1942 | inline bool |
| 1943 | operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) |
| 1944 | { return !(__x < __y); } |
| 1945 | |
| 1946 | |
| 1947 | template<typename _Tp, typename _Alloc> |
| 1948 | inline void |
| 1949 | swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) |
| 1950 | _GLIBCXX_NOEXCEPT_IF(noexcept(__x.swap(__y))) |
| 1951 | { __x.swap(__y); } |
| 1952 | |
| 1953 | _GLIBCXX_END_NAMESPACE_CONTAINER |
| 1954 | |
| 1955 | #if _GLIBCXX_USE_CXX11_ABI |
| 1956 | _GLIBCXX_BEGIN_NAMESPACE_VERSION |
| 1957 | |
| 1958 | |
| 1959 | template<typename _Tp> |
| 1960 | inline ptrdiff_t |
| 1961 | __distance(_GLIBCXX_STD_C::_List_iterator<_Tp> __first, |
| 1962 | _GLIBCXX_STD_C::_List_iterator<_Tp> __last, |
| 1963 | input_iterator_tag __tag) |
| 1964 | { |
| 1965 | typedef _GLIBCXX_STD_C::_List_const_iterator<_Tp> _CIter; |
| 1966 | return std::__distance(_CIter(__first), _CIter(__last), __tag); |
| 1967 | } |
| 1968 | |
| 1969 | template<typename _Tp> |
| 1970 | inline ptrdiff_t |
| 1971 | __distance(_GLIBCXX_STD_C::_List_const_iterator<_Tp> __first, |
| 1972 | _GLIBCXX_STD_C::_List_const_iterator<_Tp> __last, |
| 1973 | input_iterator_tag) |
| 1974 | { |
| 1975 | typedef _GLIBCXX_STD_C::_List_node<size_t> _Sentinel; |
| 1976 | _GLIBCXX_STD_C::_List_const_iterator<_Tp> __beyond = __last; |
| 1977 | ++__beyond; |
| 1978 | bool __whole = __first == __beyond; |
| 1979 | if (__builtin_constant_p (__whole) && __whole) |
| 1980 | return *static_cast<const _Sentinel*>(__last._M_node)->_M_valptr(); |
| 1981 | |
| 1982 | ptrdiff_t __n = 0; |
| 1983 | while (__first != __last) |
| 1984 | { |
| 1985 | ++__first; |
| 1986 | ++__n; |
| 1987 | } |
| 1988 | return __n; |
| 1989 | } |
| 1990 | |
| 1991 | _GLIBCXX_END_NAMESPACE_VERSION |
| 1992 | #endif |
| 1993 | } |
| 1994 | |
| 1995 | #endif |
| 1996 | |