Implement full support for non-pointer pointers in custom allocators for list.

llvm-svn: 184859
This commit is contained in:
Howard Hinnant 2013-06-25 16:08:47 +00:00
parent eb95448245
commit 866d4efa7f
65 changed files with 2001 additions and 97 deletions

View File

@ -196,13 +196,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)))
{}
};
@ -305,7 +312,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++()
@ -352,9 +366,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_;
@ -439,7 +453,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++()
@ -505,11 +526,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 +555,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 +587,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 +671,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 +710,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 +754,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 +779,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 +793,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 +816,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 +1057,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 +1071,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,7 +1333,7 @@ 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);
@ -1307,9 +1350,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)
{
@ -1359,7 +1402,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;
@ -1375,9 +1418,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)
{
@ -1427,7 +1470,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;
@ -1441,7 +1484,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();
}
@ -1454,7 +1497,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();
}
@ -1469,7 +1513,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();
}
@ -1482,7 +1526,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();
}
@ -1498,7 +1543,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();
}
@ -1512,7 +1557,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();
}
@ -1532,7 +1578,7 @@ list<_Tp, _Alloc>::emplace(const_iterator __p, _Args&&... __args)
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);
@ -1557,7 +1603,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);
@ -1574,7 +1620,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
@ -1583,7 +1629,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)
@ -1592,8 +1638,8 @@ 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>
@ -1602,7 +1648,7 @@ list<_Tp, _Alloc>::pop_back()
{
_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
@ -1611,7 +1657,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)
@ -1620,8 +1666,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>
@ -1636,8 +1682,8 @@ list<_Tp, _Alloc>::erase(const_iterator __p)
_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
@ -1646,7 +1692,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)
@ -1655,8 +1701,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
@ -1676,10 +1722,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
@ -1688,7 +1734,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)
@ -1697,14 +1743,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
}
@ -1762,7 +1808,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;
}
}
@ -1821,7 +1868,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;
}
}
@ -1839,10 +1887,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
@ -1853,7 +1901,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;
@ -1883,9 +1932,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
@ -1896,7 +1945,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;
@ -1937,11 +1986,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);
@ -1950,7 +1999,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)
@ -2056,12 +2105,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
@ -2076,7 +2125,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;
@ -2119,9 +2169,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;
@ -2135,13 +2185,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
@ -2153,14 +2203,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
@ -2198,7 +2248,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>

View File

@ -21,8 +21,11 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
C c(1);
@ -30,6 +33,18 @@ int main()
c.clear();
assert(c.back() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c(1);
assert(c.back() == 0);
c.clear();
assert(c.back() == 0);
assert(false);
}
#endif
}
#else

View File

@ -21,13 +21,26 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
const C c;
assert(c.back() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
const C c;
assert(c.back() == 0);
assert(false);
}
#endif
}
#else

View File

@ -21,13 +21,26 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
const C c;
assert(c.front() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
const C c;
assert(c.front() == 0);
assert(false);
}
#endif
}
#else

View File

@ -21,8 +21,11 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
C c(1);
@ -30,6 +33,18 @@ int main()
c.clear();
assert(c.front() == 0);
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c(1);
assert(c.front() == 0);
c.clear();
assert(c.front() == 0);
assert(false);
}
#endif
}
#else

View File

@ -21,14 +21,28 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
C c1;
C c2;
bool b = c1.begin() != c2.begin();
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c1;
C c2;
bool b = c1.begin() != c2.begin();
assert(false);
}
#endif
}
#else

View File

@ -21,8 +21,11 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
C c(1);
@ -31,6 +34,19 @@ int main()
assert(i == c.begin());
--i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.end();
--i;
assert(i == c.begin());
--i;
assert(false);
}
#endif
}
#else

View File

@ -21,8 +21,11 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
C c(1);
@ -31,6 +34,19 @@ int main()
assert(i == c.end());
++i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.begin();
++i;
assert(i == c.end());
++i;
assert(false);
}
#endif
}
#else

View File

@ -21,14 +21,28 @@
#include <exception>
#include <cstdlib>
#include "../../min_allocator.h"
int main()
{
{
typedef int T;
typedef std::list<T> C;
C c(1);
C::iterator i = c.end();
T j = *i;
assert(false);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c(1);
C::iterator i = c.end();
T j = *i;
assert(false);
}
#endif
}
#else

View File

@ -20,6 +20,14 @@
#include <cassert>
#include <iterator>
#include "../../min_allocator.h"
struct A
{
int first;
int second;
};
int main()
{
{
@ -69,4 +77,62 @@ int main()
C::iterator i;
C::const_iterator j;
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c;
C::iterator i = c.begin();
C::iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
const C c;
C::const_iterator i = c.begin();
C::const_iterator j = c.end();
assert(std::distance(i, j) == 0);
assert(i == j);
}
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C c;
C::const_iterator i = c.cbegin();
C::const_iterator j = c.cend();
assert(std::distance(i, j) == 0);
assert(i == j);
assert(i == c.end());
}
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t), std::end(t));
C::iterator i = c.begin();
assert(*i == 0);
++i;
assert(*i == 1);
*i = 10;
assert(*i == 10);
assert(std::distance(c.begin(), c.end()) == 10);
}
{
typedef int T;
typedef std::list<T, min_allocator<T>> C;
C::iterator i;
C::const_iterator j;
}
{
typedef A T;
typedef std::list<T, min_allocator<T>> C;
C c = {A{1, 2}};
C::iterator i = c.begin();
i->first = 3;
C::const_iterator j = i;
assert(j->first == 3);
}
#endif
}

