aboutsummaryrefslogtreecommitdiff
path: root/contrib/libc++/include/list
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/libc++/include/list')
-rw-r--r--contrib/libc++/include/list144
1 files changed, 77 insertions, 67 deletions
diff --git a/contrib/libc++/include/list b/contrib/libc++/include/list
index cff0a853eff9..76c50a156093 100644
--- a/contrib/libc++/include/list
+++ b/contrib/libc++/include/list
@@ -93,10 +93,10 @@ public:
size_type max_size() const noexcept;
template <class... Args>
- void emplace_front(Args&&... args);
+ reference emplace_front(Args&&... args);
void pop_front();
template <class... Args>
- void emplace_back(Args&&... args);
+ reference emplace_back(Args&&... args);
void pop_back();
void push_front(const value_type& x);
void push_front(value_type&& x);
@@ -266,12 +266,12 @@ struct __list_node
}
};
-template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TYPE_VIS_ONLY list;
+template <class _Tp, class _Alloc = allocator<_Tp> > class _LIBCPP_TEMPLATE_VIS list;
template <class _Tp, class _Alloc> class __list_imp;
-template <class _Tp, class _VoidPtr> class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator;
+template <class _Tp, class _VoidPtr> class _LIBCPP_TEMPLATE_VIS __list_const_iterator;
template <class _Tp, class _VoidPtr>
-class _LIBCPP_TYPE_VIS_ONLY __list_iterator
+class _LIBCPP_TEMPLATE_VIS __list_iterator
{
typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
typedef typename _NodeTraits::__link_pointer __link_pointer;
@@ -394,7 +394,7 @@ public:
};
template <class _Tp, class _VoidPtr>
-class _LIBCPP_TYPE_VIS_ONLY __list_const_iterator
+class _LIBCPP_TEMPLATE_VIS __list_const_iterator
{
typedef __list_node_pointer_traits<_Tp, _VoidPtr> _NodeTraits;
typedef typename _NodeTraits::__link_pointer __link_pointer;
@@ -571,6 +571,10 @@ protected:
{return __size_alloc_.second();}
_LIBCPP_INLINE_VISIBILITY
+ size_type __node_alloc_max_size() const _NOEXCEPT {
+ return __node_alloc_traits::max_size(__node_alloc());
+ }
+ _LIBCPP_INLINE_VISIBILITY
static void __unlink_nodes(__link_pointer __f, __link_pointer __l) _NOEXCEPT;
_LIBCPP_INLINE_VISIBILITY
@@ -622,9 +626,9 @@ protected:
void swap(__list_imp& __c)
#if _LIBCPP_STD_VER >= 14
- _NOEXCEPT;
+ _NOEXCEPT_DEBUG;
#else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
+ _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value);
#endif
@@ -651,7 +655,7 @@ private:
}
_LIBCPP_INLINE_VISIBILITY
- void __copy_assign_alloc(const __list_imp& __c, false_type)
+ void __copy_assign_alloc(const __list_imp&, false_type)
{}
_LIBCPP_INLINE_VISIBILITY
@@ -662,9 +666,16 @@ private:
}
_LIBCPP_INLINE_VISIBILITY
- void __move_assign_alloc(__list_imp& __c, false_type)
+ void __move_assign_alloc(__list_imp&, false_type)
_NOEXCEPT
{}
+
+ _LIBCPP_INLINE_VISIBILITY
+ void __invalidate_all_iterators() {
+#if _LIBCPP_DEBUG_LEVEL >= 2
+ __get_db()->__invalidate_all(this);
+#endif
+ }
};
// Unlink nodes [__f, __l]
@@ -720,21 +731,7 @@ __list_imp<_Tp, _Alloc>::clear() _NOEXCEPT
__node_alloc_traits::destroy(__na, _VSTD::addressof(__np->__value_));
__node_alloc_traits::deallocate(__na, __np, 1);
}
-#if _LIBCPP_DEBUG_LEVEL >= 2
- __c_node* __c = __get_db()->__find_c_and_lock(this);
- for (__i_node** __p = __c->end_; __p != __c->beg_; )
- {
- --__p;
- const_iterator* __i = static_cast<const_iterator*>((*__p)->__i_);
- if (__i->__ptr_ != __l)
- {
- (*__p)->__c_ = nullptr;
- if (--__c->end_ != __p)
- memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
- }
- }
- __get_db()->unlock();
-#endif
+ __invalidate_all_iterators();
}
}
@@ -742,9 +739,9 @@ template <class _Tp, class _Alloc>
void
__list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
#if _LIBCPP_STD_VER >= 14
- _NOEXCEPT
+ _NOEXCEPT_DEBUG
#else
- _NOEXCEPT_(!__alloc_traits::propagate_on_container_swap::value ||
+ _NOEXCEPT_DEBUG_(!__alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<allocator_type>::value)
#endif
{
@@ -803,7 +800,7 @@ __list_imp<_Tp, _Alloc>::swap(__list_imp& __c)
}
template <class _Tp, class _Alloc /*= allocator<_Tp>*/>
-class _LIBCPP_TYPE_VIS_ONLY list
+class _LIBCPP_TEMPLATE_VIS list
: private __list_imp<_Tp, _Alloc>
{
typedef __list_imp<_Tp, _Alloc> base;
@@ -904,7 +901,11 @@ public:
bool empty() const _NOEXCEPT {return base::empty();}
_LIBCPP_INLINE_VISIBILITY
size_type max_size() const _NOEXCEPT
- {return numeric_limits<difference_type>::max();}
+ {
+ return std::min<size_type>(
+ base::__node_alloc_max_size(),
+ numeric_limits<difference_type >::max());
+ }
_LIBCPP_INLINE_VISIBILITY
iterator begin() _NOEXCEPT {return base::begin();}
@@ -968,9 +969,9 @@ public:
void push_back(value_type&& __x);
#ifndef _LIBCPP_HAS_NO_VARIADICS
template <class... _Args>
- void emplace_front(_Args&&... __args);
+ reference emplace_front(_Args&&... __args);
template <class... _Args>
- void emplace_back(_Args&&... __args);
+ reference emplace_back(_Args&&... __args);
template <class... _Args>
iterator emplace(const_iterator __p, _Args&&... __args);
#endif // _LIBCPP_HAS_NO_VARIADICS
@@ -994,9 +995,9 @@ public:
_LIBCPP_INLINE_VISIBILITY
void swap(list& __c)
#if _LIBCPP_STD_VER >= 14
- _NOEXCEPT
+ _NOEXCEPT_DEBUG
#else
- _NOEXCEPT_(!__node_alloc_traits::propagate_on_container_swap::value ||
+ _NOEXCEPT_DEBUG_(!__node_alloc_traits::propagate_on_container_swap::value ||
__is_nothrow_swappable<__node_allocator>::value)
#endif
{base::swap(__c);}
@@ -1353,6 +1354,9 @@ list<_Tp, _Alloc>::assign(_InpIter __f, _InpIter __l,
insert(__e, __f, __l);
else
erase(__i, __e);
+#if _LIBCPP_DEBUG_LEVEL >= 2
+ __get_db()->__invalidate_all(this);
+#endif
}
template <class _Tp, class _Alloc>
@@ -1367,6 +1371,9 @@ list<_Tp, _Alloc>::assign(size_type __n, const value_type& __x)
insert(__e, __n, __x);
else
erase(__i, __e);
+#if _LIBCPP_DEBUG_LEVEL >= 2
+ __get_db()->__invalidate_all(this);
+#endif
}
template <class _Tp, class _Alloc>
@@ -1593,7 +1600,7 @@ list<_Tp, _Alloc>::push_back(value_type&& __x)
template <class _Tp, class _Alloc>
template <class... _Args>
-void
+typename list<_Tp, _Alloc>::reference
list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
{
__node_allocator& __na = base::__node_alloc();
@@ -1602,12 +1609,12 @@ list<_Tp, _Alloc>::emplace_front(_Args&&... __args)
__node_alloc_traits::construct(__na, _VSTD::addressof(__hold->__value_), _VSTD::forward<_Args>(__args)...);
__link_nodes_at_front(__hold.get()->__as_link(), __hold.get()->__as_link());
++base::__sz();
- __hold.release();
+ return __hold.release()->__value_;
}
template <class _Tp, class _Alloc>
template <class... _Args>
-void
+typename list<_Tp, _Alloc>::reference
list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
{
__node_allocator& __na = base::__node_alloc();
@@ -1617,7 +1624,7 @@ list<_Tp, _Alloc>::emplace_back(_Args&&... __args)
__link_pointer __nl = __hold->__as_link();
__link_nodes_at_back(__nl, __nl);
++base::__sz();
- __hold.release();
+ return __hold.release()->__value_;
}
template <class _Tp, class _Alloc>
@@ -1751,15 +1758,15 @@ list<_Tp, _Alloc>::erase(const_iterator __p)
--base::__sz();
#if _LIBCPP_DEBUG_LEVEL >= 2
__c_node* __c = __get_db()->__find_c_and_lock(this);
- for (__i_node** __p = __c->end_; __p != __c->beg_; )
+ for (__i_node** __ip = __c->end_; __ip != __c->beg_; )
{
- --__p;
- iterator* __i = static_cast<iterator*>((*__p)->__i_);
+ --__ip;
+ iterator* __i = static_cast<iterator*>((*__ip)->__i_);
if (__i->__ptr_ == __n)
{
- (*__p)->__c_ = nullptr;
- if (--__c->end_ != __p)
- memmove(__p, __p+1, (__c->end_ - __p)*sizeof(__i_node*));
+ (*__ip)->__c_ = nullptr;
+ if (--__c->end_ != __ip)
+ memmove(__ip, __ip+1, (__c->end_ - __ip)*sizeof(__i_node*));
}
}
__get_db()->unlock();
@@ -1782,6 +1789,9 @@ list<_Tp, _Alloc>::erase(const_iterator __f, const_iterator __l)
_LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__f) == this,
"list::erase(iterator, iterator) called with an iterator not"
" referring to this list");
+ _LIBCPP_ASSERT(__get_const_db()->__find_c_from_i(&__l) == this,
+ "list::erase(iterator, iterator) called with an iterator not"
+ " referring to this list");
#endif
if (__f != __l)
{
@@ -1961,16 +1971,16 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c)
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
- for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
+ for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
{
- --__p;
- iterator* __i = static_cast<iterator*>((*__p)->__i_);
+ --__ip;
+ iterator* __i = static_cast<iterator*>((*__ip)->__i_);
if (__i->__ptr_ != __c.__end_as_link())
{
- __cn1->__add(*__p);
- (*__p)->__c_ = __cn1;
- if (--__cn2->end_ != __p)
- memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
+ __cn1->__add(*__ip);
+ (*__ip)->__c_ = __cn1;
+ if (--__cn2->end_ != __ip)
+ memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
}
}
__db->unlock();
@@ -2004,16 +2014,16 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __i)
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
- for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
+ for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
{
- --__p;
- iterator* __j = static_cast<iterator*>((*__p)->__i_);
+ --__ip;
+ iterator* __j = static_cast<iterator*>((*__ip)->__i_);
if (__j->__ptr_ == __f)
{
- __cn1->__add(*__p);
- (*__p)->__c_ = __cn1;
- if (--__cn2->end_ != __p)
- memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
+ __cn1->__add(*__ip);
+ (*__ip)->__c_ = __cn1;
+ if (--__cn2->end_ != __ip)
+ memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
}
}
__db->unlock();
@@ -2058,19 +2068,19 @@ list<_Tp, _Alloc>::splice(const_iterator __p, list& __c, const_iterator __f, con
__libcpp_db* __db = __get_db();
__c_node* __cn1 = __db->__find_c_and_lock(this);
__c_node* __cn2 = __db->__find_c(&__c);
- for (__i_node** __p = __cn2->end_; __p != __cn2->beg_;)
+ for (__i_node** __ip = __cn2->end_; __ip != __cn2->beg_;)
{
- --__p;
- iterator* __j = static_cast<iterator*>((*__p)->__i_);
+ --__ip;
+ iterator* __j = static_cast<iterator*>((*__ip)->__i_);
for (__link_pointer __k = __f.__ptr_;
__k != __l.__ptr_; __k = __k->__next_)
{
if (__j->__ptr_ == __k)
{
- __cn1->__add(*__p);
- (*__p)->__c_ = __cn1;
- if (--__cn2->end_ != __p)
- memmove(__p, __p+1, (__cn2->end_ - __p)*sizeof(__i_node*));
+ __cn1->__add(*__ip);
+ (*__ip)->__c_ = __cn1;
+ if (--__cn2->end_ != __ip)
+ memmove(__ip, __ip+1, (__cn2->end_ - __ip)*sizeof(__i_node*));
}
}
}
@@ -2083,7 +2093,7 @@ template <class _Tp, class _Alloc>
void
list<_Tp, _Alloc>::remove(const value_type& __x)
{
- list<_Tp, _Alloc> __deleted_nodes; // collect the nodes we're removing
+ list<_Tp, _Alloc> __deleted_nodes(get_allocator()); // collect the nodes we're removing
for (const_iterator __i = begin(), __e = end(); __i != __e;)
{
if (*__i == __x)
@@ -2328,14 +2338,14 @@ list<_Tp, _Alloc>::__decrementable(const const_iterator* __i) const
template <class _Tp, class _Alloc>
bool
-list<_Tp, _Alloc>::__addable(const const_iterator* __i, ptrdiff_t __n) const
+list<_Tp, _Alloc>::__addable(const const_iterator*, ptrdiff_t) const
{
return false;
}
template <class _Tp, class _Alloc>
bool
-list<_Tp, _Alloc>::__subscriptable(const const_iterator* __i, ptrdiff_t __n) const
+list<_Tp, _Alloc>::__subscriptable(const const_iterator*, ptrdiff_t) const
{
return false;
}