diff options
Diffstat (limited to 'system/include/libcxx/list')
-rw-r--r-- | system/include/libcxx/list | 270 |
1 files changed, 165 insertions, 105 deletions
diff --git a/system/include/libcxx/list b/system/include/libcxx/list index 06904d96..4b1272a8 100644 --- a/system/include/libcxx/list +++ b/system/include/libcxx/list @@ -178,6 +178,12 @@ template <class T, class Alloc> #include <__undef_min_max> +#ifdef _LIBCPP_DEBUG2 +# include <__debug> +#else +# define _LIBCPP_ASSERT(x, m) ((void)0) +#endif + #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) #pragma GCC system_header #endif @@ -196,13 +202,20 @@ struct __list_node_base rebind<__list_node<_Tp, _VoidPtr> >::other pointer; #endif + typedef typename pointer_traits<_VoidPtr>::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind<__list_node_base> __base_pointer; +#else + rebind<__list_node_base>::other __base_pointer; +#endif + pointer __prev_; pointer __next_; _LIBCPP_INLINE_VISIBILITY __list_node_base() - : __prev_(static_cast<pointer>(this)), - __next_(static_cast<pointer>(this)) + : __prev_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))), + __next_(static_cast<pointer>(pointer_traits<__base_pointer>::pointer_to(*this))) {} }; @@ -260,7 +273,7 @@ public: typedef typename pointer_traits<pointer>::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY - __list_iterator() _NOEXCEPT + __list_iterator() _NOEXCEPT : __ptr_(nullptr) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); @@ -305,7 +318,14 @@ public: return __ptr_->__value_; } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &(operator*());} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__ptr_->__value_); + } _LIBCPP_INLINE_VISIBILITY __list_iterator& operator++() @@ -336,10 +356,6 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __list_iterator& __x, const __list_iterator& __y) { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), - "Attempted to compare non-comparable list::iterator"); -#endif return __x.__ptr_ == __y.__ptr_; } friend _LIBCPP_INLINE_VISIBILITY @@ -352,9 +368,9 @@ class _LIBCPP_TYPE_VIS __list_const_iterator { typedef typename pointer_traits<_VoidPtr>::template #ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES - rebind<const __list_node<_Tp, _VoidPtr> > __node_pointer; + rebind<__list_node<_Tp, _VoidPtr> > __node_pointer; #else - rebind<const __list_node<_Tp, _VoidPtr> >::other __node_pointer; + rebind<__list_node<_Tp, _VoidPtr> >::other __node_pointer; #endif __node_pointer __ptr_; @@ -387,14 +403,14 @@ public: typedef typename pointer_traits<pointer>::difference_type difference_type; _LIBCPP_INLINE_VISIBILITY - __list_const_iterator() _NOEXCEPT + __list_const_iterator() _NOEXCEPT : __ptr_(nullptr) { #if _LIBCPP_DEBUG_LEVEL >= 2 __get_db()->__insert_i(this); #endif } _LIBCPP_INLINE_VISIBILITY - __list_const_iterator(__list_iterator<_Tp, _VoidPtr> __p) _NOEXCEPT + __list_const_iterator(const __list_iterator<_Tp, _VoidPtr>& __p) _NOEXCEPT : __ptr_(__p.__ptr_) { #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -439,7 +455,14 @@ public: return __ptr_->__value_; } _LIBCPP_INLINE_VISIBILITY - pointer operator->() const {return &(operator*());} + pointer operator->() const + { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__dereferenceable(this), + "Attempted to dereference a non-dereferenceable list::iterator"); +#endif + return pointer_traits<pointer>::pointer_to(__ptr_->__value_); + } _LIBCPP_INLINE_VISIBILITY __list_const_iterator& operator++() @@ -470,10 +493,6 @@ public: friend _LIBCPP_INLINE_VISIBILITY bool operator==(const __list_const_iterator& __x, const __list_const_iterator& __y) { -#if _LIBCPP_DEBUG_LEVEL >= 2 - _LIBCPP_ASSERT(__get_const_db()->__comparable(&__x, &__y), - "Attempted to compare non-comparable list::const_iterator"); -#endif return __x.__ptr_ == __y.__ptr_; } friend _LIBCPP_INLINE_VISIBILITY @@ -505,11 +524,20 @@ protected: __node_allocator; typedef allocator_traits<__node_allocator> __node_alloc_traits; typedef typename __node_alloc_traits::pointer __node_pointer; - typedef typename __node_alloc_traits::const_pointer __node_const_pointer; + typedef typename __node_alloc_traits::pointer __node_const_pointer; typedef typename __alloc_traits::pointer pointer; typedef typename __alloc_traits::const_pointer const_pointer; typedef typename __alloc_traits::difference_type difference_type; + typedef typename __alloc_traits::template +#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES + rebind_alloc<__node_base> +#else + rebind_alloc<__node_base>::other +#endif + __node_base_allocator; + typedef typename allocator_traits<__node_base_allocator>::pointer __node_base_pointer; + __node_base __end_; __compressed_pair<size_type, __node_allocator> __size_alloc_; @@ -525,7 +553,7 @@ protected: const __node_allocator& __node_alloc() const _NOEXCEPT {return __size_alloc_.second();} - static void __unlink_nodes(__node_base& __f, __node_base& __l) _NOEXCEPT; + static void __unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT; __list_imp() _NOEXCEPT_(is_nothrow_default_constructible<__node_allocator>::value); @@ -557,18 +585,22 @@ protected: iterator end() _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 - return iterator(static_cast<__node_pointer>(&__end_), this); + return iterator(static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)), this); #else - return iterator(static_cast<__node_pointer>(&__end_)); + return iterator(static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_))); #endif } _LIBCPP_INLINE_VISIBILITY const_iterator end() const _NOEXCEPT { #if _LIBCPP_DEBUG_LEVEL >= 2 - return const_iterator(static_cast<__node_const_pointer>(&__end_), this); + return const_iterator(static_cast<__node_const_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_))), this); #else - return const_iterator(static_cast<__node_const_pointer>(&__end_)); + return const_iterator(static_cast<__node_const_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(__end_)))); #endif } @@ -637,11 +669,11 @@ private: template <class _Tp, class _Alloc> inline _LIBCPP_INLINE_VISIBILITY void -__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_base& __f, __node_base& __l) +__list_imp<_Tp, _Alloc>::__unlink_nodes(__node_pointer __f, __node_pointer __l) _NOEXCEPT { - __f.__prev_->__next_ = __l.__next_; - __l.__next_->__prev_ = __f.__prev_; + __f->__prev_->__next_ = __l->__next_; + __l->__next_->__prev_ = __f->__prev_; } template <class _Tp, class _Alloc> @@ -676,15 +708,16 @@ __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT { __node_allocator& __na = __node_alloc(); __node_pointer __f = __end_.__next_; - __node_pointer __l = static_cast<__node_pointer>(&__end_); - __unlink_nodes(*__f, *__l->__prev_); + __node_pointer __l = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)); + __unlink_nodes(__f, __l->__prev_); __sz() = 0; while (__f != __l) { - __node& __n = *__f; + __node_pointer __n = __f; __f = __f->__next_; - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } #if _LIBCPP_DEBUG_LEVEL >= 2 __c_node* __c = __get_db()->__find_c_and_lock(this); @@ -719,16 +752,20 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) swap(__sz(), __c.__sz()); swap(__end_, __c.__end_); if (__sz() == 0) - __end_.__next_ = __end_.__prev_ = &static_cast<__node&>(__end_); + __end_.__next_ = __end_.__prev_ = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)); else __end_.__prev_->__next_ = __end_.__next_->__prev_ - = &static_cast<__node&>(__end_); + = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_)); if (__c.__sz() == 0) __c.__end_.__next_ = __c.__end_.__prev_ - = &static_cast<__node&>(__c.__end_); + = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)); else __c.__end_.__prev_->__next_ = __c.__end_.__next_->__prev_ - = &static_cast<__node&>(__c.__end_); + = static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_)); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); @@ -740,7 +777,8 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) { --__p; const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->__ptr_ == static_cast<__node_pointer>(&__c.__end_)) + if (__i->__ptr_ == static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) { __cn2->__add(*__p); if (--__cn1->end_ != __p) @@ -753,7 +791,8 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c) { --__p; const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_); - if (__i->__ptr_ == static_cast<__node_pointer>(&__end_)) + if (__i->__ptr_ == static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__end_))) { __cn1->__add(*__p); if (--__cn2->end_ != __p) @@ -775,6 +814,8 @@ class _LIBCPP_TYPE_VIS list typedef typename base::__node_allocator __node_allocator; typedef typename base::__node_pointer __node_pointer; typedef typename base::__node_alloc_traits __node_alloc_traits; + typedef typename base::__node_base __node_base; + typedef typename base::__node_base_pointer __node_base_pointer; public: typedef _Tp value_type; @@ -1014,7 +1055,7 @@ public: #endif // _LIBCPP_DEBUG_LEVEL >= 2 private: - static void __link_nodes(__node& __p, __node& __f, __node& __l); + static void __link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l); iterator __iterator(size_type __n); template <class _Comp> static iterator __sort(iterator __f1, iterator __e2, size_type __n, _Comp& __comp); @@ -1028,12 +1069,12 @@ private: template <class _Tp, class _Alloc> inline _LIBCPP_INLINE_VISIBILITY void -list<_Tp, _Alloc>::__link_nodes(__node& __p, __node& __f, __node& __l) +list<_Tp, _Alloc>::__link_nodes(__node_pointer __p, __node_pointer __f, __node_pointer __l) { - __p.__prev_->__next_ = &__f; - __f.__prev_ = __p.__prev_; - __p.__prev_ = &__l; - __l.__next_ = &__p; + __p->__prev_->__next_ = __f; + __f->__prev_ = __p->__prev_; + __p->__prev_ = __l; + __l->__next_ = __p; } template <class _Tp, class _Alloc> @@ -1290,9 +1331,13 @@ list<_Tp, _Alloc>::insert(const_iterator __p, const value_type& __x) unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __hold->__prev_ = 0; __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); ++base::__sz(); +#if _LIBCPP_DEBUG_LEVEL >= 2 + return iterator(__hold.release(), this); +#else return iterator(__hold.release()); +#endif } template <class _Tp, class _Alloc> @@ -1303,9 +1348,9 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, n, x) called with an iterator not" " referring to this list"); - iterator __r(const_cast<__node_pointer>(__p.__ptr_), this); + iterator __r(__p.__ptr_, this); #else - iterator __r(const_cast<__node_pointer>(__p.__ptr_)); + iterator __r(__p.__ptr_); #endif if (__n > 0) { @@ -1355,7 +1400,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, size_type __n, const value_type& _ throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } return __r; @@ -1371,9 +1416,9 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, "list::insert(iterator, range) called with an iterator not" " referring to this list"); - iterator __r(const_cast<__node_pointer>(__p.__ptr_), this); + iterator __r(__p.__ptr_, this); #else - iterator __r(const_cast<__node_pointer>(__p.__ptr_)); + iterator __r(__p.__ptr_); #endif if (__f != __l) { @@ -1423,7 +1468,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, _InpIter __f, _InpIter __l, throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(__p.__ptr_, __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } return __r; @@ -1437,7 +1482,7 @@ list<_Tp, _Alloc>::push_front(const value_type& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); - __link_nodes(*base::__end_.__next_, *__hold, *__hold); + __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1450,7 +1495,8 @@ list<_Tp, _Alloc>::push_back(const value_type& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), __x); - __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1465,7 +1511,7 @@ list<_Tp, _Alloc>::push_front(value_type&& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); - __link_nodes(*base::__end_.__next_, *__hold, *__hold); + __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1478,7 +1524,8 @@ list<_Tp, _Alloc>::push_back(value_type&& __x) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); - __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1494,7 +1541,7 @@ list<_Tp, _Alloc>::emplace_front(_Args&&... __args) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); - __link_nodes(*base::__end_.__next_, *__hold, *__hold); + __link_nodes(base::__end_.__next_, __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1508,7 +1555,8 @@ list<_Tp, _Alloc>::emplace_back(_Args&&... __args) typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); - __link_nodes(static_cast<__node&>(base::__end_), *__hold, *__hold); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __hold.get(), __hold.get()); ++base::__sz(); __hold.release(); } @@ -1518,12 +1566,17 @@ template <class... _Args> typename list<_Tp, _Alloc>::iterator list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args) { +#if _LIBCPP_DEBUG_LEVEL >= 2 + _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__p) == this, + "list::emplace(iterator, args...) called with an iterator not" + " referring to this list"); +#endif __node_allocator& __na = base::__node_alloc(); typedef __allocator_destructor<__node_allocator> _Dp; unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __hold->__prev_ = 0; __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...); - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__hold.release(), this); @@ -1548,7 +1601,7 @@ list<_Tp, _Alloc>::insert(const_iterator __p, value_type&& __x) unique_ptr<__node, _Dp> __hold(__node_alloc_traits::allocate(__na, 1), _Dp(__na, 1)); __hold->__prev_ = 0; __node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::move(__x)); - __link_nodes(const_cast<__node&>(*__p.__ptr_), *__hold, *__hold); + __link_nodes(__p.__ptr_, __hold.get(), __hold.get()); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__hold.release(), this); @@ -1565,7 +1618,7 @@ list<_Tp, _Alloc>::pop_front() { _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); __node_allocator& __na = base::__node_alloc(); - __node& __n = *base::__end_.__next_; + __node_pointer __n = base::__end_.__next_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1574,7 +1627,7 @@ list<_Tp, _Alloc>::pop_front() { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1583,17 +1636,17 @@ list<_Tp, _Alloc>::pop_front() } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } template <class _Tp, class _Alloc> void list<_Tp, _Alloc>::pop_back() { - _LIBCPP_ASSERT(!empty(), "list::pop_front() called with empty list"); + _LIBCPP_ASSERT(!empty(), "list::pop_back() called with empty list"); __node_allocator& __na = base::__node_alloc(); - __node& __n = *base::__end_.__prev_; + __node_pointer __n = base::__end_.__prev_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1602,7 +1655,7 @@ list<_Tp, _Alloc>::pop_back() { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1611,8 +1664,8 @@ list<_Tp, _Alloc>::pop_back() } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } template <class _Tp, class _Alloc> @@ -1624,9 +1677,11 @@ list<_Tp, _Alloc>::erase(const_iterator __p) "list::erase(iterator) called with an iterator not" " referring to this list"); #endif + _LIBCPP_ASSERT(__p != end(), + "list::erase(iterator) called with a non-dereferenceable iterator"); __node_allocator& __na = base::__node_alloc(); - __node& __n = const_cast<__node&>(*__p.__ptr_); - __node_pointer __r = __n.__next_; + __node_pointer __n = __p.__ptr_; + __node_pointer __r = __n->__next_; base::__unlink_nodes(__n, __n); --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1635,7 +1690,7 @@ list<_Tp, _Alloc>::erase(const_iterator __p) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1644,8 +1699,8 @@ list<_Tp, _Alloc>::erase(const_iterator __p) } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); #if _LIBCPP_DEBUG_LEVEL >= 2 return iterator(__r, this); #else @@ -1665,10 +1720,10 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) if (__f != __l) { __node_allocator& __na = base::__node_alloc(); - base::__unlink_nodes(const_cast<__node&>(*__f.__ptr_), *__l.__ptr_->__prev_); + base::__unlink_nodes(__f.__ptr_, __l.__ptr_->__prev_); while (__f != __l) { - __node& __n = const_cast<__node&>(*__f.__ptr_); + __node_pointer __n = __f.__ptr_; ++__f; --base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1677,7 +1732,7 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ == &__n) + if (__i->__ptr_ == __n) { (*__p)->__c_ = nullptr; if (--__c->end_ != __p) @@ -1686,14 +1741,14 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l) } __get_db()->unlock(); #endif - __node_alloc_traits::destroy(__na, _VSTD::addressof(__n.__value_)); - __node_alloc_traits::deallocate(__na, _VSTD::addressof(__n), 1); + __node_alloc_traits::destroy(__na, _VSTD::addressof(__n->__value_)); + __node_alloc_traits::deallocate(__na, __n, 1); } } #if _LIBCPP_DEBUG_LEVEL >= 2 - return iterator(const_cast<__node_pointer>(__l.__ptr_), this); + return iterator(__l.__ptr_, this); #else - return iterator(const_cast<__node_pointer>(__l.__ptr_)); + return iterator(__l.__ptr_); #endif } @@ -1751,7 +1806,8 @@ list<_Tp, _Alloc>::resize(size_type __n) throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } } @@ -1810,7 +1866,8 @@ list<_Tp, _Alloc>::resize(size_type __n, const value_type& __x) throw; } #endif // _LIBCPP_NO_EXCEPTIONS - __link_nodes(static_cast<__node&>(base::__end_), *__r.__ptr_, *__e.__ptr_); + __link_nodes(static_cast<__node_pointer>(pointer_traits<__node_base_pointer>:: + pointer_to(base::__end_)), __r.__ptr_, __e.__ptr_); base::__sz() += __ds; } } @@ -1828,10 +1885,10 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) #endif if (!__c.empty()) { - __node& __f = *__c.__end_.__next_; - __node& __l = *__c.__end_.__prev_; + __node_pointer __f = __c.__end_.__next_; + __node_pointer __l = __c.__end_.__prev_; base::__unlink_nodes(__f, __l); - __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __l); + __link_nodes(__p.__ptr_, __f, __l); base::__sz() += __c.__sz(); __c.__sz() = 0; #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1842,7 +1899,8 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_)) + if (__i->__ptr_ != static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; @@ -1872,9 +1930,9 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) #endif if (__p.__ptr_ != __i.__ptr_ && __p.__ptr_ != __i.__ptr_->__next_) { - __node& __f = const_cast<__node&>(*__i.__ptr_); + __node_pointer __f = __i.__ptr_; base::__unlink_nodes(__f, __f); - __link_nodes(const_cast<__node&>(*__p.__ptr_), __f, __f); + __link_nodes(__p.__ptr_, __f, __f); --__c.__sz(); ++base::__sz(); #if _LIBCPP_DEBUG_LEVEL >= 2 @@ -1885,7 +1943,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i) { --__p; iterator* __j = static_cast<iterator*>((*__p)->__i_); - if (__j->__ptr_ == &__f) + if (__j->__ptr_ == __f) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; @@ -1926,11 +1984,11 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con __c.__sz() -= __s; base::__sz() += __s; } - __node& __first = const_cast<__node&>(*__f.__ptr_); + __node_pointer __first = __f.__ptr_; --__l; - __node& __last = const_cast<__node&>(*__l.__ptr_); + __node_pointer __last = __l.__ptr_; base::__unlink_nodes(__first, __last); - __link_nodes(const_cast<__node&>(*__p.__ptr_), __first, __last); + __link_nodes(__p.__ptr_, __first, __last); #if _LIBCPP_DEBUG_LEVEL >= 2 __libcpp_db* __db = __get_db(); __c_node* __cn1 = __db->__find_c_and_lock(this); @@ -1939,7 +1997,7 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con { --__p; iterator* __j = static_cast<iterator*>((*__p)->__i_); - for (__node_pointer __k = const_cast<__node_pointer>(__f.__ptr_); + for (__node_pointer __k = __f.__ptr_; __k != __l.__ptr_; __k = __k->__next_) { if (__j->__ptr_ == __k) @@ -2045,12 +2103,12 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) ; base::__sz() += __ds; __c.__sz() -= __ds; - __node& __f = *__f2.__ptr_; - __node& __l = *__m2.__ptr_->__prev_; + __node_pointer __f = __f2.__ptr_; + __node_pointer __l = __m2.__ptr_->__prev_; __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); - __link_nodes(*__f1.__ptr_, __f, __l); + __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else @@ -2065,7 +2123,8 @@ list<_Tp, _Alloc>::merge(list& __c, _Comp __comp) { --__p; iterator* __i = static_cast<iterator*>((*__p)->__i_); - if (__i->__ptr_ != static_cast<__node_pointer>(&__c.__end_)) + if (__i->__ptr_ != static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(__c.__end_))) { __cn1->__add(*__p); (*__p)->__c_ = __cn1; @@ -2108,9 +2167,9 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __ case 2: if (__comp(*--__e2, *__f1)) { - __node& __f = *__e2.__ptr_; + __node_pointer __f = __e2.__ptr_; base::__unlink_nodes(__f, __f); - __link_nodes(*__f1.__ptr_, __f, __f); + __link_nodes(__f1.__ptr_, __f, __f); return __e2; } return __f1; @@ -2124,13 +2183,13 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __ iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) ; - __node& __f = *__f2.__ptr_; - __node& __l = *__m2.__ptr_->__prev_; + __node_pointer __f = __f2.__ptr_; + __node_pointer __l = __m2.__ptr_->__prev_; __r = __f2; __e1 = __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); - __link_nodes(*__f1.__ptr_, __f, __l); + __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else @@ -2142,14 +2201,14 @@ list<_Tp, _Alloc>::__sort(iterator __f1, iterator __e2, size_type __n, _Comp& __ iterator __m2 = _VSTD::next(__f2); for (; __m2 != __e2 && __comp(*__m2, *__f1); ++__m2) ; - __node& __f = *__f2.__ptr_; - __node& __l = *__m2.__ptr_->__prev_; + __node_pointer __f = __f2.__ptr_; + __node_pointer __l = __m2.__ptr_->__prev_; if (__e1 == __f2) __e1 = __m2; __f2 = __m2; base::__unlink_nodes(__f, __l); __m2 = _VSTD::next(__f1); - __link_nodes(*__f1.__ptr_, __f, __l); + __link_nodes(__f1.__ptr_, __f, __l); __f1 = __m2; } else @@ -2187,7 +2246,8 @@ template <class _Tp, class _Alloc> bool list<_Tp, _Alloc>::__dereferenceable(const const_iterator* __i) const { - return __i->__ptr_ != &this->__end_; + return __i->__ptr_ != static_cast<__node_pointer>( + pointer_traits<__node_base_pointer>::pointer_to(const_cast<__node_base&>(this->__end_))); } template <class _Tp, class _Alloc> |