View File

@ -14,6 +14,7 @@
#include <list>
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -46,4 +47,35 @@ int main()
assert(std::distance(l.begin(), l.end()) == 20);
}
#endif // __LIBCPP_MOVE
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l(5, 2);
l.resize(2);
assert(l.size() == 2);
assert(std::distance(l.begin(), l.end()) == 2);
assert((l == std::list<int, min_allocator<int>>(2, 2)));
}
{
std::list<int, min_allocator<int>> l(5, 2);
l.resize(10);
assert(l.size() == 10);
assert(std::distance(l.begin(), l.end()) == 10);
assert(l.front() == 2);
assert(l.back() == 0);
}
#ifdef __LIBCPP_MOVE
{
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
l.resize(5);
assert(l.size() == 5);
assert(std::distance(l.begin(), l.end()) == 5);
}
{
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(10);
l.resize(20);
assert(l.size() == 20);
assert(std::distance(l.begin(), l.end()) == 20);
}
#endif // __LIBCPP_MOVE
#endif
}

View File

@ -14,6 +14,7 @@
#include <list>
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -32,4 +33,21 @@ int main()
assert(l.front() == 2);
assert(l.back() == 3.5);
}
#if __cplusplus >= 201103L
{
std::list<double, min_allocator<double>> l(5, 2);
l.resize(2, 3.5);
assert(l.size() == 2);
assert(std::distance(l.begin(), l.end()) == 2);
assert((l == std::list<double, min_allocator<double>>(2, 2)));
}
{
std::list<double, min_allocator<double>> l(5, 2);
l.resize(10, 3.5);
assert(l.size() == 10);
assert(std::distance(l.begin(), l.end()) == 10);
assert(l.front() == 2);
assert(l.back() == 3.5);
}
#endif
}

View File

@ -14,6 +14,7 @@
#include <list>
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -31,4 +32,13 @@ int main()
assert(l2 == l);
assert(l2.get_allocator() == other_allocator<int>(5));
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int> > l(3, 2, min_allocator<int>());
std::list<int, min_allocator<int> > l2(l, min_allocator<int>());
l2 = l;
assert(l2 == l);
assert(l2.get_allocator() == min_allocator<int>());
}
#endif
}

View File

@ -14,9 +14,12 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::list<int> d;
d.assign({3, 4, 5, 6});
assert(d.size() == 4);
@ -25,5 +28,18 @@ int main()
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> d;
d.assign({3, 4, 5, 6});
assert(d.size() == 4);
std::list<int, min_allocator<int>>::iterator i = d.begin();
assert(*i++ == 3);
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -61,5 +62,21 @@ int main()
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#if __cplusplus >= 201103L
{
std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
std::list<MoveOnly, min_allocator<MoveOnly> > l2(min_allocator<MoveOnly>{});
l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -37,4 +38,17 @@ int main()
assert(l2.get_allocator() == other_allocator<int>(-2));
}
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l(3, 2);
std::list<int, min_allocator<int>> l2 = l;
assert(l2 == l);
}
{
std::list<int, min_allocator<int> > l(3, 2, min_allocator<int>());
std::list<int, min_allocator<int> > l2 = l;
assert(l2 == l);
assert(l2.get_allocator() == l.get_allocator());
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -30,4 +31,12 @@ int main()
assert(l2 == l);
assert(l2.get_allocator() == other_allocator<int>(3));
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int> > l(3, 2, min_allocator<int>());
std::list<int, min_allocator<int> > l2(l, min_allocator<int>());
assert(l2 == l);
assert(l2.get_allocator() == min_allocator<int>());
}
#endif
}

View File

