list revision 253159
1275970Scy// -*- C++ -*- 2275970Scy//===---------------------------- list ------------------------------------===// 3275970Scy// 4275970Scy// The LLVM Compiler Infrastructure 5275970Scy// 6275970Scy// This file is dual licensed under the MIT and the University of Illinois Open 7275970Scy// Source Licenses. See LICENSE.TXT for details. 8275970Scy// 9275970Scy//===----------------------------------------------------------------------===// 10275970Scy 11275970Scy#ifndef _LIBCPP_LIST 12275970Scy#define _LIBCPP_LIST 13275970Scy 14275970Scy/* 15275970Scy list synopsis 16275970Scy 17275970Scynamespace std 18275970Scy{ 19275970Scy 20275970Scytemplate <class T, class Alloc = allocator<T> > 21275970Scyclass list 22275970Scy{ 23275970Scypublic: 24275970Scy 25275970Scy // types: 26275970Scy typedef T value_type; 27275970Scy typedef Alloc allocator_type; 28275970Scy typedef typename allocator_type::reference reference; 29275970Scy typedef typename allocator_type::const_reference const_reference; 30275970Scy typedef typename allocator_type::pointer pointer; 31275970Scy typedef typename allocator_type::const_pointer const_pointer; 32275970Scy typedef implementation-defined iterator; 33275970Scy typedef implementation-defined const_iterator; 34275970Scy typedef implementation-defined size_type; 35275970Scy typedef implementation-defined difference_type; 36275970Scy typedef reverse_iterator<iterator> reverse_iterator; 37275970Scy typedef reverse_iterator<const_iterator> const_reverse_iterator; 38275970Scy 39275970Scy list() 40275970Scy noexcept(is_nothrow_default_constructible<allocator_type>::value); 41275970Scy explicit list(const allocator_type& a); 42275970Scy explicit list(size_type n); 43275970Scy list(size_type n, const value_type& value); 44275970Scy list(size_type n, const value_type& value, const allocator_type& a); 45275970Scy template <class Iter> 46275970Scy list(Iter first, Iter last); 47275970Scy template <class Iter> 48275970Scy list(Iter first, Iter last, const allocator_type& a); 49275970Scy list(const list& x); 50275970Scy list(const list&, const allocator_type& a); 51275970Scy list(list&& x) 52275970Scy noexcept(is_nothrow_move_constructible<allocator_type>::value); 53275970Scy list(list&&, const allocator_type& a); 54275970Scy list(initializer_list<value_type>); 55275970Scy list(initializer_list<value_type>, const allocator_type& a); 56275970Scy 57275970Scy ~list(); 58275970Scy 59275970Scy list& operator=(const list& x); 60275970Scy list& operator=(list&& x) 61275970Scy noexcept( 62275970Scy allocator_type::propagate_on_container_move_assignment::value && 63275970Scy is_nothrow_move_assignable<allocator_type>::value); 64275970Scy list& operator=(initializer_list<value_type>); 65275970Scy template <class Iter> 66275970Scy void assign(Iter first, Iter last); 67275970Scy void assign(size_type n, const value_type& t); 68275970Scy void assign(initializer_list<value_type>); 69275970Scy 70275970Scy allocator_type get_allocator() const noexcept; 71275970Scy 72275970Scy iterator begin() noexcept; 73275970Scy const_iterator begin() const noexcept; 74275970Scy iterator end() noexcept; 75275970Scy const_iterator end() const noexcept; 76275970Scy reverse_iterator rbegin() noexcept; 77275970Scy const_reverse_iterator rbegin() const noexcept; 78275970Scy reverse_iterator rend() noexcept; 79275970Scy const_reverse_iterator rend() const noexcept; 80275970Scy const_iterator cbegin() const noexcept; 81275970Scy const_iterator cend() const noexcept; 82275970Scy const_reverse_iterator crbegin() const noexcept; 83275970Scy const_reverse_iterator crend() const noexcept; 84275970Scy 85275970Scy reference front(); 86275970Scy const_reference front() const; 87275970Scy reference back(); 88275970Scy const_reference back() const; 89275970Scy 90275970Scy bool empty() const noexcept; 91275970Scy size_type size() const noexcept; 92275970Scy size_type max_size() const noexcept; 93275970Scy 94275970Scy template <class... Args> 95275970Scy void emplace_front(Args&&... args); 96275970Scy void pop_front(); 97275970Scy template <class... Args> 98275970Scy void emplace_back(Args&&... args); 99275970Scy void pop_back(); 100275970Scy void push_front(const value_type& x); 101275970Scy void push_front(value_type&& x); 102275970Scy void push_back(const value_type& x); 103275970Scy void push_back(value_type&& x); 104275970Scy template <class... Args> 105275970Scy iterator emplace(const_iterator position, Args&&... args); 106275970Scy iterator insert(const_iterator position, const value_type& x); 107275970Scy iterator insert(const_iterator position, value_type&& x); 108275970Scy iterator insert(const_iterator position, size_type n, const value_type& x); 109275970Scy template <class Iter> 110275970Scy iterator insert(const_iterator position, Iter first, Iter last); 111275970Scy iterator insert(const_iterator position, initializer_list<value_type> il); 112275970Scy 113275970Scy iterator erase(const_iterator position); 114275970Scy iterator erase(const_iterator position, const_iterator last); 115275970Scy 116275970Scy void resize(size_type sz); 117275970Scy void resize(size_type sz, const value_type& c); 118275970Scy 119275970Scy void swap(list&) 120275970Scy noexcept(!allocator_type::propagate_on_container_swap::value || 121275970Scy __is_nothrow_swappable<allocator_type>::value); 122275970Scy void clear() noexcept; 123275970Scy 124275970Scy void splice(const_iterator position, list& x); 125275970Scy void splice(const_iterator position, list&& x); 126275970Scy void splice(const_iterator position, list& x, const_iterator i); 127275970Scy void splice(const_iterator position, list&& x, const_iterator i); 128275970Scy void splice(const_iterator position, list& x, const_iterator first, 129275970Scy const_iterator last); 130275970Scy void splice(const_iterator position, list&& x, const_iterator first, 131275970Scy const_iterator last); 132275970Scy 133275970Scy void remove(const value_type& value); 134275970Scy template <class Pred> void remove_if(Pred pred); 135275970Scy void unique(); 136275970Scy template <class BinaryPredicate> 137275970Scy void unique(BinaryPredicate binary_pred); 138275970Scy void merge(list& x); 139275970Scy void merge(list&& x); 140275970Scy template <class Compare> 141275970Scy void merge(list& x, Compare comp); 142275970Scy template <class Compare> 143275970Scy void merge(list&& x, Compare comp); 144275970Scy void sort(); 145275970Scy template <class Compare> 146275970Scy void sort(Compare comp); 147275970Scy void reverse() noexcept; 148275970Scy}; 149275970Scy 150275970Scytemplate <class T, class Alloc> 151275970Scy bool operator==(const list<T,Alloc>& x, const list<T,Alloc>& y); 152275970Scytemplate <class T, class Alloc> 153275970Scy bool operator< (const list<T,Alloc>& x, const list<T,Alloc>& y); 154275970Scytemplate <class T, class Alloc> 155275970Scy bool operator!=(const list<T,Alloc>& x, const list<T,Alloc>& y); 156275970Scytemplate <class T, class Alloc> 157275970Scy bool operator> (const list<T,Alloc>& x, const list<T,Alloc>& y); 158275970Scytemplate <class T, class Alloc> 159275970Scy bool operator>=(const list<T,Alloc>& x, const list<T,Alloc>& y); 160275970Scytemplate <class T, class Alloc> 161275970Scy bool operator<=(const list<T,Alloc>& x, const list<T,Alloc>& y); 162275970Scy 163275970Scytemplate <class T, class Alloc> 164275970Scy void swap(list<T,Alloc>& x, list<T,Alloc>& y) 165275970Scy noexcept(noexcept(x.swap(y))); 166275970Scy 167275970Scy} // std 168275970Scy 169275970Scy*/ 170275970Scy 171275970Scy#include <__config> 172275970Scy 173275970Scy#include <memory> 174275970Scy#include <limits> 175275970Scy#include <initializer_list> 176275970Scy#include <iterator> 177275970Scy#include <algorithm> 178275970Scy 179275970Scy#include <__undef_min_max> 180275970Scy 181275970Scy#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 182275970Scy#pragma GCC system_header 183275970Scy#endif 184275970Scy 185275970Scy_LIBCPP_BEGIN_NAMESPACE_STD 186275970Scy 187275970Scytemplate <class _Tp, class _VoidPtr> struct __list_node; 188275970Scy 189275970Scytemplate <class _Tp, class _VoidPtr> 190275970Scystruct __list_node_base 191275970Scy{ 192275970Scy typedef typename pointer_traits<_VoidPtr>::template 193275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 194275970Scy rebind<__list_node<_Tp, _VoidPtr> > pointer; 195275970Scy#else 196275970Scy rebind<__list_node<_Tp, _VoidPtr> >::other pointer; 197275970Scy#endif 198275970Scy 199275970Scy typedef typename pointer_traits<_VoidPtr>::template 200275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 201275970Scy rebind<__list_node_base> __base_pointer; 202275970Scy#else 203275970Scy rebind<__list_node_base>::other __base_pointer; 204275970Scy#endif 205275970Scy 206275970Scy pointer __prev_; 207275970Scy pointer __next_; 208275970Scy 209275970Scy _LIBCPP_INLINE_VISIBILITY 210275970Scy __list_node_base() 211275970Scy : __prev_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))), 212275970Scy __next_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))) 213275970Scy {} 214275970Scy}; 215275970Scy 216275970Scytemplate <class _Tp, class _VoidPtr> 217275970Scystruct __list_node 218275970Scy : public __list_node_base<_Tp, _VoidPtr> 219275970Scy{ 220275970Scy _Tp __value_; 221275970Scy}; 222275970Scy 223275970Scytemplate <class _Tp, class _Alloc> class _LIBCPP_TYPE_VIS list; 224275970Scytemplate <class _Tp, class _Alloc> class __list_imp; 225275970Scytemplate <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS __list_const_iterator; 226275970Scy 227275970Scytemplate <class _Tp, class _VoidPtr> 228275970Scyclass _LIBCPP_TYPE_VIS __list_iterator 229275970Scy{ 230275970Scy typedef typename pointer_traits<_VoidPtr>::template 231275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 232275970Scy rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; 233275970Scy#else 234275970Scy rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; 235275970Scy#endif 236275970Scy 237275970Scy __node_pointer __ptr_; 238275970Scy 239275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 240275970Scy _LIBCPP_INLINE_VISIBILITY 241275970Scy explicit __list_iterator(__node_pointer __p, const void* __c) _NOEXCEPT 242275970Scy : __ptr_(__p) 243275970Scy { 244275970Scy __get_db()->__insert_ic(this, __c); 245275970Scy } 246275970Scy#else 247275970Scy _LIBCPP_INLINE_VISIBILITY 248275970Scy explicit __list_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} 249275970Scy#endif 250275970Scy 251275970Scy 252275970Scy 253275970Scy template<class, class> friend class list; 254275970Scy template<class, class> friend class __list_imp; 255275970Scy template<class, class> friend class __list_const_iterator; 256275970Scypublic: 257275970Scy typedef bidirectional_iterator_tag iterator_category; 258275970Scy typedef _Tp value_type; 259275970Scy typedef value_type& reference; 260275970Scy typedef typename pointer_traits<_VoidPtr>::template 261275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 262275970Scy rebind<value_type> 263275970Scy#else 264275970Scy rebind<value_type>::other 265275970Scy#endif 266275970Scy pointer; 267275970Scy typedef typename pointer_traits<pointer>::difference_type difference_type; 268275970Scy 269275970Scy _LIBCPP_INLINE_VISIBILITY 270275970Scy __list_iterator() _NOEXCEPT 271275970Scy { 272275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 273275970Scy __get_db()->__insert_i(this); 274275970Scy#endif 275275970Scy } 276275970Scy 277275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 278275970Scy 279275970Scy _LIBCPP_INLINE_VISIBILITY 280275970Scy __list_iterator(const __list_iterator& __p) 281275970Scy : __ptr_(__p.__ptr_) 282275970Scy { 283275970Scy __get_db()->__iterator_copy(this, &__p); 284275970Scy } 285275970Scy 286275970Scy _LIBCPP_INLINE_VISIBILITY 287275970Scy ~__list_iterator() 288275970Scy { 289275970Scy __get_db()->__erase_i(this); 290275970Scy } 291275970Scy 292275970Scy _LIBCPP_INLINE_VISIBILITY 293275970Scy __list_iterator& operator=(const __list_iterator& __p) 294275970Scy { 295275970Scy if (this != &__p) 296275970Scy { 297275970Scy __get_db()->__iterator_copy(this, &__p); 298275970Scy __ptr_ = __p.__ptr_; 299275970Scy } 300275970Scy return *this; 301275970Scy } 302275970Scy 303275970Scy#endif // _LIBCPP_DEBUG_LEVEL >= 2 304275970Scy 305275970Scy _LIBCPP_INLINE_VISIBILITY 306275970Scy reference operator*() const 307275970Scy { 308275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 309275970Scy _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 310275970Scy "Attempted to dereference a non-dereferenceable list::iterator"); 311275970Scy#endif 312275970Scy return __ptr_->__value_; 313275970Scy } 314275970Scy _LIBCPP_INLINE_VISIBILITY 315275970Scy pointer operator->() const 316275970Scy { 317275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 318275970Scy _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 319275970Scy "Attempted to dereference a non-dereferenceable list::iterator"); 320275970Scy#endif 321275970Scy return pointer_traits<pointer>::pointer_to(__ptr_->__value_); 322275970Scy } 323275970Scy 324275970Scy _LIBCPP_INLINE_VISIBILITY 325275970Scy __list_iterator& operator++() 326275970Scy { 327275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 328275970Scy _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 329275970Scy "Attempted to increment non-incrementable list::iterator"); 330275970Scy#endif 331275970Scy __ptr_ = __ptr_->__next_; 332275970Scy return *this; 333275970Scy } 334275970Scy _LIBCPP_INLINE_VISIBILITY 335275970Scy __list_iterator operator++(int) {__list_iterator __t(*this); ++(*this); return __t;} 336275970Scy 337275970Scy _LIBCPP_INLINE_VISIBILITY 338275970Scy __list_iterator& operator--() 339275970Scy { 340275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 341275970Scy _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 342275970Scy "Attempted to decrement non-decrementable list::iterator"); 343275970Scy#endif 344275970Scy __ptr_ = __ptr_->__prev_; 345275970Scy return *this; 346275970Scy } 347275970Scy _LIBCPP_INLINE_VISIBILITY 348275970Scy __list_iterator operator--(int) {__list_iterator __t(*this); --(*this); return __t;} 349275970Scy 350275970Scy friend _LIBCPP_INLINE_VISIBILITY 351275970Scy bool operator==(const __list_iterator& __x, const __list_iterator& __y) 352275970Scy { 353275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 354275970Scy _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), 355275970Scy "Attempted to compare non-comparable list::iterator"); 356275970Scy#endif 357275970Scy return __x.__ptr_ == __y.__ptr_; 358275970Scy } 359275970Scy friend _LIBCPP_INLINE_VISIBILITY 360275970Scy bool operator!=(const __list_iterator& __x, const __list_iterator& __y) 361275970Scy {return !(__x == __y);} 362275970Scy}; 363275970Scy 364275970Scytemplate <class _Tp, class _VoidPtr> 365275970Scyclass _LIBCPP_TYPE_VIS __list_const_iterator 366275970Scy{ 367275970Scy typedef typename pointer_traits<_VoidPtr>::template 368275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 369275970Scy rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; 370275970Scy#else 371275970Scy rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; 372275970Scy#endif 373275970Scy 374275970Scy __node_pointer __ptr_; 375275970Scy 376275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 377275970Scy _LIBCPP_INLINE_VISIBILITY 378275970Scy explicit __list_const_iterator(__node_pointer __p, const void* __c) _NOEXCEPT 379275970Scy : __ptr_(__p) 380275970Scy { 381275970Scy __get_db()->__insert_ic(this, __c); 382275970Scy } 383275970Scy#else 384275970Scy _LIBCPP_INLINE_VISIBILITY 385275970Scy explicit __list_const_iterator(__node_pointer __p) _NOEXCEPT : __ptr_(__p) {} 386275970Scy#endif 387275970Scy 388275970Scy template<class, class> friend class list; 389275970Scy template<class, class> friend class __list_imp; 390275970Scypublic: 391275970Scy typedef bidirectional_iterator_tag iterator_category; 392275970Scy typedef _Tp value_type; 393275970Scy typedef const value_type& reference; 394275970Scy typedef typename pointer_traits<_VoidPtr>::template 395275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 396275970Scy rebind<const value_type> 397275970Scy#else 398275970Scy rebind<const value_type>::other 399275970Scy#endif 400275970Scy pointer; 401275970Scy typedef typename pointer_traits<pointer>::difference_type difference_type; 402275970Scy 403275970Scy _LIBCPP_INLINE_VISIBILITY 404275970Scy __list_const_iterator() _NOEXCEPT 405275970Scy { 406275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 407275970Scy __get_db()->__insert_i(this); 408275970Scy#endif 409275970Scy } 410275970Scy _LIBCPP_INLINE_VISIBILITY 411275970Scy __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT 412275970Scy : __ptr_(__p.__ptr_) 413275970Scy { 414275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 415275970Scy __get_db()->__iterator_copy(this, &__p); 416275970Scy#endif 417275970Scy } 418275970Scy 419275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 420275970Scy 421275970Scy _LIBCPP_INLINE_VISIBILITY 422275970Scy __list_const_iterator(const __list_const_iterator& __p) 423275970Scy : __ptr_(__p.__ptr_) 424275970Scy { 425275970Scy __get_db()->__iterator_copy(this, &__p); 426275970Scy } 427275970Scy 428275970Scy _LIBCPP_INLINE_VISIBILITY 429275970Scy ~__list_const_iterator() 430275970Scy { 431275970Scy __get_db()->__erase_i(this); 432275970Scy } 433275970Scy 434275970Scy _LIBCPP_INLINE_VISIBILITY 435275970Scy __list_const_iterator& operator=(const __list_const_iterator& __p) 436275970Scy { 437275970Scy if (this != &__p) 438275970Scy { 439275970Scy __get_db()->__iterator_copy(this, &__p); 440275970Scy __ptr_ = __p.__ptr_; 441275970Scy } 442275970Scy return *this; 443275970Scy } 444275970Scy 445275970Scy#endif // _LIBCPP_DEBUG_LEVEL >= 2 446275970Scy _LIBCPP_INLINE_VISIBILITY 447275970Scy reference operator*() const 448275970Scy { 449275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 450275970Scy _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 451275970Scy "Attempted to dereference a non-dereferenceable list::const_iterator"); 452275970Scy#endif 453275970Scy return __ptr_->__value_; 454275970Scy } 455275970Scy _LIBCPP_INLINE_VISIBILITY 456275970Scy pointer operator->() const 457275970Scy { 458275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 459275970Scy _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 460275970Scy "Attempted to dereference a non-dereferenceable list::iterator"); 461275970Scy#endif 462275970Scy return pointer_traits<pointer>::pointer_to(__ptr_->__value_); 463275970Scy } 464275970Scy 465275970Scy _LIBCPP_INLINE_VISIBILITY 466275970Scy __list_const_iterator& operator++() 467275970Scy { 468275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 469275970Scy _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), 470275970Scy "Attempted to increment non-incrementable list::const_iterator"); 471275970Scy#endif 472275970Scy __ptr_ = __ptr_->__next_; 473275970Scy return *this; 474275970Scy } 475275970Scy _LIBCPP_INLINE_VISIBILITY 476275970Scy __list_const_iterator operator++(int) {__list_const_iterator __t(*this); ++(*this); return __t;} 477275970Scy 478275970Scy _LIBCPP_INLINE_VISIBILITY 479275970Scy __list_const_iterator& operator--() 480275970Scy { 481275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 482275970Scy _LIBCPP_ASSERT(__get_const_db()->__decrementable(this), 483275970Scy "Attempted to decrement non-decrementable list::const_iterator"); 484275970Scy#endif 485275970Scy __ptr_ = __ptr_->__prev_; 486275970Scy return *this; 487275970Scy } 488275970Scy _LIBCPP_INLINE_VISIBILITY 489275970Scy __list_const_iterator operator--(int) {__list_const_iterator __t(*this); --(*this); return __t;} 490275970Scy 491275970Scy friend _LIBCPP_INLINE_VISIBILITY 492275970Scy bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) 493275970Scy { 494275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 495275970Scy _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), 496275970Scy "Attempted to compare non-comparable list::const_iterator"); 497275970Scy#endif 498275970Scy return __x.__ptr_ == __y.__ptr_; 499275970Scy } 500275970Scy friend _LIBCPP_INLINE_VISIBILITY 501275970Scy bool operator!=(const __list_const_iterator& __x, const __list_const_iterator& __y) 502275970Scy {return !(__x == __y);} 503275970Scy}; 504275970Scy 505275970Scytemplate <class _Tp, class _Alloc> 506275970Scyclass __list_imp 507275970Scy{ 508275970Scy __list_imp(const __list_imp&); 509275970Scy __list_imp& operator=(const __list_imp&); 510275970Scyprotected: 511275970Scy typedef _Tp value_type; 512275970Scy typedef _Alloc allocator_type; 513275970Scy typedef allocator_traits<allocator_type> __alloc_traits; 514275970Scy typedef typename __alloc_traits::size_type size_type; 515275970Scy typedef typename __alloc_traits::void_pointer __void_pointer; 516275970Scy typedef __list_iterator<value_type, __void_pointer> iterator; 517275970Scy typedef __list_const_iterator<value_type, __void_pointer> const_iterator; 518275970Scy typedef __list_node_base<value_type, __void_pointer> __node_base; 519275970Scy typedef __list_node<value_type, __void_pointer> __node; 520275970Scy typedef typename __alloc_traits::template 521275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 522275970Scy rebind_alloc<__node> 523275970Scy#else 524275970Scy rebind_alloc<__node>::other 525275970Scy#endif 526275970Scy __node_allocator; 527275970Scy typedef allocator_traits<__node_allocator> __node_alloc_traits; 528275970Scy typedef typename __node_alloc_traits::pointer __node_pointer; 529275970Scy typedef typename __node_alloc_traits::pointer __node_const_pointer; 530275970Scy typedef typename __alloc_traits::pointer pointer; 531275970Scy typedef typename __alloc_traits::const_pointer const_pointer; 532275970Scy typedef typename __alloc_traits::difference_type difference_type; 533275970Scy 534275970Scy typedef typename __alloc_traits::template 535275970Scy#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 536275970Scy rebind_alloc<__node_base> 537275970Scy#else 538275970Scy rebind_alloc<__node_base>::other 539275970Scy#endif 540275970Scy __node_base_allocator; 541275970Scy typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; 542275970Scy 543275970Scy __node_base __end_; 544275970Scy __compressed_pair<size_type, __node_allocator> __size_alloc_; 545275970Scy 546275970Scy _LIBCPP_INLINE_VISIBILITY 547275970Scy size_type& __sz() _NOEXCEPT {return __size_alloc_.first();} 548275970Scy _LIBCPP_INLINE_VISIBILITY 549275970Scy const size_type& __sz() const _NOEXCEPT 550275970Scy {return __size_alloc_.first();} 551275970Scy _LIBCPP_INLINE_VISIBILITY 552275970Scy __node_allocator& __node_alloc() _NOEXCEPT 553275970Scy {return __size_alloc_.second();} 554275970Scy _LIBCPP_INLINE_VISIBILITY 555275970Scy const __node_allocator& __node_alloc() const _NOEXCEPT 556275970Scy {return __size_alloc_.second();} 557275970Scy 558275970Scy static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT; 559275970Scy 560275970Scy __list_imp() 561275970Scy _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); 562275970Scy __list_imp(const allocator_type& __a); 563275970Scy ~__list_imp(); 564275970Scy void clear() _NOEXCEPT; 565275970Scy _LIBCPP_INLINE_VISIBILITY 566275970Scy bool empty() const _NOEXCEPT {return __sz() == 0;} 567275970Scy 568275970Scy _LIBCPP_INLINE_VISIBILITY 569275970Scy iterator begin() _NOEXCEPT 570275970Scy { 571275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 572275970Scy return iterator(__end_.__next_, this); 573275970Scy#else 574275970Scy return iterator(__end_.__next_); 575275970Scy#endif 576275970Scy } 577275970Scy _LIBCPP_INLINE_VISIBILITY 578275970Scy const_iterator begin() const _NOEXCEPT 579275970Scy { 580275970Scy#if _LIBCPP_DEBUG_LEVEL >= 2 581275970Scy return const_iterator(__end_.__next_, this); 582275970Scy#else 583275970Scy return const_iterator(__end_.__next_); 584275970Scy#endif 585 } 586 _LIBCPP_INLINE_VISIBILITY 587 iterator end() _NOEXCEPT 588 { 589#if _LIBCPP_DEBUG_LEVEL >= 2 590 return iterator(static_cast<__node_pointer>( 591 pointer_traits<__node_base_pointer>::pointer_to(__end_)), this); 592#else 593 return iterator(static_cast<__node_pointer>( 594 pointer_traits<__node_base_pointer>::pointer_to(__end_))); 595#endif 596 } 597 _LIBCPP_INLINE_VISIBILITY 598 const_iterator end() const _NOEXCEPT 599 { 600#if _LIBCPP_DEBUG_LEVEL >= 2 601 return const_iterator(static_cast<__node_const_pointer>( 602 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this); 603#else 604 return const_iterator(static_cast<__node_const_pointer>( 605 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_)))); 606#endif 607 } 608 609 void swap(__list_imp& __c) 610 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || 611 __is_nothrow_swappable<__node_allocator>::value); 612 613 _LIBCPP_INLINE_VISIBILITY 614 void __copy_assign_alloc(const __list_imp& __c) 615 {__copy_assign_alloc(__c, integral_constant<bool, 616 __node_alloc_traits::propagate_on_container_copy_assignment::value>());} 617 618 _LIBCPP_INLINE_VISIBILITY 619 void __move_assign_alloc(__list_imp& __c) 620 _NOEXCEPT_( 621 !__node_alloc_traits::propagate_on_container_move_assignment::value || 622 is_nothrow_move_assignable<__node_allocator>::value) 623 {__move_assign_alloc(__c, integral_constant<bool, 624 __node_alloc_traits::propagate_on_container_move_assignment::value>());} 625 626private: 627 _LIBCPP_INLINE_VISIBILITY 628 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y) 629 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || 630 __is_nothrow_swappable<__node_allocator>::value) 631 {__swap_alloc(__x, __y, integral_constant<bool, 632 __node_alloc_traits::propagate_on_container_swap::value>());} 633 _LIBCPP_INLINE_VISIBILITY 634 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, true_type) 635 _NOEXCEPT_(__is_nothrow_swappable<__node_allocator>::value) 636 { 637 using _VSTD::swap; 638 swap(__x, __y); 639 } 640 _LIBCPP_INLINE_VISIBILITY 641 static void __swap_alloc(__node_allocator& __x, __node_allocator& __y, false_type) 642 _NOEXCEPT 643 {} 644 645 _LIBCPP_INLINE_VISIBILITY 646 void __copy_assign_alloc(const __list_imp& __c, true_type) 647 { 648 if (__node_alloc() != __c.__node_alloc()) 649 clear(); 650 __node_alloc() = __c.__node_alloc(); 651 } 652 653 _LIBCPP_INLINE_VISIBILITY 654 void __copy_assign_alloc(const __list_imp& __c, false_type) 655 {} 656 657 _LIBCPP_INLINE_VISIBILITY 658 void __move_assign_alloc(__list_imp& __c, true_type) 659 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) 660 { 661 __node_alloc() = _VSTD::move(__c.__node_alloc()); 662 } 663 664 _LIBCPP_INLINE_VISIBILITY 665 void __move_assign_alloc(__list_imp& __c, false_type) 666 _NOEXCEPT 667 {} 668}; 669 670// Unlink nodes [__f, __l] 671template <class _Tp, class _Alloc> 672inline _LIBCPP_INLINE_VISIBILITY 673void 674__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l) 675 _NOEXCEPT 676{ 677 __f->__prev_->__next_ = __l->__next_; 678 __l->__next_->__prev_ = __f->__prev_; 679} 680 681template <class _Tp, class _Alloc> 682inline _LIBCPP_INLINE_VISIBILITY 683__list_imp<_Tp, _Alloc>::__list_imp() 684 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) 685 : __size_alloc_(0) 686{ 687} 688 689template <class _Tp, class _Alloc> 690inline _LIBCPP_INLINE_VISIBILITY 691__list_imp<_Tp, _Alloc>::__list_imp(const allocator_type& __a) 692 : __size_alloc_(0, __node_allocator(__a)) 693{ 694} 695 696template <class _Tp, class _Alloc> 697__list_imp<_Tp, _Alloc>::~__list_imp() 698{ 699 clear(); 700#if _LIBCPP_DEBUG_LEVEL >= 2 701 __get_db()->__erase_c(this); 702#endif 703} 704 705template <class _Tp, class _Alloc> 706void 707__list_imp<_Tp, _Alloc>::clear() _NOEXCEPT 708{ 709 if (!empty()) 710 { 711 __node_allocator& __na = __node_alloc(); 712 __node_pointer __f = __end_.__next_; 713 __node_pointer __l = static_cast<__node_pointer>( 714 pointer_traits<__node_base_pointer>::pointer_to(__end_)); 715 __unlink_nodes(__f, __l->__prev_); 716 __sz() = 0; 717 while (__f != __l) 718 { 719 __node_pointer __n = __f; 720 __f = __f->__next_; 721 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); 722 __node_alloc_traits::deallocate(__na, __n, 1); 723 } 724#if _LIBCPP_DEBUG_LEVEL >= 2 725 __c_node* __c = __get_db()->__find_c_and_lock(this); 726 for (__i_node** __p = __c->end_; __p != __c->beg_; ) 727 { 728 --__p; 729 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 730 if (__i->__ptr_ != __l) 731 { 732 (*__p)->__c_ = nullptr; 733 if (--__c->end_ != __p) 734 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 735 } 736 } 737 __get_db()->unlock(); 738#endif 739 } 740} 741 742template <class _Tp, class _Alloc> 743void 744__list_imp<_Tp, _Alloc>::swap(__list_imp& __c) 745 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || 746 __is_nothrow_swappable<__node_allocator>::value) 747{ 748 _LIBCPP_ASSERT(__alloc_traits::propagate_on_container_swap::value || 749 this->__node_alloc() == __c.__node_alloc(), 750 "list::swap: Either propagate_on_container_swap must be true" 751 " or the allocators must compare equal"); 752 using _VSTD::swap; 753 __swap_alloc(__node_alloc(), __c.__node_alloc()); 754 swap(__sz(), __c.__sz()); 755 swap(__end_, __c.__end_); 756 if (__sz() == 0) 757 __end_.__next_ = __end_.__prev_ = static_cast<__node_pointer>( 758 pointer_traits<__node_base_pointer>::pointer_to(__end_)); 759 else 760 __end_.__prev_->__next_ = __end_.__next_->__prev_ 761 = static_cast<__node_pointer>( 762 pointer_traits<__node_base_pointer>::pointer_to(__end_)); 763 if (__c.__sz() == 0) 764 __c.__end_.__next_ = __c.__end_.__prev_ 765 = static_cast<__node_pointer>( 766 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)); 767 else 768 __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ 769 = static_cast<__node_pointer>( 770 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)); 771#if _LIBCPP_DEBUG_LEVEL >= 2 772 __libcpp_db* __db = __get_db(); 773 __c_node* __cn1 = __db->__find_c_and_lock(this); 774 __c_node* __cn2 = __db->__find_c(&__c); 775 std::swap(__cn1->beg_, __cn2->beg_); 776 std::swap(__cn1->end_, __cn2->end_); 777 std::swap(__cn1->cap_, __cn2->cap_); 778 for (__i_node** __p = __cn1->end_; __p != __cn1->beg_;) 779 { 780 --__p; 781 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 782 if (__i->__ptr_ == static_cast<__node_pointer>( 783 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) 784 { 785 __cn2->__add(*__p); 786 if (--__cn1->end_ != __p) 787 memmove(__p, __p+1, (__cn1->end_ - __p)*sizeof(__i_node*)); 788 } 789 else 790 (*__p)->__c_ = __cn1; 791 } 792 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 793 { 794 --__p; 795 const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); 796 if (__i->__ptr_ == static_cast<__node_pointer>( 797 pointer_traits<__node_base_pointer>::pointer_to(__end_))) 798 { 799 __cn1->__add(*__p); 800 if (--__cn2->end_ != __p) 801 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 802 } 803 else 804 (*__p)->__c_ = __cn2; 805 } 806 __db->unlock(); 807#endif 808} 809 810template <class _Tp, class _Alloc = allocator<_Tp> > 811class _LIBCPP_TYPE_VIS list 812 : private __list_imp<_Tp, _Alloc> 813{ 814 typedef __list_imp<_Tp, _Alloc> base; 815 typedef typename base::__node __node; 816 typedef typename base::__node_allocator __node_allocator; 817 typedef typename base::__node_pointer __node_pointer; 818 typedef typename base::__node_alloc_traits __node_alloc_traits; 819 typedef typename base::__node_base __node_base; 820 typedef typename base::__node_base_pointer __node_base_pointer; 821 822public: 823 typedef _Tp value_type; 824 typedef _Alloc allocator_type; 825 static_assert((is_same<value_type, typename allocator_type::value_type>::value), 826 "Invalid allocator::value_type"); 827 typedef value_type& reference; 828 typedef const value_type& const_reference; 829 typedef typename base::pointer pointer; 830 typedef typename base::const_pointer const_pointer; 831 typedef typename base::size_type size_type; 832 typedef typename base::difference_type difference_type; 833 typedef typename base::iterator iterator; 834 typedef typename base::const_iterator const_iterator; 835 typedef _VSTD::reverse_iterator<iterator> reverse_iterator; 836 typedef _VSTD::reverse_iterator<const_iterator> const_reverse_iterator; 837 838 _LIBCPP_INLINE_VISIBILITY 839 list() 840 _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value) 841 { 842#if _LIBCPP_DEBUG_LEVEL >= 2 843 __get_db()->__insert_c(this); 844#endif 845 } 846 _LIBCPP_INLINE_VISIBILITY 847 list(const allocator_type& __a) : base(__a) 848 { 849#if _LIBCPP_DEBUG_LEVEL >= 2 850 __get_db()->__insert_c(this); 851#endif 852 } 853 list(size_type __n); 854 list(size_type __n, const value_type& __x); 855 list(size_type __n, const value_type& __x, const allocator_type& __a); 856 template <class _InpIter> 857 list(_InpIter __f, _InpIter __l, 858 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); 859 template <class _InpIter> 860 list(_InpIter __f, _InpIter __l, const allocator_type& __a, 861 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); 862 863 list(const list& __c); 864 list(const list& __c, const allocator_type& __a); 865 list& operator=(const list& __c); 866#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 867 list(initializer_list<value_type> __il); 868 list(initializer_list<value_type> __il, const allocator_type& __a); 869#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 870#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 871 list(list&& __c) 872 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value); 873 list(list&& __c, const allocator_type& __a); 874 list& operator=(list&& __c) 875 _NOEXCEPT_( 876 __node_alloc_traits::propagate_on_container_move_assignment::value && 877 is_nothrow_move_assignable<__node_allocator>::value); 878#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 879#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 880 _LIBCPP_INLINE_VISIBILITY 881 list& operator=(initializer_list<value_type> __il) 882 {assign(__il.begin(), __il.end()); return *this;} 883#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 884 885 template <class _InpIter> 886 void assign(_InpIter __f, _InpIter __l, 887 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); 888 void assign(size_type __n, const value_type& __x); 889#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 890 _LIBCPP_INLINE_VISIBILITY 891 void assign(initializer_list<value_type> __il) 892 {assign(__il.begin(), __il.end());} 893#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 894 895 allocator_type get_allocator() const _NOEXCEPT; 896 897 _LIBCPP_INLINE_VISIBILITY 898 size_type size() const _NOEXCEPT {return base::__sz();} 899 _LIBCPP_INLINE_VISIBILITY 900 bool empty() const _NOEXCEPT {return base::empty();} 901 _LIBCPP_INLINE_VISIBILITY 902 size_type max_size() const _NOEXCEPT 903 {return numeric_limits<difference_type>::max();} 904 905 _LIBCPP_INLINE_VISIBILITY 906 iterator begin() _NOEXCEPT {return base::begin();} 907 _LIBCPP_INLINE_VISIBILITY 908 const_iterator begin() const _NOEXCEPT {return base::begin();} 909 _LIBCPP_INLINE_VISIBILITY 910 iterator end() _NOEXCEPT {return base::end();} 911 _LIBCPP_INLINE_VISIBILITY 912 const_iterator end() const _NOEXCEPT {return base::end();} 913 _LIBCPP_INLINE_VISIBILITY 914 const_iterator cbegin() const _NOEXCEPT {return base::begin();} 915 _LIBCPP_INLINE_VISIBILITY 916 const_iterator cend() const _NOEXCEPT {return base::end();} 917 918 _LIBCPP_INLINE_VISIBILITY 919 reverse_iterator rbegin() _NOEXCEPT 920 {return reverse_iterator(end());} 921 _LIBCPP_INLINE_VISIBILITY 922 const_reverse_iterator rbegin() const _NOEXCEPT 923 {return const_reverse_iterator(end());} 924 _LIBCPP_INLINE_VISIBILITY 925 reverse_iterator rend() _NOEXCEPT 926 {return reverse_iterator(begin());} 927 _LIBCPP_INLINE_VISIBILITY 928 const_reverse_iterator rend() const _NOEXCEPT 929 {return const_reverse_iterator(begin());} 930 _LIBCPP_INLINE_VISIBILITY 931 const_reverse_iterator crbegin() const _NOEXCEPT 932 {return const_reverse_iterator(end());} 933 _LIBCPP_INLINE_VISIBILITY 934 const_reverse_iterator crend() const _NOEXCEPT 935 {return const_reverse_iterator(begin());} 936 937 _LIBCPP_INLINE_VISIBILITY 938 reference front() 939 { 940 _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); 941 return base::__end_.__next_->__value_; 942 } 943 _LIBCPP_INLINE_VISIBILITY 944 const_reference front() const 945 { 946 _LIBCPP_ASSERT(!empty(), "list::front called on empty list"); 947 return base::__end_.__next_->__value_; 948 } 949 _LIBCPP_INLINE_VISIBILITY 950 reference back() 951 { 952 _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); 953 return base::__end_.__prev_->__value_; 954 } 955 _LIBCPP_INLINE_VISIBILITY 956 const_reference back() const 957 { 958 _LIBCPP_ASSERT(!empty(), "list::back called on empty list"); 959 return base::__end_.__prev_->__value_; 960 } 961 962#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 963 void push_front(value_type&& __x); 964 void push_back(value_type&& __x); 965#ifndef _LIBCPP_HAS_NO_VARIADICS 966 template <class... _Args> 967 void emplace_front(_Args&&... __args); 968 template <class... _Args> 969 void emplace_back(_Args&&... __args); 970 template <class... _Args> 971 iterator emplace(const_iterator __p, _Args&&... __args); 972#endif // _LIBCPP_HAS_NO_VARIADICS 973 iterator insert(const_iterator __p, value_type&& __x); 974#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 975 976 void push_front(const value_type& __x); 977 void push_back(const value_type& __x); 978 979 iterator insert(const_iterator __p, const value_type& __x); 980 iterator insert(const_iterator __p, size_type __n, const value_type& __x); 981 template <class _InpIter> 982 iterator insert(const_iterator __p, _InpIter __f, _InpIter __l, 983 typename enable_if<__is_input_iterator<_InpIter>::value>::type* = 0); 984#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 985 _LIBCPP_INLINE_VISIBILITY 986 iterator insert(const_iterator __p, initializer_list<value_type> __il) 987 {return insert(__p, __il.begin(), __il.end());} 988#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 989 990 _LIBCPP_INLINE_VISIBILITY 991 void swap(list& __c) 992 _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value || 993 __is_nothrow_swappable<__node_allocator>::value) 994 {base::swap(__c);} 995 _LIBCPP_INLINE_VISIBILITY 996 void clear() _NOEXCEPT {base::clear();} 997 998 void pop_front(); 999 void pop_back(); 1000 1001 iterator erase(const_iterator __p); 1002 iterator erase(const_iterator __f, const_iterator __l); 1003 1004 void resize(size_type __n); 1005 void resize(size_type __n, const value_type& __x); 1006 1007 void splice(const_iterator __p, list& __c); 1008#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1009 _LIBCPP_INLINE_VISIBILITY 1010 void splice(const_iterator __p, list&& __c) {splice(__p, __c);} 1011#endif 1012 void splice(const_iterator __p, list& __c, const_iterator __i); 1013#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1014 _LIBCPP_INLINE_VISIBILITY 1015 void splice(const_iterator __p, list&& __c, const_iterator __i) 1016 {splice(__p, __c, __i);} 1017#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1018 void splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l); 1019#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1020 _LIBCPP_INLINE_VISIBILITY 1021 void splice(const_iterator __p, list&& __c, const_iterator __f, const_iterator __l) 1022 {splice(__p, __c, __f, __l);} 1023#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1024 1025 void remove(const value_type& __x); 1026 template <class _Pred> void remove_if(_Pred __pred); 1027 void unique(); 1028 template <class _BinaryPred> 1029 void unique(_BinaryPred __binary_pred); 1030 void merge(list& __c); 1031#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1032 _LIBCPP_INLINE_VISIBILITY 1033 void merge(list&& __c) {merge(__c);} 1034#endif 1035 template <class _Comp> 1036 void merge(list& __c, _Comp __comp); 1037#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1038 template <class _Comp> 1039 _LIBCPP_INLINE_VISIBILITY 1040 void merge(list&& __c, _Comp __comp) {merge(__c, __comp);} 1041#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1042 void sort(); 1043 template <class _Comp> 1044 void sort(_Comp __comp); 1045 1046 void reverse() _NOEXCEPT; 1047 1048 bool __invariants() const; 1049 1050#if _LIBCPP_DEBUG_LEVEL >= 2 1051 1052 bool __dereferenceable(const const_iterator* __i) const; 1053 bool __decrementable(const const_iterator* __i) const; 1054 bool __addable(const const_iterator* __i, ptrdiff_t __n) const; 1055 bool __subscriptable(const const_iterator* __i, ptrdiff_t __n) const; 1056 1057#endif // _LIBCPP_DEBUG_LEVEL >= 2 1058 1059private: 1060 static void __link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l); 1061 iterator __iterator(size_type __n); 1062 template <class _Comp> 1063 static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); 1064 1065 void __move_assign(list& __c, true_type) 1066 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value); 1067 void __move_assign(list& __c, false_type); 1068}; 1069 1070// Link in nodes [__f, __l] just prior to __p 1071template <class _Tp, class _Alloc> 1072inline _LIBCPP_INLINE_VISIBILITY 1073void 1074list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l) 1075{ 1076 __p->__prev_->__next_ = __f; 1077 __f->__prev_ = __p->__prev_; 1078 __p->__prev_ = __l; 1079 __l->__next_ = __p; 1080} 1081 1082template <class _Tp, class _Alloc> 1083inline _LIBCPP_INLINE_VISIBILITY 1084typename list<_Tp, _Alloc>::iterator 1085list<_Tp, _Alloc>::__iterator(size_type __n) 1086{ 1087 return __n <= base::__sz() / 2 ? _VSTD::next(begin(), __n) 1088 : _VSTD::prev(end(), base::__sz() - __n); 1089} 1090 1091template <class _Tp, class _Alloc> 1092list<_Tp, _Alloc>::list(size_type __n) 1093{ 1094#if _LIBCPP_DEBUG_LEVEL >= 2 1095 __get_db()->__insert_c(this); 1096#endif 1097 for (; __n > 0; --__n) 1098#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1099 emplace_back(); 1100#else 1101 push_back(value_type()); 1102#endif 1103} 1104 1105template <class _Tp, class _Alloc> 1106list<_Tp, _Alloc>::list(size_type __n, const value_type& __x) 1107{ 1108#if _LIBCPP_DEBUG_LEVEL >= 2 1109 __get_db()->__insert_c(this); 1110#endif 1111 for (; __n > 0; --__n) 1112 push_back(__x); 1113} 1114 1115template <class _Tp, class _Alloc> 1116list<_Tp, _Alloc>::list(size_type __n, const value_type& __x, const allocator_type& __a) 1117 : base(__a) 1118{ 1119#if _LIBCPP_DEBUG_LEVEL >= 2 1120 __get_db()->__insert_c(this); 1121#endif 1122 for (; __n > 0; --__n) 1123 push_back(__x); 1124} 1125 1126template <class _Tp, class _Alloc> 1127template <class _InpIter> 1128list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, 1129 typename enable_if<__is_input_iterator<_InpIter>::value>::type*) 1130{ 1131#if _LIBCPP_DEBUG_LEVEL >= 2 1132 __get_db()->__insert_c(this); 1133#endif 1134 for (; __f != __l; ++__f) 1135 push_back(*__f); 1136} 1137 1138template <class _Tp, class _Alloc> 1139template <class _InpIter> 1140list<_Tp, _Alloc>::list(_InpIter __f, _InpIter __l, const allocator_type& __a, 1141 typename enable_if<__is_input_iterator<_InpIter>::value>::type*) 1142 : base(__a) 1143{ 1144#if _LIBCPP_DEBUG_LEVEL >= 2 1145 __get_db()->__insert_c(this); 1146#endif 1147 for (; __f != __l; ++__f) 1148 push_back(*__f); 1149} 1150 1151template <class _Tp, class _Alloc> 1152list<_Tp, _Alloc>::list(const list& __c) 1153 : base(allocator_type( 1154 __node_alloc_traits::select_on_container_copy_construction( 1155 __c.__node_alloc()))) 1156{ 1157#if _LIBCPP_DEBUG_LEVEL >= 2 1158 __get_db()->__insert_c(this); 1159#endif 1160 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) 1161 push_back(*__i); 1162} 1163 1164template <class _Tp, class _Alloc> 1165list<_Tp, _Alloc>::list(const list& __c, const allocator_type& __a) 1166 : base(__a) 1167{ 1168#if _LIBCPP_DEBUG_LEVEL >= 2 1169 __get_db()->__insert_c(this); 1170#endif 1171 for (const_iterator __i = __c.begin(), __e = __c.end(); __i != __e; ++__i) 1172 push_back(*__i); 1173} 1174 1175#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1176 1177template <class _Tp, class _Alloc> 1178list<_Tp, _Alloc>::list(initializer_list<value_type> __il, const allocator_type& __a) 1179 : base(__a) 1180{ 1181#if _LIBCPP_DEBUG_LEVEL >= 2 1182 __get_db()->__insert_c(this); 1183#endif 1184 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), 1185 __e = __il.end(); __i != __e; ++__i) 1186 push_back(*__i); 1187} 1188 1189template <class _Tp, class _Alloc> 1190list<_Tp, _Alloc>::list(initializer_list<value_type> __il) 1191{ 1192#if _LIBCPP_DEBUG_LEVEL >= 2 1193 __get_db()->__insert_c(this); 1194#endif 1195 for (typename initializer_list<value_type>::const_iterator __i = __il.begin(), 1196 __e = __il.end(); __i != __e; ++__i) 1197 push_back(*__i); 1198} 1199 1200#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS 1201 1202template <class _Tp, class _Alloc> 1203inline _LIBCPP_INLINE_VISIBILITY 1204list<_Tp, _Alloc>& 1205list<_Tp, _Alloc>::operator=(const list& __c) 1206{ 1207 if (this != &__c) 1208 { 1209 base::__copy_assign_alloc(__c); 1210 assign(__c.begin(), __c.end()); 1211 } 1212 return *this; 1213} 1214 1215#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1216 1217template <class _Tp, class _Alloc> 1218inline _LIBCPP_INLINE_VISIBILITY 1219list<_Tp, _Alloc>::list(list&& __c) 1220 _NOEXCEPT_(is_nothrow_move_constructible<__node_allocator>::value) 1221 : base(allocator_type(_VSTD::move(__c.__node_alloc()))) 1222{ 1223#if _LIBCPP_DEBUG_LEVEL >= 2 1224 __get_db()->__insert_c(this); 1225#endif 1226 splice(end(), __c); 1227} 1228 1229template <class _Tp, class _Alloc> 1230inline _LIBCPP_INLINE_VISIBILITY 1231list<_Tp, _Alloc>::list(list&& __c, const allocator_type& __a) 1232 : base(__a) 1233{ 1234#if _LIBCPP_DEBUG_LEVEL >= 2 1235 __get_db()->__insert_c(this); 1236#endif 1237 if (__a == __c.get_allocator()) 1238 splice(end(), __c); 1239 else 1240 { 1241 typedef move_iterator<iterator> _Ip; 1242 assign(_Ip(__c.begin()), _Ip(__c.end())); 1243 } 1244} 1245 1246template <class _Tp, class _Alloc> 1247inline _LIBCPP_INLINE_VISIBILITY 1248list<_Tp, _Alloc>& 1249list<_Tp, _Alloc>::operator=(list&& __c) 1250 _NOEXCEPT_( 1251 __node_alloc_traits::propagate_on_container_move_assignment::value && 1252 is_nothrow_move_assignable<__node_allocator>::value) 1253{ 1254 __move_assign(__c, integral_constant<bool, 1255 __node_alloc_traits::propagate_on_container_move_assignment::value>()); 1256 return *this; 1257} 1258 1259template <class _Tp, class _Alloc> 1260void 1261list<_Tp, _Alloc>::__move_assign(list& __c, false_type) 1262{ 1263 if (base::__node_alloc() != __c.__node_alloc()) 1264 { 1265 typedef move_iterator<iterator> _Ip; 1266 assign(_Ip(__c.begin()), _Ip(__c.end())); 1267 } 1268 else 1269 __move_assign(__c, true_type()); 1270} 1271 1272template <class _Tp, class _Alloc> 1273void 1274list<_Tp, _Alloc>::__move_assign(list& __c, true_type) 1275 _NOEXCEPT_(is_nothrow_move_assignable<__node_allocator>::value) 1276{ 1277 clear(); 1278 base::__move_assign_alloc(__c); 1279 splice(end(), __c); 1280} 1281 1282#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1283 1284template <class _Tp, class _Alloc> 1285template <class _InpIter> 1286void 1287list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l, 1288 typename enable_if<__is_input_iterator<_InpIter>::value>::type*) 1289{ 1290 iterator __i = begin(); 1291 iterator __e = end(); 1292 for (; __f != __l && __i != __e; ++__f, ++__i) 1293 *__i = *__f; 1294 if (__i == __e) 1295 insert(__e, __f, __l); 1296 else 1297 erase(__i, __e); 1298} 1299 1300template <class _Tp, class _Alloc> 1301void 1302list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x) 1303{ 1304 iterator __i = begin(); 1305 iterator __e = end(); 1306 for (; __n > 0 && __i != __e; --__n, ++__i) 1307 *__i = __x; 1308 if (__i == __e) 1309 insert(__e, __n, __x); 1310 else 1311 erase(__i, __e); 1312} 1313 1314template <class _Tp, class _Alloc> 1315inline _LIBCPP_INLINE_VISIBILITY 1316_Alloc 1317list<_Tp, _Alloc>::get_allocator() const _NOEXCEPT 1318{ 1319 return allocator_type(base::__node_alloc()); 1320} 1321 1322template <class _Tp, class _Alloc> 1323typename list<_Tp, _Alloc>::iterator 1324list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) 1325{ 1326#if _LIBCPP_DEBUG_LEVEL >= 2 1327 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1328 "list::insert(iterator, x) called with an iterator not" 1329 " referring to this list"); 1330#endif 1331 __node_allocator& __na = base::__node_alloc(); 1332 typedef __allocator_destructor<__node_allocator> _Dp; 1333 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1334 __hold->__prev_ = 0; 1335 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1336 __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); 1337 ++base::__sz(); 1338#if _LIBCPP_DEBUG_LEVEL >= 2 1339 return iterator(__hold.release(), this); 1340#else 1341 return iterator(__hold.release()); 1342#endif 1343} 1344 1345template <class _Tp, class _Alloc> 1346typename list<_Tp, _Alloc>::iterator 1347list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& __x) 1348{ 1349#if _LIBCPP_DEBUG_LEVEL >= 2 1350 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1351 "list::insert(iterator, n, x) called with an iterator not" 1352 " referring to this list"); 1353 iterator __r(__p.__ptr_, this); 1354#else 1355 iterator __r(__p.__ptr_); 1356#endif 1357 if (__n > 0) 1358 { 1359 size_type __ds = 0; 1360 __node_allocator& __na = base::__node_alloc(); 1361 typedef __allocator_destructor<__node_allocator> _Dp; 1362 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1363 __hold->__prev_ = 0; 1364 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1365 ++__ds; 1366#if _LIBCPP_DEBUG_LEVEL >= 2 1367 __r = iterator(__hold.get(), this); 1368#else 1369 __r = iterator(__hold.get()); 1370#endif 1371 __hold.release(); 1372 iterator __e = __r; 1373#ifndef _LIBCPP_NO_EXCEPTIONS 1374 try 1375 { 1376#endif // _LIBCPP_NO_EXCEPTIONS 1377 for (--__n; __n != 0; --__n, ++__e, ++__ds) 1378 { 1379 __hold.reset(__node_alloc_traits::allocate(__na, 1)); 1380 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1381 __e.__ptr_->__next_ = __hold.get(); 1382 __hold->__prev_ = __e.__ptr_; 1383 __hold.release(); 1384 } 1385#ifndef _LIBCPP_NO_EXCEPTIONS 1386 } 1387 catch (...) 1388 { 1389 while (true) 1390 { 1391 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 1392 __node_pointer __prev = __e.__ptr_->__prev_; 1393 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); 1394 if (__prev == 0) 1395 break; 1396#if _LIBCPP_DEBUG_LEVEL >= 2 1397 __e = iterator(__prev, this); 1398#else 1399 __e = iterator(__prev); 1400#endif 1401 } 1402 throw; 1403 } 1404#endif // _LIBCPP_NO_EXCEPTIONS 1405 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); 1406 base::__sz() += __ds; 1407 } 1408 return __r; 1409} 1410 1411template <class _Tp, class _Alloc> 1412template <class _InpIter> 1413typename list<_Tp, _Alloc>::iterator 1414list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, 1415 typename enable_if<__is_input_iterator<_InpIter>::value>::type*) 1416{ 1417#if _LIBCPP_DEBUG_LEVEL >= 2 1418 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1419 "list::insert(iterator, range) called with an iterator not" 1420 " referring to this list"); 1421 iterator __r(__p.__ptr_, this); 1422#else 1423 iterator __r(__p.__ptr_); 1424#endif 1425 if (__f != __l) 1426 { 1427 size_type __ds = 0; 1428 __node_allocator& __na = base::__node_alloc(); 1429 typedef __allocator_destructor<__node_allocator> _Dp; 1430 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1431 __hold->__prev_ = 0; 1432 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); 1433 ++__ds; 1434#if _LIBCPP_DEBUG_LEVEL >= 2 1435 __r = iterator(__hold.get(), this); 1436#else 1437 __r = iterator(__hold.get()); 1438#endif 1439 __hold.release(); 1440 iterator __e = __r; 1441#ifndef _LIBCPP_NO_EXCEPTIONS 1442 try 1443 { 1444#endif // _LIBCPP_NO_EXCEPTIONS 1445 for (++__f; __f != __l; ++__f, ++__e, ++__ds) 1446 { 1447 __hold.reset(__node_alloc_traits::allocate(__na, 1)); 1448 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), *__f); 1449 __e.__ptr_->__next_ = __hold.get(); 1450 __hold->__prev_ = __e.__ptr_; 1451 __hold.release(); 1452 } 1453#ifndef _LIBCPP_NO_EXCEPTIONS 1454 } 1455 catch (...) 1456 { 1457 while (true) 1458 { 1459 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 1460 __node_pointer __prev = __e.__ptr_->__prev_; 1461 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); 1462 if (__prev == 0) 1463 break; 1464#if _LIBCPP_DEBUG_LEVEL >= 2 1465 __e = iterator(__prev, this); 1466#else 1467 __e = iterator(__prev); 1468#endif 1469 } 1470 throw; 1471 } 1472#endif // _LIBCPP_NO_EXCEPTIONS 1473 __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); 1474 base::__sz() += __ds; 1475 } 1476 return __r; 1477} 1478 1479template <class _Tp, class _Alloc> 1480void 1481list<_Tp, _Alloc>::push_front(const value_type& __x) 1482{ 1483 __node_allocator& __na = base::__node_alloc(); 1484 typedef __allocator_destructor<__node_allocator> _Dp; 1485 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1486 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1487 __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); 1488 ++base::__sz(); 1489 __hold.release(); 1490} 1491 1492template <class _Tp, class _Alloc> 1493void 1494list<_Tp, _Alloc>::push_back(const value_type& __x) 1495{ 1496 __node_allocator& __na = base::__node_alloc(); 1497 typedef __allocator_destructor<__node_allocator> _Dp; 1498 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1499 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1500 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: 1501 pointer_to(base::__end_)), __hold.get(), __hold.get()); 1502 ++base::__sz(); 1503 __hold.release(); 1504} 1505 1506#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 1507 1508template <class _Tp, class _Alloc> 1509void 1510list<_Tp, _Alloc>::push_front(value_type&& __x) 1511{ 1512 __node_allocator& __na = base::__node_alloc(); 1513 typedef __allocator_destructor<__node_allocator> _Dp; 1514 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1515 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); 1516 __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); 1517 ++base::__sz(); 1518 __hold.release(); 1519} 1520 1521template <class _Tp, class _Alloc> 1522void 1523list<_Tp, _Alloc>::push_back(value_type&& __x) 1524{ 1525 __node_allocator& __na = base::__node_alloc(); 1526 typedef __allocator_destructor<__node_allocator> _Dp; 1527 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1528 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); 1529 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: 1530 pointer_to(base::__end_)), __hold.get(), __hold.get()); 1531 ++base::__sz(); 1532 __hold.release(); 1533} 1534 1535#ifndef _LIBCPP_HAS_NO_VARIADICS 1536 1537template <class _Tp, class _Alloc> 1538template <class... _Args> 1539void 1540list<_Tp, _Alloc>::emplace_front(_Args&&... __args) 1541{ 1542 __node_allocator& __na = base::__node_alloc(); 1543 typedef __allocator_destructor<__node_allocator> _Dp; 1544 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1545 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); 1546 __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); 1547 ++base::__sz(); 1548 __hold.release(); 1549} 1550 1551template <class _Tp, class _Alloc> 1552template <class... _Args> 1553void 1554list<_Tp, _Alloc>::emplace_back(_Args&&... __args) 1555{ 1556 __node_allocator& __na = base::__node_alloc(); 1557 typedef __allocator_destructor<__node_allocator> _Dp; 1558 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1559 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); 1560 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: 1561 pointer_to(base::__end_)), __hold.get(), __hold.get()); 1562 ++base::__sz(); 1563 __hold.release(); 1564} 1565 1566template <class _Tp, class _Alloc> 1567template <class... _Args> 1568typename list<_Tp, _Alloc>::iterator 1569list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) 1570{ 1571#if _LIBCPP_DEBUG_LEVEL >= 2 1572 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1573 "list::emplace(iterator, args...) called with an iterator not" 1574 " referring to this list"); 1575#endif 1576 __node_allocator& __na = base::__node_alloc(); 1577 typedef __allocator_destructor<__node_allocator> _Dp; 1578 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1579 __hold->__prev_ = 0; 1580 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); 1581 __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); 1582 ++base::__sz(); 1583#if _LIBCPP_DEBUG_LEVEL >= 2 1584 return iterator(__hold.release(), this); 1585#else 1586 return iterator(__hold.release()); 1587#endif 1588} 1589 1590#endif // _LIBCPP_HAS_NO_VARIADICS 1591 1592template <class _Tp, class _Alloc> 1593typename list<_Tp, _Alloc>::iterator 1594list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) 1595{ 1596#if _LIBCPP_DEBUG_LEVEL >= 2 1597 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1598 "list::insert(iterator, x) called with an iterator not" 1599 " referring to this list"); 1600#endif 1601 __node_allocator& __na = base::__node_alloc(); 1602 typedef __allocator_destructor<__node_allocator> _Dp; 1603 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1604 __hold->__prev_ = 0; 1605 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); 1606 __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); 1607 ++base::__sz(); 1608#if _LIBCPP_DEBUG_LEVEL >= 2 1609 return iterator(__hold.release(), this); 1610#else 1611 return iterator(__hold.release()); 1612#endif 1613} 1614 1615#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 1616 1617template <class _Tp, class _Alloc> 1618void 1619list<_Tp, _Alloc>::pop_front() 1620{ 1621 _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); 1622 __node_allocator& __na = base::__node_alloc(); 1623 __node_pointer __n = base::__end_.__next_; 1624 base::__unlink_nodes(__n, __n); 1625 --base::__sz(); 1626#if _LIBCPP_DEBUG_LEVEL >= 2 1627 __c_node* __c = __get_db()->__find_c_and_lock(this); 1628 for (__i_node** __p = __c->end_; __p != __c->beg_; ) 1629 { 1630 --__p; 1631 iterator* __i = static_cast<iterator*>((*__p)->__i_); 1632 if (__i->__ptr_ == __n) 1633 { 1634 (*__p)->__c_ = nullptr; 1635 if (--__c->end_ != __p) 1636 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 1637 } 1638 } 1639 __get_db()->unlock(); 1640#endif 1641 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); 1642 __node_alloc_traits::deallocate(__na, __n, 1); 1643} 1644 1645template <class _Tp, class _Alloc> 1646void 1647list<_Tp, _Alloc>::pop_back() 1648{ 1649 _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list"); 1650 __node_allocator& __na = base::__node_alloc(); 1651 __node_pointer __n = base::__end_.__prev_; 1652 base::__unlink_nodes(__n, __n); 1653 --base::__sz(); 1654#if _LIBCPP_DEBUG_LEVEL >= 2 1655 __c_node* __c = __get_db()->__find_c_and_lock(this); 1656 for (__i_node** __p = __c->end_; __p != __c->beg_; ) 1657 { 1658 --__p; 1659 iterator* __i = static_cast<iterator*>((*__p)->__i_); 1660 if (__i->__ptr_ == __n) 1661 { 1662 (*__p)->__c_ = nullptr; 1663 if (--__c->end_ != __p) 1664 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 1665 } 1666 } 1667 __get_db()->unlock(); 1668#endif 1669 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); 1670 __node_alloc_traits::deallocate(__na, __n, 1); 1671} 1672 1673template <class _Tp, class _Alloc> 1674typename list<_Tp, _Alloc>::iterator 1675list<_Tp, _Alloc>::erase(const_iterator __p) 1676{ 1677#if _LIBCPP_DEBUG_LEVEL >= 2 1678 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1679 "list::erase(iterator) called with an iterator not" 1680 " referring to this list"); 1681#endif 1682 _LIBCPP_ASSERT(__p != end(), 1683 "list::erase(iterator) called with a non-dereferenceable iterator"); 1684 __node_allocator& __na = base::__node_alloc(); 1685 __node_pointer __n = __p.__ptr_; 1686 __node_pointer __r = __n->__next_; 1687 base::__unlink_nodes(__n, __n); 1688 --base::__sz(); 1689#if _LIBCPP_DEBUG_LEVEL >= 2 1690 __c_node* __c = __get_db()->__find_c_and_lock(this); 1691 for (__i_node** __p = __c->end_; __p != __c->beg_; ) 1692 { 1693 --__p; 1694 iterator* __i = static_cast<iterator*>((*__p)->__i_); 1695 if (__i->__ptr_ == __n) 1696 { 1697 (*__p)->__c_ = nullptr; 1698 if (--__c->end_ != __p) 1699 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 1700 } 1701 } 1702 __get_db()->unlock(); 1703#endif 1704 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); 1705 __node_alloc_traits::deallocate(__na, __n, 1); 1706#if _LIBCPP_DEBUG_LEVEL >= 2 1707 return iterator(__r, this); 1708#else 1709 return iterator(__r); 1710#endif 1711} 1712 1713template <class _Tp, class _Alloc> 1714typename list<_Tp, _Alloc>::iterator 1715list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) 1716{ 1717#if _LIBCPP_DEBUG_LEVEL >= 2 1718 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this, 1719 "list::erase(iterator, iterator) called with an iterator not" 1720 " referring to this list"); 1721#endif 1722 if (__f != __l) 1723 { 1724 __node_allocator& __na = base::__node_alloc(); 1725 base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); 1726 while (__f != __l) 1727 { 1728 __node_pointer __n = __f.__ptr_; 1729 ++__f; 1730 --base::__sz(); 1731#if _LIBCPP_DEBUG_LEVEL >= 2 1732 __c_node* __c = __get_db()->__find_c_and_lock(this); 1733 for (__i_node** __p = __c->end_; __p != __c->beg_; ) 1734 { 1735 --__p; 1736 iterator* __i = static_cast<iterator*>((*__p)->__i_); 1737 if (__i->__ptr_ == __n) 1738 { 1739 (*__p)->__c_ = nullptr; 1740 if (--__c->end_ != __p) 1741 memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*)); 1742 } 1743 } 1744 __get_db()->unlock(); 1745#endif 1746 __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); 1747 __node_alloc_traits::deallocate(__na, __n, 1); 1748 } 1749 } 1750#if _LIBCPP_DEBUG_LEVEL >= 2 1751 return iterator(__l.__ptr_, this); 1752#else 1753 return iterator(__l.__ptr_); 1754#endif 1755} 1756 1757template <class _Tp, class _Alloc> 1758void 1759list<_Tp, _Alloc>::resize(size_type __n) 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> _Dp; 1769 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1770 __hold->__prev_ = 0; 1771 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); 1772 ++__ds; 1773#if _LIBCPP_DEBUG_LEVEL >= 2 1774 iterator __r = iterator(__hold.release(), this); 1775#else 1776 iterator __r = iterator(__hold.release()); 1777#endif 1778 iterator __e = __r; 1779#ifndef _LIBCPP_NO_EXCEPTIONS 1780 try 1781 { 1782#endif // _LIBCPP_NO_EXCEPTIONS 1783 for (--__n; __n != 0; --__n, ++__e, ++__ds) 1784 { 1785 __hold.reset(__node_alloc_traits::allocate(__na, 1)); 1786 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_)); 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 { 1797 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 1798 __node_pointer __prev = __e.__ptr_->__prev_; 1799 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); 1800 if (__prev == 0) 1801 break; 1802#if _LIBCPP_DEBUG_LEVEL >= 2 1803 __e = iterator(__prev, this); 1804#else 1805 __e = iterator(__prev); 1806#endif 1807 } 1808 throw; 1809 } 1810#endif // _LIBCPP_NO_EXCEPTIONS 1811 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: 1812 pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_); 1813 base::__sz() += __ds; 1814 } 1815} 1816 1817template <class _Tp, class _Alloc> 1818void 1819list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) 1820{ 1821 if (__n < base::__sz()) 1822 erase(__iterator(__n), end()); 1823 else if (__n > base::__sz()) 1824 { 1825 __n -= base::__sz(); 1826 size_type __ds = 0; 1827 __node_allocator& __na = base::__node_alloc(); 1828 typedef __allocator_destructor<__node_allocator> _Dp; 1829 unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); 1830 __hold->__prev_ = 0; 1831 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1832 ++__ds; 1833#if _LIBCPP_DEBUG_LEVEL >= 2 1834 iterator __r = iterator(__hold.release(), this); 1835#else 1836 iterator __r = iterator(__hold.release()); 1837#endif 1838 iterator __e = __r; 1839#ifndef _LIBCPP_NO_EXCEPTIONS 1840 try 1841 { 1842#endif // _LIBCPP_NO_EXCEPTIONS 1843 for (--__n; __n != 0; --__n, ++__e, ++__ds) 1844 { 1845 __hold.reset(__node_alloc_traits::allocate(__na, 1)); 1846 __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); 1847 __e.__ptr_->__next_ = __hold.get(); 1848 __hold->__prev_ = __e.__ptr_; 1849 __hold.release(); 1850 } 1851#ifndef _LIBCPP_NO_EXCEPTIONS 1852 } 1853 catch (...) 1854 { 1855 while (true) 1856 { 1857 __node_alloc_traits::destroy(__na, _VSTD::addressof(*__e)); 1858 __node_pointer __prev = __e.__ptr_->__prev_; 1859 __node_alloc_traits::deallocate(__na, __e.__ptr_, 1); 1860 if (__prev == 0) 1861 break; 1862#if _LIBCPP_DEBUG_LEVEL >= 2 1863 __e = iterator(__prev, this); 1864#else 1865 __e = iterator(__prev); 1866#endif 1867 } 1868 throw; 1869 } 1870#endif // _LIBCPP_NO_EXCEPTIONS 1871 __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: 1872 pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_); 1873 base::__sz() += __ds; 1874 } 1875} 1876 1877template <class _Tp, class _Alloc> 1878void 1879list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) 1880{ 1881 _LIBCPP_ASSERT(this != &__c, 1882 "list::splice(iterator, list) called with this == &list"); 1883#if _LIBCPP_DEBUG_LEVEL >= 2 1884 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1885 "list::splice(iterator, list) called with an iterator not" 1886 " referring to this list"); 1887#endif 1888 if (!__c.empty()) 1889 { 1890 __node_pointer __f = __c.__end_.__next_; 1891 __node_pointer __l = __c.__end_.__prev_; 1892 base::__unlink_nodes(__f, __l); 1893 __link_nodes(__p.__ptr_, __f, __l); 1894 base::__sz() += __c.__sz(); 1895 __c.__sz() = 0; 1896#if _LIBCPP_DEBUG_LEVEL >= 2 1897 __libcpp_db* __db = __get_db(); 1898 __c_node* __cn1 = __db->__find_c_and_lock(this); 1899 __c_node* __cn2 = __db->__find_c(&__c); 1900 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 1901 { 1902 --__p; 1903 iterator* __i = static_cast<iterator*>((*__p)->__i_); 1904 if (__i->__ptr_ != static_cast<__node_pointer>( 1905 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) 1906 { 1907 __cn1->__add(*__p); 1908 (*__p)->__c_ = __cn1; 1909 if (--__cn2->end_ != __p) 1910 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 1911 } 1912 } 1913 __db->unlock(); 1914#endif 1915 } 1916} 1917 1918template <class _Tp, class _Alloc> 1919void 1920list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) 1921{ 1922#if _LIBCPP_DEBUG_LEVEL >= 2 1923 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1924 "list::splice(iterator, list, iterator) called with first iterator not" 1925 " referring to this list"); 1926 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__i) == &__c, 1927 "list::splice(iterator, list, iterator) called with second iterator not" 1928 " referring to list argument"); 1929 _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(&__i), 1930 "list::splice(iterator, list, iterator) called with second iterator not" 1931 " derefereceable"); 1932#endif 1933 if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) 1934 { 1935 __node_pointer __f = __i.__ptr_; 1936 base::__unlink_nodes(__f, __f); 1937 __link_nodes(__p.__ptr_, __f, __f); 1938 --__c.__sz(); 1939 ++base::__sz(); 1940#if _LIBCPP_DEBUG_LEVEL >= 2 1941 __libcpp_db* __db = __get_db(); 1942 __c_node* __cn1 = __db->__find_c_and_lock(this); 1943 __c_node* __cn2 = __db->__find_c(&__c); 1944 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 1945 { 1946 --__p; 1947 iterator* __j = static_cast<iterator*>((*__p)->__i_); 1948 if (__j->__ptr_ == __f) 1949 { 1950 __cn1->__add(*__p); 1951 (*__p)->__c_ = __cn1; 1952 if (--__cn2->end_ != __p) 1953 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 1954 } 1955 } 1956 __db->unlock(); 1957#endif 1958 } 1959} 1960 1961template <class _Tp, class _Alloc> 1962void 1963list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, const_iterator __l) 1964{ 1965#if _LIBCPP_DEBUG_LEVEL >= 2 1966 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, 1967 "list::splice(iterator, list, iterator, iterator) called with first iterator not" 1968 " referring to this list"); 1969 _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == &__c, 1970 "list::splice(iterator, list, iterator, iterator) called with second iterator not" 1971 " referring to list argument"); 1972 if (this == &__c) 1973 { 1974 for (const_iterator __i = __f; __i != __l; ++__i) 1975 _LIBCPP_ASSERT(__i != __p, 1976 "list::splice(iterator, list, iterator, iterator)" 1977 " called with the first iterator within the range" 1978 " of the second and third iterators"); 1979 } 1980#endif 1981 if (__f != __l) 1982 { 1983 if (this != &__c) 1984 { 1985 size_type __s = _VSTD::distance(__f, __l); 1986 __c.__sz() -= __s; 1987 base::__sz() += __s; 1988 } 1989 __node_pointer __first = __f.__ptr_; 1990 --__l; 1991 __node_pointer __last = __l.__ptr_; 1992 base::__unlink_nodes(__first, __last); 1993 __link_nodes(__p.__ptr_, __first, __last); 1994#if _LIBCPP_DEBUG_LEVEL >= 2 1995 __libcpp_db* __db = __get_db(); 1996 __c_node* __cn1 = __db->__find_c_and_lock(this); 1997 __c_node* __cn2 = __db->__find_c(&__c); 1998 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 1999 { 2000 --__p; 2001 iterator* __j = static_cast<iterator*>((*__p)->__i_); 2002 for (__node_pointer __k = __f.__ptr_; 2003 __k != __l.__ptr_; __k = __k->__next_) 2004 { 2005 if (__j->__ptr_ == __k) 2006 { 2007 __cn1->__add(*__p); 2008 (*__p)->__c_ = __cn1; 2009 if (--__cn2->end_ != __p) 2010 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 2011 } 2012 } 2013 } 2014 __db->unlock(); 2015#endif 2016 } 2017} 2018 2019template <class _Tp, class _Alloc> 2020void 2021list<_Tp, _Alloc>::remove(const value_type& __x) 2022{ 2023 for (iterator __i = begin(), __e = end(); __i != __e;) 2024 { 2025 if (*__i == __x) 2026 { 2027 iterator __j = _VSTD::next(__i); 2028 for (; __j != __e && *__j == __x; ++__j) 2029 ; 2030 __i = erase(__i, __j); 2031 } 2032 else 2033 ++__i; 2034 } 2035} 2036 2037template <class _Tp, class _Alloc> 2038template <class _Pred> 2039void 2040list<_Tp, _Alloc>::remove_if(_Pred __pred) 2041{ 2042 for (iterator __i = begin(), __e = end(); __i != __e;) 2043 { 2044 if (__pred(*__i)) 2045 { 2046 iterator __j = _VSTD::next(__i); 2047 for (; __j != __e && __pred(*__j); ++__j) 2048 ; 2049 __i = erase(__i, __j); 2050 } 2051 else 2052 ++__i; 2053 } 2054} 2055 2056template <class _Tp, class _Alloc> 2057inline _LIBCPP_INLINE_VISIBILITY 2058void 2059list<_Tp, _Alloc>::unique() 2060{ 2061 unique(__equal_to<value_type>()); 2062} 2063 2064template <class _Tp, class _Alloc> 2065template <class _BinaryPred> 2066void 2067list<_Tp, _Alloc>::unique(_BinaryPred __binary_pred) 2068{ 2069 for (iterator __i = begin(), __e = end(); __i != __e;) 2070 { 2071 iterator __j = _VSTD::next(__i); 2072 for (; __j != __e && __binary_pred(*__i, *__j); ++__j) 2073 ; 2074 if (++__i != __j) 2075 __i = erase(__i, __j); 2076 } 2077} 2078 2079template <class _Tp, class _Alloc> 2080inline _LIBCPP_INLINE_VISIBILITY 2081void 2082list<_Tp, _Alloc>::merge(list& __c) 2083{ 2084 merge(__c, __less<value_type>()); 2085} 2086 2087template <class _Tp, class _Alloc> 2088template <class _Comp> 2089void 2090list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) 2091{ 2092 if (this != &__c) 2093 { 2094 iterator __f1 = begin(); 2095 iterator __e1 = end(); 2096 iterator __f2 = __c.begin(); 2097 iterator __e2 = __c.end(); 2098 while (__f1 != __e1 && __f2 != __e2) 2099 { 2100 if (__comp(*__f2, *__f1)) 2101 { 2102 size_type __ds = 1; 2103 iterator __m2 = _VSTD::next(__f2); 2104 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2, ++__ds) 2105 ; 2106 base::__sz() += __ds; 2107 __c.__sz() -= __ds; 2108 __node_pointer __f = __f2.__ptr_; 2109 __node_pointer __l = __m2.__ptr_->__prev_; 2110 __f2 = __m2; 2111 base::__unlink_nodes(__f, __l); 2112 __m2 = _VSTD::next(__f1); 2113 __link_nodes(__f1.__ptr_, __f, __l); 2114 __f1 = __m2; 2115 } 2116 else 2117 ++__f1; 2118 } 2119 splice(__e1, __c); 2120#if _LIBCPP_DEBUG_LEVEL >= 2 2121 __libcpp_db* __db = __get_db(); 2122 __c_node* __cn1 = __db->__find_c_and_lock(this); 2123 __c_node* __cn2 = __db->__find_c(&__c); 2124 for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;) 2125 { 2126 --__p; 2127 iterator* __i = static_cast<iterator*>((*__p)->__i_); 2128 if (__i->__ptr_ != static_cast<__node_pointer>( 2129 pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) 2130 { 2131 __cn1->__add(*__p); 2132 (*__p)->__c_ = __cn1; 2133 if (--__cn2->end_ != __p) 2134 memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*)); 2135 } 2136 } 2137 __db->unlock(); 2138#endif 2139 } 2140} 2141 2142template <class _Tp, class _Alloc> 2143inline _LIBCPP_INLINE_VISIBILITY 2144void 2145list<_Tp, _Alloc>::sort() 2146{ 2147 sort(__less<value_type>()); 2148} 2149 2150template <class _Tp, class _Alloc> 2151template <class _Comp> 2152inline _LIBCPP_INLINE_VISIBILITY 2153void 2154list<_Tp, _Alloc>::sort(_Comp __comp) 2155{ 2156 __sort(begin(), end(), base::__sz(), __comp); 2157} 2158 2159template <class _Tp, class _Alloc> 2160template <class _Comp> 2161typename list<_Tp, _Alloc>::iterator 2162list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp) 2163{ 2164 switch (__n) 2165 { 2166 case 0: 2167 case 1: 2168 return __f1; 2169 case 2: 2170 if (__comp(*--__e2, *__f1)) 2171 { 2172 __node_pointer __f = __e2.__ptr_; 2173 base::__unlink_nodes(__f, __f); 2174 __link_nodes(__f1.__ptr_, __f, __f); 2175 return __e2; 2176 } 2177 return __f1; 2178 } 2179 size_type __n2 = __n / 2; 2180 iterator __e1 = _VSTD::next(__f1, __n2); 2181 iterator __r = __f1 = __sort(__f1, __e1, __n2, __comp); 2182 iterator __f2 = __e1 = __sort(__e1, __e2, __n - __n2, __comp); 2183 if (__comp(*__f2, *__f1)) 2184 { 2185 iterator __m2 = _VSTD::next(__f2); 2186 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) 2187 ; 2188 __node_pointer __f = __f2.__ptr_; 2189 __node_pointer __l = __m2.__ptr_->__prev_; 2190 __r = __f2; 2191 __e1 = __f2 = __m2; 2192 base::__unlink_nodes(__f, __l); 2193 __m2 = _VSTD::next(__f1); 2194 __link_nodes(__f1.__ptr_, __f, __l); 2195 __f1 = __m2; 2196 } 2197 else 2198 ++__f1; 2199 while (__f1 != __e1 && __f2 != __e2) 2200 { 2201 if (__comp(*__f2, *__f1)) 2202 { 2203 iterator __m2 = _VSTD::next(__f2); 2204 for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) 2205 ; 2206 __node_pointer __f = __f2.__ptr_; 2207 __node_pointer __l = __m2.__ptr_->__prev_; 2208 if (__e1 == __f2) 2209 __e1 = __m2; 2210 __f2 = __m2; 2211 base::__unlink_nodes(__f, __l); 2212 __m2 = _VSTD::next(__f1); 2213 __link_nodes(__f1.__ptr_, __f, __l); 2214 __f1 = __m2; 2215 } 2216 else 2217 ++__f1; 2218 } 2219 return __r; 2220} 2221 2222template <class _Tp, class _Alloc> 2223void 2224list<_Tp, _Alloc>::reverse() _NOEXCEPT 2225{ 2226 if (base::__sz() > 1) 2227 { 2228 iterator __e = end(); 2229 for (iterator __i = begin(); __i.__ptr_ != __e.__ptr_;) 2230 { 2231 _VSTD::swap(__i.__ptr_->__prev_, __i.__ptr_->__next_); 2232 __i.__ptr_ = __i.__ptr_->__prev_; 2233 } 2234 _VSTD::swap(__e.__ptr_->__prev_, __e.__ptr_->__next_); 2235 } 2236} 2237 2238template <class _Tp, class _Alloc> 2239bool 2240list<_Tp, _Alloc>::__invariants() const 2241{ 2242 return size() == _VSTD::distance(begin(), end()); 2243} 2244 2245#if _LIBCPP_DEBUG_LEVEL >= 2 2246 2247template <class _Tp, class _Alloc> 2248bool 2249list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const 2250{ 2251 return __i->__ptr_ != static_cast<__node_pointer>( 2252 pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_))); 2253} 2254 2255template <class _Tp, class _Alloc> 2256bool 2257list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const 2258{ 2259 return !empty() && __i->__ptr_ != base::__end_.__next_; 2260} 2261 2262template <class _Tp, class _Alloc> 2263bool 2264list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const 2265{ 2266 return false; 2267} 2268 2269template <class _Tp, class _Alloc> 2270bool 2271list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const 2272{ 2273 return false; 2274} 2275 2276#endif // _LIBCPP_DEBUG_LEVEL >= 2 2277 2278template <class _Tp, class _Alloc> 2279inline _LIBCPP_INLINE_VISIBILITY 2280bool 2281operator==(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 2282{ 2283 return __x.size() == __y.size() && _VSTD::equal(__x.begin(), __x.end(), __y.begin()); 2284} 2285 2286template <class _Tp, class _Alloc> 2287inline _LIBCPP_INLINE_VISIBILITY 2288bool 2289operator< (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 2290{ 2291 return _VSTD::lexicographical_compare(__x.begin(), __x.end(), __y.begin(), __y.end()); 2292} 2293 2294template <class _Tp, class _Alloc> 2295inline _LIBCPP_INLINE_VISIBILITY 2296bool 2297operator!=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 2298{ 2299 return !(__x == __y); 2300} 2301 2302template <class _Tp, class _Alloc> 2303inline _LIBCPP_INLINE_VISIBILITY 2304bool 2305operator> (const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 2306{ 2307 return __y < __x; 2308} 2309 2310template <class _Tp, class _Alloc> 2311inline _LIBCPP_INLINE_VISIBILITY 2312bool 2313operator>=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 2314{ 2315 return !(__x < __y); 2316} 2317 2318template <class _Tp, class _Alloc> 2319inline _LIBCPP_INLINE_VISIBILITY 2320bool 2321operator<=(const list<_Tp, _Alloc>& __x, const list<_Tp, _Alloc>& __y) 2322{ 2323 return !(__y < __x); 2324} 2325 2326template <class _Tp, class _Alloc> 2327inline _LIBCPP_INLINE_VISIBILITY 2328void 2329swap(list<_Tp, _Alloc>& __x, list<_Tp, _Alloc>& __y) 2330 _NOEXCEPT_(_NOEXCEPT_(__x.swap(__y))) 2331{ 2332 __x.swap(__y); 2333} 2334 2335_LIBCPP_END_NAMESPACE_STD 2336 2337#endif // _LIBCPP_LIST 2338