@ -14,6 +14,7 @@
#include <list>
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -32,4 +33,21 @@ int main()
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l;
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
{
std::list<DefaultOnly, min_allocator<DefaultOnly>> l;
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
{
std::list<int, min_allocator<int>> l((min_allocator<int>()));
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
#endif
}

View File

@ -14,8 +14,7 @@
#include <list>
#include <cassert>
#include "../../../stack_allocator.h"
#include <iostream>
#include "../../../min_allocator.h"
int main()
{
@ -34,4 +33,16 @@ int main()
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l;
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
{
std::list<int, min_allocator<int>> l((min_allocator<int>()));
assert(l.size() == 0);
assert(std::distance(l.begin(), l.end()) == 0);
}
#endif
}

View File

@ -14,9 +14,12 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::list<int> d = {3, 4, 5, 6};
assert(d.size() == 4);
std::list<int>::iterator i = d.begin();
@ -24,5 +27,17 @@ int main()
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> d = {3, 4, 5, 6};
assert(d.size() == 4);
std::list<int, min_allocator<int>>::iterator i = d.begin();
assert(*i++ == 3);
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -15,10 +15,12 @@
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::list<int, test_allocator<int>> d({3, 4, 5, 6}, test_allocator<int>(3));
assert(d.get_allocator() == test_allocator<int>(3));
assert(d.size() == 4);
@ -27,5 +29,18 @@ int main()
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> d({3, 4, 5, 6}, min_allocator<int>());
assert(d.get_allocator() == min_allocator<int>());
assert(d.size() == 4);
std::list<int, min_allocator<int>>::iterator i = d.begin();
assert(*i++ == 3);
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -16,6 +16,7 @@
#include <cassert>
#include "test_iterators.h"
#include "../../../stack_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -50,4 +51,27 @@ int main()
for (std::list<int>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j)
assert(*i == j);
}
#if __cplusplus >= 201103L
{
int a[] = {0, 1, 2, 3};
std::list<int, min_allocator<int>> l(input_iterator<const int*>(a),
input_iterator<const int*>(a + sizeof(a)/sizeof(a[0])));
assert(l.size() == sizeof(a)/sizeof(a[0]));
assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0]));
int j = 0;
for (std::list<int, min_allocator<int>>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j)
assert(*i == j);
}
{
int a[] = {0, 1, 2, 3};
std::list<int, min_allocator<int>> l(input_iterator<const int*>(a),
input_iterator<const int*>(a + sizeof(a)/sizeof(a[0])),
min_allocator<int>());
assert(l.size() == sizeof(a)/sizeof(a[0]));
assert(std::distance(l.begin(), l.end()) == sizeof(a)/sizeof(a[0]));
int j = 0;
for (std::list<int, min_allocator<int>>::const_iterator i = l.begin(), e = l.end(); i != e; ++i, ++j)
assert(*i == j);
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -45,5 +46,20 @@ int main()
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#if __cplusplus >= 201103L
{
std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
std::list<MoveOnly, min_allocator<MoveOnly> > l2 = std::move(l);
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == lo.get_allocator());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -58,5 +59,20 @@ int main()
assert(!l.empty());
assert(l2.get_allocator() == other_allocator<MoveOnly>(4));
}
#if __cplusplus >= 201103L
{
std::list<MoveOnly, min_allocator<MoveOnly> > l(min_allocator<MoveOnly>{});
std::list<MoveOnly, min_allocator<MoveOnly> > lo(min_allocator<MoveOnly>{});
for (int i = 1; i <= 3; ++i)
{
l.push_back(i);
lo.push_back(i);
}
std::list<MoveOnly, min_allocator<MoveOnly> > l2(std::move(l), min_allocator<MoveOnly>());
assert(l2 == lo);
assert(l.empty());
assert(l2.get_allocator() == min_allocator<MoveOnly>());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -13,10 +13,12 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::list<int> d;
d = {3, 4, 5, 6};
assert(d.size() == 4);
@ -25,5 +27,18 @@ int main()
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> d;
d = {3, 4, 5, 6};
assert(d.size() == 4);
std::list<int, min_allocator<int>>::iterator i = d.begin();
assert(*i++ == 3);
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../stack_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -47,4 +48,24 @@ int main()
assert(std::distance(l.begin(), l.end()) == 3);
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l(3);
assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3);
std::list<int, min_allocator<int>>::const_iterator i = l.begin();
assert(*i == 0);
++i;
assert(*i == 0);
++i;
assert(*i == 0);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<DefaultOnly, min_allocator<DefaultOnly>> l(3);
assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3);
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../stack_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -51,4 +52,28 @@ int main()
++i;
assert(*i == 2);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l(3, 2);
assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3);
std::list<int, min_allocator<int>>::const_iterator i = l.begin();
assert(*i == 2);
++i;
assert(*i == 2);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l(3, 2, min_allocator<int>());
assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3);
std::list<int, min_allocator<int>>::const_iterator i = l.begin();
assert(*i == 2);
++i;
assert(*i == 2);
++i;
assert(*i == 2);
}
#endif
}

View File

@ -14,10 +14,22 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a[] = {1, 2, 3};
std::list<int> c(a, a+3);
c.clear();
assert(c.empty());
}
#if __cplusplus >= 201103L
{
int a[] = {1, 2, 3};
std::list<int, min_allocator<int>> c(a, a+3);
c.clear();
assert(c.empty());
}
#endif
}

View File

@ -18,6 +18,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
class A
{
int i_;
@ -36,6 +38,7 @@ public:
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<A> c;
c.emplace(c.cbegin(), 2, 3.5);
assert(c.size() == 1);
@ -47,7 +50,7 @@ int main()
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<A> c1;
@ -56,4 +59,30 @@ int main()
assert(false);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if __cplusplus >= 201103L
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<A, min_allocator<A>> c;
c.emplace(c.cbegin(), 2, 3.5);
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
c.emplace(c.cend(), 3, 4.5);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<A, min_allocator<A>> c1;
std::list<A, min_allocator<A>> c2;
std::list<A, min_allocator<A>>::iterator i = c1.emplace(c2.cbegin(), 2, 3.5);
assert(false);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif
}

View File

@ -14,6 +14,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
class A
{
int i_;
@ -32,6 +34,7 @@ public:
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<A> c;
c.emplace_back(2, 3.5);
assert(c.size() == 1);
@ -43,5 +46,21 @@ int main()
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
}
#if __cplusplus >= 201103L
{
std::list<A, min_allocator<A>> c;
c.emplace_back(2, 3.5);
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
c.emplace_back(3, 4.5);
assert(c.size() == 2);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
assert(c.back().geti() == 3);
assert(c.back().getd() == 4.5);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -14,6 +14,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
class A
{
int i_;
@ -32,6 +34,7 @@ public:
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<A> c;
c.emplace_front(2, 3.5);
assert(c.size() == 1);
@ -43,5 +46,21 @@ int main()
assert(c.front().getd() == 4.5);
assert(c.back().geti() == 2);
assert(c.back().getd() == 3.5);
}
#if __cplusplus >= 201103L
{
std::list<A, min_allocator<A>> c;
c.emplace_front(2, 3.5);
assert(c.size() == 1);
assert(c.front().geti() == 2);
assert(c.front().getd() == 3.5);
c.emplace_front(3, 4.5);
assert(c.size() == 2);
assert(c.front().geti() == 3);
assert(c.front().getd() == 4.5);
assert(c.back().geti() == 2);
assert(c.back().getd() == 3.5);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -14,8 +14,11 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int>::const_iterator i = l1.begin();
@ -35,4 +38,28 @@ int main()
assert(j == l1.end());
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
++i;
std::list<int, min_allocator<int>>::iterator j = l1.erase(i);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(*j == 3);
assert(*l1.begin() == 1);
assert(*next(l1.begin()) == 3);
j = l1.erase(j);
assert(j == l1.end());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(*l1.begin() == 1);
j = l1.erase(l1.begin());
assert(j == l1.end());
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
}
#endif
}

View File

@ -20,13 +20,26 @@
#include <cstdlib>
#include <exception>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int>::const_iterator i = l1.end();
l1.erase(i);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::const_iterator i = l1.end();
l1.erase(i);
assert(false);
}
#endif
}
#else

View File

@ -20,14 +20,28 @@
#include <cstdlib>
#include <exception>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int> l2(a1, a1+3);
std::list<int>::const_iterator i = l2.begin();
l1.erase(i);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a1, a1+3);
std::list<int, min_allocator<int>>::const_iterator i = l2.begin();
l1.erase(i);
assert(false);
}
#endif
}
#else

View File

@ -14,6 +14,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
int a1[] = {1, 2, 3};
@ -47,4 +49,36 @@ int main()
assert(distance(l1.cbegin(), l1.cend()) == 0);
assert(i == l1.begin());
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), l1.cbegin());
assert(l1.size() == 3);
assert(distance(l1.cbegin(), l1.cend()) == 3);
assert(i == l1.begin());
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin()));
assert(l1.size() == 2);
assert(distance(l1.cbegin(), l1.cend()) == 2);
assert(i == l1.begin());
assert((l1 == std::list<int, min_allocator<int>>(a1+1, a1+3)));
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 2));
assert(l1.size() == 1);
assert(distance(l1.cbegin(), l1.cend()) == 1);
assert(i == l1.begin());
assert((l1 == std::list<int, min_allocator<int>>(a1+2, a1+3)));
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l1.cbegin(), 3));
assert(l1.size() == 0);
assert(distance(l1.cbegin(), l1.cend()) == 0);
assert(i == l1.begin());
}
#endif
}

View File

@ -20,13 +20,26 @@
#include <exception>
#include <cstdlib>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int> l2(a1, a1+3);
std::list<int>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin()));
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), next(l1.cbegin()));
assert(false);
}
#endif
}
#else

View File

@ -20,13 +20,26 @@
#include <exception>
#include <cstdlib>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int> l2(a1, a1+3);
std::list<int>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin()));
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l1.cbegin(), next(l2.cbegin()));
assert(false);
}
#endif
}
#else

View File

@ -20,13 +20,26 @@
#include <exception>
#include <cstdlib>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int> l2(a1, a1+3);
std::list<int>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin()));
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(l2.cbegin(), next(l2.cbegin()));
assert(false);
}
#endif
}
#else

View File

@ -20,12 +20,24 @@
#include <exception>
#include <cstdlib>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3};
std::list<int> l1(a1, a1+3);
std::list<int>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin());
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.erase(next(l1.cbegin()), l1.cbegin());
assert(false);
}
#endif
}
#else

View File

@ -14,9 +14,12 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
{
std::list<int> d(10, 1);
std::list<int>::iterator i = d.insert(next(d.cbegin(), 2), {3, 4, 5, 6});
assert(d.size() == 14);
@ -36,5 +39,29 @@ int main()
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> d(10, 1);
std::list<int, min_allocator<int>>::iterator i = d.insert(next(d.cbegin(), 2), {3, 4, 5, 6});
assert(d.size() == 14);
assert(i == next(d.begin(), 2));
i = d.begin();
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 3);
assert(*i++ == 4);
assert(*i++ == 5);
assert(*i++ == 6);
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
assert(*i++ == 1);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -20,6 +20,7 @@
#include <cstdlib>
#include <cassert>
#include "test_iterators.h"
#include "../../../min_allocator.h"
int throw_next = 0xFFFF;
int count = 0;
@ -97,9 +98,9 @@ int main()
++i;
assert(*i == 3);
}
throw_next = 0xFFFF;
#if _LIBCPP_DEBUG2 >= 1
{
throw_next = 0xFFFF;
std::list<int> v(100);
std::list<int> v2(100);
int a[] = {1, 2, 3, 4, 5};
@ -109,4 +110,74 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>>::iterator i = l1.insert(l1.begin(), a1, a1+3);
assert(i == l1.begin());
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
int a2[] = {4, 5, 6};
i = l1.insert(i, a2, a2+3);
assert(*i == 4);
assert(l1.size() == 6);
assert(distance(l1.begin(), l1.end()) == 6);
i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 3);
throw_next = 2;
int save_count = count;
try
{
i = l1.insert(i, a2, a2+3);
assert(false);
}
catch (...)
{
}
assert(save_count == count);
assert(l1.size() == 6);
assert(distance(l1.begin(), l1.end()) == 6);
i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 3);
}
#if _LIBCPP_DEBUG2 >= 1
{
throw_next = 0xFFFF;
std::list<int, min_allocator<int>> v(100);
std::list<int, min_allocator<int>> v2(100);
int a[] = {1, 2, 3, 4, 5};
const int N = sizeof(a)/sizeof(a[0]);
std::list<int, min_allocator<int>>::iterator i = v.insert(next(v2.cbegin(), 10), input_iterator<const int*>(a),
input_iterator<const int*>(a+N));
assert(false);
}
#endif
#endif
}

View File

@ -19,10 +19,12 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<MoveOnly> l1;
l1.insert(l1.cend(), MoveOnly(1));
assert(l1.size() == 1);
@ -31,6 +33,7 @@ int main()
assert(l1.size() == 2);
assert(l1.front() == MoveOnly(2));
assert(l1.back() == MoveOnly(1));
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if _LIBCPP_DEBUG2 >= 1
{
@ -40,4 +43,26 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<MoveOnly, min_allocator<MoveOnly>> l1;
l1.insert(l1.cend(), MoveOnly(1));
assert(l1.size() == 1);
assert(l1.front() == MoveOnly(1));
l1.insert(l1.cbegin(), MoveOnly(2));
assert(l1.size() == 2);
assert(l1.front() == MoveOnly(2));
assert(l1.back() == MoveOnly(1));
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.insert(v2.begin(), 4);
assert(false);
}
#endif
#endif
}

View File

@ -19,6 +19,8 @@
#include <cstdlib>
#include <cassert>
#include "../../../min_allocator.h"
int throw_next = 0xFFFF;
int count = 0;
@ -39,6 +41,7 @@ void operator delete(void* p) throw()
int main()
{
{
int a1[] = {1, 2, 3};
int a2[] = {1, 4, 4, 4, 4, 4, 2, 3};
std::list<int> l1(a1, a1+3);
@ -58,6 +61,7 @@ int main()
throw_next = 0xFFFF;
assert(save_count == count);
assert(l1 == std::list<int>(a2, a2+8));
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int> c1(100);
@ -66,4 +70,35 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
int a2[] = {1, 4, 4, 4, 4, 4, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.insert(next(l1.cbegin()), 5, 4);
assert(i == next(l1.begin()));
assert((l1 == std::list<int, min_allocator<int>>(a2, a2+8)));
throw_next = 4;
int save_count = count;
try
{
i = l1.insert(i, 5, 5);
assert(false);
}
catch (...)
{
}
throw_next = 0xFFFF;
assert(save_count == count);
assert((l1 == std::list<int, min_allocator<int>>(a2, a2+8)));
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int, min_allocator<int>> c1(100);
std::list<int, min_allocator<int>> c2;
std::list<int, min_allocator<int>>::iterator i = c1.insert(next(c2.cbegin(), 10), 5, 1);
assert(false);
}
#endif
#endif
}

View File

@ -19,6 +19,8 @@
#include <cstdlib>
#include <cassert>
#include "../../../min_allocator.h"
int throw_next = 0xFFFF;
int count = 0;
@ -39,6 +41,7 @@ void operator delete(void* p) throw()
int main()
{
{
int a1[] = {1, 2, 3};
int a2[] = {1, 4, 2, 3};
std::list<int> l1(a1, a1+3);
@ -60,6 +63,7 @@ int main()
throw_next = 0xFFFF;
assert(save_count == count);
assert(l1 == std::list<int>(a2, a2+4));
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int> v1(3);
@ -69,4 +73,38 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3};
int a2[] = {1, 4, 2, 3};
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>>::iterator i = l1.insert(next(l1.cbegin()), 4);
assert(i == next(l1.begin()));
assert(l1.size() == 4);
assert(distance(l1.begin(), l1.end()) == 4);
assert((l1 == std::list<int, min_allocator<int>>(a2, a2+4)));
throw_next = 0;
int save_count = count;
try
{
i = l1.insert(i, 5);
assert(false);
}
catch (...)
{
}
throw_next = 0xFFFF;
assert(save_count == count);
assert((l1 == std::list<int, min_allocator<int>>(a2, a2+4)));
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
int i = 4;
v1.insert(v2.begin(), i);
assert(false);
}
#endif
#endif
}

View File

@ -18,8 +18,11 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a[] = {1, 2, 3};
std::list<int> c(a, a+3);
c.pop_back();
@ -32,4 +35,21 @@ int main()
c.pop_back();
assert(false);
#endif
}
#if __cplusplus >= 201103L
{
int a[] = {1, 2, 3};
std::list<int, min_allocator<int>> c(a, a+3);
c.pop_back();
assert((c == std::list<int, min_allocator<int>>(a, a+2)));
c.pop_back();
assert((c == std::list<int, min_allocator<int>>(a, a+1)));
c.pop_back();
assert(c.empty());
#if _LIBCPP_DEBUG2 >= 1
c.pop_back();
assert(false);
#endif
}
#endif
}

View File

@ -14,8 +14,11 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a[] = {1, 2, 3};
std::list<int> c(a, a+3);
c.pop_front();
@ -24,4 +27,17 @@ int main()
assert(c == std::list<int>(a+2, a+3));
c.pop_front();
assert(c.empty());
}
#if __cplusplus >= 201103L
{
int a[] = {1, 2, 3};
std::list<int, min_allocator<int>> c(a, a+3);
c.pop_front();
assert((c == std::list<int, min_allocator<int>>(a+1, a+3)));
c.pop_front();
assert((c == std::list<int, min_allocator<int>>(a+2, a+3)));
c.pop_front();
assert(c.empty());
}
#endif
}

View File

@ -14,11 +14,24 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
std::list<int> c;
for (int i = 0; i < 5; ++i)
c.push_back(i);
int a[] = {0, 1, 2, 3, 4};
assert(c == std::list<int>(a, a+5));
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> c;
for (int i = 0; i < 5; ++i)
c.push_back(i);
int a[] = {0, 1, 2, 3, 4};
assert((c == std::list<int, min_allocator<int>>(a, a+5)));
}
#endif
}

View File

@ -15,10 +15,12 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<MoveOnly> l1;
l1.push_back(MoveOnly(1));
assert(l1.size() == 1);
@ -27,5 +29,18 @@ int main()
assert(l1.size() == 2);
assert(l1.front() == MoveOnly(1));
assert(l1.back() == MoveOnly(2));
}
#if __cplusplus >= 201103L
{
std::list<MoveOnly, min_allocator<MoveOnly>> l1;
l1.push_back(MoveOnly(1));
assert(l1.size() == 1);
assert(l1.front() == MoveOnly(1));
l1.push_back(MoveOnly(2));
assert(l1.size() == 2);
assert(l1.front() == MoveOnly(1));
assert(l1.back() == MoveOnly(2));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -14,11 +14,24 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
std::list<int> c;
for (int i = 0; i < 5; ++i)
c.push_front(i);
int a[] = {4, 3, 2, 1, 0};
assert(c == std::list<int>(a, a+5));
}
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> c;
for (int i = 0; i < 5; ++i)
c.push_front(i);
int a[] = {4, 3, 2, 1, 0};
assert((c == std::list<int, min_allocator<int>>(a, a+5)));
}
#endif
}

View File

@ -15,10 +15,12 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<MoveOnly> l1;
l1.push_front(MoveOnly(1));
assert(l1.size() == 1);
@ -27,5 +29,18 @@ int main()
assert(l1.size() == 2);
assert(l1.front() == MoveOnly(2));
assert(l1.back() == MoveOnly(1));
}
#if __cplusplus >= 201103L
{
std::list<MoveOnly, min_allocator<MoveOnly>> l1;
l1.push_front(MoveOnly(1));
assert(l1.size() == 1);
assert(l1.front() == MoveOnly(1));
l1.push_front(MoveOnly(2));
assert(l1.size() == 2);
assert(l1.front() == MoveOnly(2));
assert(l1.back() == MoveOnly(1));
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -14,8 +14,11 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
@ -23,4 +26,16 @@ int main()
std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
c1.merge(c2);
assert(c1 == std::list<int>(a3, a3+sizeof(a3)/sizeof(a3[0])));
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
int a3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
c1.merge(c2);
assert((c1 == std::list<int, min_allocator<int>>(a3, a3+sizeof(a3)/sizeof(a3[0]))));
}
#endif
}

View File

@ -15,8 +15,11 @@
#include <functional>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {10, 9, 7, 3, 1};
int a2[] = {11, 8, 6, 5, 4, 2, 0};
int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
@ -24,4 +27,16 @@ int main()
std::list<int> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
c1.merge(c2, std::greater<int>());
assert(c1 == std::list<int>(a3, a3+sizeof(a3)/sizeof(a3[0])));
}
#if __cplusplus >= 201103L
{
int a1[] = {10, 9, 7, 3, 1};
int a2[] = {11, 8, 6, 5, 4, 2, 0};
int a3[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
c1.merge(c2, std::greater<int>());
assert((c1 == std::list<int, min_allocator<int>>(a3, a3+sizeof(a3)/sizeof(a3[0]))));
}
#endif
}

View File

@ -14,11 +14,24 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {1, 2, 3, 4};
int a2[] = {1, 2, 4};
std::list<int> c(a1, a1+4);
c.remove(3);
assert(c == std::list<int>(a2, a2+3));
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3, 4};
int a2[] = {1, 2, 4};
std::list<int, min_allocator<int>> c(a1, a1+4);
c.remove(3);
assert((c == std::list<int, min_allocator<int>>(a2, a2+3)));
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <cassert>
#include <functional>
#include "../../../min_allocator.h"
bool g(int i)
{
return i < 3;
@ -22,9 +24,20 @@ bool g(int i)
int main()
{
{
int a1[] = {1, 2, 3, 4};
int a2[] = {3, 4};
std::list<int> c(a1, a1+4);
c.remove_if(g);
assert(c == std::list<int>(a2, a2+2));
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 2, 3, 4};
int a2[] = {3, 4};
std::list<int, min_allocator<int>> c(a1, a1+4);
c.remove_if(g);
assert((c == std::list<int, min_allocator<int>>(a2, a2+2)));
}
#endif
}

View File

@ -14,11 +14,24 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
c1.reverse();
assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0])));
}
#if __cplusplus >= 201103L
{
int a1[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
c1.reverse();
assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
}
#endif
}

View File

@ -14,11 +14,24 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9};
int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
c1.sort();
assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0])));
}
#if __cplusplus >= 201103L
{
int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9};
int a2[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
c1.sort();
assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
}
#endif
}

View File

@ -15,11 +15,24 @@
#include <functional>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9};
int a2[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
std::list<int> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
c1.sort(std::greater<int>());
assert(c1 == std::list<int>(a2, a2+sizeof(a2)/sizeof(a2[0])));
}
#if __cplusplus >= 201103L
{
int a1[] = {4, 8, 1, 0, 5, 7, 2, 3, 6, 11, 10, 9};
int a2[] = {11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
c1.sort(std::greater<int>());
assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
}
#endif
}

View File

@ -18,6 +18,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
int a1[] = {1, 2, 3};
@ -409,4 +411,393 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2;
l1.splice(l1.end(), l2);
assert(l1.size() == 0);
assert(distance(l1.begin(), l1.end()) == 0);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(l1.end(), l2);
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(l1.end(), l2);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 5);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.end(), l2);
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2;
l1.splice(l1.begin(), l2);
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2;
l1.splice(l1.end(), l2);
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(l1.begin(), l2);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(l1.end(), l2);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(l1.begin(), l2);
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(l1.end(), l2);
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.begin(), l2);
assert(l1.size() == 4);
assert(distance(l1.begin(), l1.end()) == 4);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.end(), l2);
assert(l1.size() == 4);
assert(distance(l1.begin(), l1.end()) == 4);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2;
l1.splice(l1.begin(), l2);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2;
l1.splice(next(l1.begin()), l2);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2;
l1.splice(next(l1.begin(), 2), l2);
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(l1.begin(), l2);
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(next(l1.begin()), l2);
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(next(l1.begin(), 2), l2);
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(l1.begin(), l2);
assert(l1.size() == 4);
assert(distance(l1.begin(), l1.end()) == 4);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(next(l1.begin()), l2);
assert(l1.size() == 4);
assert(distance(l1.begin(), l1.end()) == 4);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(next(l1.begin(), 2), l2);
assert(l1.size() == 4);
assert(distance(l1.begin(), l1.end()) == 4);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.begin(), l2);
assert(l1.size() == 6);
assert(distance(l1.begin(), l1.end()) == 6);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(next(l1.begin()), l2);
assert(l1.size() == 6);
assert(distance(l1.begin(), l1.end()) == 6);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(next(l1.begin(), 2), l2);
assert(l1.size() == 6);
assert(distance(l1.begin(), l1.end()) == 6);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 3);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(next(l1.begin(), 3), l2);
assert(l1.size() == 6);
assert(distance(l1.begin(), l1.end()) == 6);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
++i;
assert(*i == 4);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.splice(v2.begin(), v2);
assert(false);
}
#endif
#endif
}

View File

@ -18,6 +18,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
int a1[] = {1, 2, 3};
@ -186,4 +188,170 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(l1.end(), l2, l2.begin());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(l1.end(), l2, l2.begin());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 1);
assert(distance(l2.begin(), l2.end()) == 1);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
i = l2.begin();
assert(*i == 5);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+2);
l1.splice(l1.end(), l2, next(l2.begin()));
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 1);
assert(distance(l2.begin(), l2.end()) == 1);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 5);
i = l2.begin();
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.end(), l2, l2.begin());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 2);
assert(distance(l2.begin(), l2.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
i = l2.begin();
assert(*i == 5);
++i;
assert(*i == 6);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.end(), l2, next(l2.begin()));
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 2);
assert(distance(l2.begin(), l2.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 5);
i = l2.begin();
assert(*i == 4);
++i;
assert(*i == 6);
}
{
std::list<int, min_allocator<int>> l1;
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.end(), l2, next(l2.begin(), 2));
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
assert(l2.size() == 2);
assert(distance(l2.begin(), l2.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 6);
i = l2.begin();
assert(*i == 4);
++i;
assert(*i == 5);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
l1.splice(l1.begin(), l1, l1.begin());
assert(l1.size() == 1);
assert(distance(l1.begin(), l1.end()) == 1);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(l1.begin(), l2, l2.begin());
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 4);
++i;
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+1);
std::list<int, min_allocator<int>> l2(a2, a2+1);
l1.splice(next(l1.begin()), l2, l2.begin());
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
assert(l2.size() == 0);
assert(distance(l2.begin(), l2.end()) == 0);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
l1.splice(l1.begin(), l1, l1.begin());
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
l1.splice(l1.begin(), l1, next(l1.begin()));
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 2);
++i;
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
l1.splice(next(l1.begin()), l1, l1.begin());
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+2);
l1.splice(next(l1.begin()), l1, next(l1.begin()));
assert(l1.size() == 2);
assert(distance(l1.begin(), l1.end()) == 2);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.splice(v1.begin(), v2, v1.begin());
assert(false);
}
#endif
#endif
}

View File

@ -18,6 +18,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
int a1[] = {1, 2, 3};
@ -126,4 +128,110 @@ int main()
assert(false);
}
#endif
#if __cplusplus >= 201103L
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin()));
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 2));
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 2);
++i;
assert(*i == 1);
++i;
assert(*i == 3);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
l1.splice(l1.begin(), l1, next(l1.begin()), next(l1.begin(), 3));
assert(l1.size() == 3);
assert(distance(l1.begin(), l1.end()) == 3);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 2);
++i;
assert(*i == 3);
++i;
assert(*i == 1);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.begin(), l2, next(l2.begin()), l2.end());
assert(l1.size() == 5);
assert(distance(l1.begin(), l1.end()) == 5);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
assert(l2.size() == 1);
i = l2.begin();
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(next(l1.begin()), l2, next(l2.begin()), l2.end());
assert(l1.size() == 5);
assert(distance(l1.begin(), l1.end()) == 5);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
assert(l2.size() == 1);
i = l2.begin();
assert(*i == 4);
}
{
std::list<int, min_allocator<int>> l1(a1, a1+3);
std::list<int, min_allocator<int>> l2(a2, a2+3);
l1.splice(l1.end(), l2, next(l2.begin()), l2.end());
assert(l1.size() == 5);
assert(distance(l1.begin(), l1.end()) == 5);
std::list<int, min_allocator<int>>::const_iterator i = l1.begin();
assert(*i == 1);
++i;
assert(*i == 2);
++i;
assert(*i == 3);
++i;
assert(*i == 5);
++i;
assert(*i == 6);
assert(l2.size() == 1);
i = l2.begin();
assert(*i == 4);
}
#if _LIBCPP_DEBUG2 >= 1
{
std::list<int, min_allocator<int>> v1(3);
std::list<int, min_allocator<int>> v2(3);
v1.splice(v1.begin(), v2, v2.begin(), v1.end());
assert(false);
}
#endif
#endif
}

View File

@ -14,11 +14,24 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3};
int a2[] = {2, 1, 4, 3};
std::list<int> c(a1, a1+sizeof(a1)/sizeof(a1[0]));
c.unique();
assert(c == std::list<int>(a2, a2+4));
}
#if __cplusplus >= 201103L
{
int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3};
int a2[] = {2, 1, 4, 3};
std::list<int, min_allocator<int>> c(a1, a1+sizeof(a1)/sizeof(a1[0]));
c.unique();
assert((c == std::list<int, min_allocator<int>>(a2, a2+4)));
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <list>
#include <cassert>
#include "../../../min_allocator.h"
bool g(int x, int y)
{
return x == y;
@ -21,9 +23,20 @@ bool g(int x, int y)
int main()
{
{
int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3};
int a2[] = {2, 1, 4, 3};
std::list<int> c(a1, a1+sizeof(a1)/sizeof(a1[0]));
c.unique(g);
assert(c == std::list<int>(a2, a2+4));
}
#if __cplusplus >= 201103L
{
int a1[] = {2, 1, 1, 4, 4, 4, 4, 3, 3};
int a2[] = {2, 1, 4, 3};
std::list<int, min_allocator<int>> c(a1, a1+sizeof(a1)/sizeof(a1[0]));
c.unique(g);
assert((c == std::list<int, min_allocator<int>>(a2, a2+4)));
}
#endif
}

View File

@ -20,6 +20,7 @@
#include <cassert>
#include <__debug>
#include "../../../min_allocator.h"
int main()
{
@ -38,5 +39,21 @@ int main()
c1.erase(i1);
assert(false);
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
std::list<int, min_allocator<int>>::iterator i1 = c1.begin();
std::list<int, min_allocator<int>>::iterator i2 = c2.begin();
swap(c1, c2);
c1.erase(i2);
c2.erase(i1);
std::list<int, min_allocator<int>>::iterator j = i1;
c1.erase(i1);
assert(false);
}
#endif
#endif
}

View File

@ -15,6 +15,7 @@
#include <list>
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -85,4 +86,61 @@ int main()
assert((c2 == std::list<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A(1));
}
#if __cplusplus >= 201103L
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
swap(c1, c2);
assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert((c2 == std::list<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int, min_allocator<int>> c1(a1, a1);
std::list<int, min_allocator<int>> c2(a2, a2+sizeof(a2)/sizeof(a2[0]));
swap(c1, c2);
assert((c1 == std::list<int, min_allocator<int>>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int, min_allocator<int>> c1(a1, a1+sizeof(a1)/sizeof(a1[0]));
std::list<int, min_allocator<int>> c2(a2, a2);
swap(c1, c2);
assert(c1.empty());
assert(distance(c1.begin(), c1.end()) == 0);
assert((c2 == std::list<int, min_allocator<int>>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
}
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
std::list<int, min_allocator<int>> c1(a1, a1);
std::list<int, min_allocator<int>> c2(a2, a2);
swap(c1, c2);
assert(c1.empty());
assert(distance(c1.begin(), c1.end()) == 0);
assert(c2.empty());
assert(distance(c2.begin(), c2.end()) == 0);
}
#ifndef _LIBCPP_DEBUG_LEVEL
// This test known to result in undefined behavior detected by _LIBCPP_DEBUG_LEVEL >= 1
{
int a1[] = {1, 3, 7, 9, 10};
int a2[] = {0, 2, 4, 5, 6, 8, 11};
typedef min_allocator<int> A;
std::list<int, A> c1(a1, a1+sizeof(a1)/sizeof(a1[0]), A());
std::list<int, A> c2(a2, a2+sizeof(a2)/sizeof(a2[0]), A());
swap(c1, c2);
assert((c1 == std::list<int, A>(a2, a2+sizeof(a2)/sizeof(a2[0]))));
assert(c1.get_allocator() == A());
assert((c2 == std::list<int, A>(a1, a1+sizeof(a1)/sizeof(a1[0]))));
assert(c2.get_allocator() == A());
}
#endif
#endif
}

View File

@ -25,6 +25,8 @@
#include <list>
#include <type_traits>
#include "../../min_allocator.h"
int main()
{
static_assert((std::is_same<std::list<int>::value_type, int>::value), "");
@ -33,4 +35,12 @@ int main()
static_assert((std::is_same<std::list<int>::const_reference, std::allocator<int>::const_reference>::value), "");
static_assert((std::is_same<std::list<int>::pointer, std::allocator<int>::pointer>::value), "");
static_assert((std::is_same<std::list<int>::const_pointer, std::allocator<int>::const_pointer>::value), "");
#if __cplusplus >= 201103L
static_assert((std::is_same<std::list<int, min_allocator<int>>::value_type, int>::value), "");
static_assert((std::is_same<std::list<int, min_allocator<int>>::allocator_type, min_allocator<int> >::value), "");
static_assert((std::is_same<std::list<int, min_allocator<int>>::reference, int&>::value), "");
static_assert((std::is_same<std::list<int, min_allocator<int>>::const_reference, const int&>::value), "");
static_assert((std::is_same<std::list<int, min_allocator<int>>::pointer, min_pointer<int>>::value), "");
static_assert((std::is_same<std::list<int, min_allocator<int>>::const_pointer, min_pointer<const int>>::value), "");
#endif
}