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

llvm-svn: 184759
This commit is contained in:
Howard Hinnant 2013-06-24 17:17:28 +00:00
parent 3912d785e3
commit 8a27ba8051
56 changed files with 1591 additions and 61 deletions

View File

@ -232,7 +232,7 @@ public:
typedef forward_iterator_tag iterator_category;
typedef typename pointer_traits<__node_pointer>::element_type::value_type
value_type;
typedef value_type& reference;
typedef value_type& reference;
typedef typename pointer_traits<__node_pointer>::difference_type
difference_type;
typedef typename pointer_traits<__node_pointer>::template
@ -249,7 +249,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __ptr_->__value_;}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return &__ptr_->__value_;}
pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
_LIBCPP_INLINE_VISIBILITY
__forward_list_iterator& operator++()
@ -303,7 +303,7 @@ class _LIBCPP_TYPE_VIS __forward_list_const_iterator
public:
typedef forward_iterator_tag iterator_category;
typedef typename __node::value_type value_type;
typedef const value_type& reference;
typedef const value_type& reference;
typedef typename pointer_traits<__node_const_pointer>::difference_type
difference_type;
typedef typename pointer_traits<__node_const_pointer>::template
@ -323,7 +323,7 @@ public:
_LIBCPP_INLINE_VISIBILITY
reference operator*() const {return __ptr_->__value_;}
_LIBCPP_INLINE_VISIBILITY
pointer operator->() const {return &__ptr_->__value_;}
pointer operator->() const {return pointer_traits<pointer>::pointer_to(__ptr_->__value_);}
_LIBCPP_INLINE_VISIBILITY
__forward_list_const_iterator& operator++()
@ -368,18 +368,27 @@ protected:
__node_allocator;
typedef allocator_traits<__node_allocator> __node_traits;
typedef typename __node_traits::pointer __node_pointer;
typedef typename __node_traits::const_pointer __node_const_pointer;
typedef typename __node_traits::pointer __node_const_pointer;
typedef typename allocator_traits<allocator_type>::template
#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES
rebind_alloc<__begin_node>
#else
rebind_alloc<__begin_node>::other
#endif
__begin_node_allocator;
typedef typename allocator_traits<__begin_node_allocator>::pointer __begin_node_pointer;
__compressed_pair<__begin_node, __node_allocator> __before_begin_;
_LIBCPP_INLINE_VISIBILITY
__node_pointer __before_begin() _NOEXCEPT
{return pointer_traits<__node_pointer>::pointer_to(
static_cast<__node&>(__before_begin_.first()));}
{return static_cast<__node_pointer>(pointer_traits<__begin_node_pointer>::
pointer_to(__before_begin_.first()));}
_LIBCPP_INLINE_VISIBILITY
__node_const_pointer __before_begin() const _NOEXCEPT
{return pointer_traits<__node_const_pointer>::pointer_to(
static_cast<const __node&>(__before_begin_.first()));}
{return static_cast<__node_const_pointer>(pointer_traits<__begin_node_pointer>::
pointer_to(const_cast<__begin_node&>(__before_begin_.first())));}
_LIBCPP_INLINE_VISIBILITY
__node_allocator& __alloc() _NOEXCEPT
@ -389,7 +398,7 @@ protected:
{return __before_begin_.second();}
typedef __forward_list_iterator<__node_pointer> iterator;
typedef __forward_list_const_iterator<__node_const_pointer> const_iterator;
typedef __forward_list_const_iterator<__node_pointer> const_iterator;
_LIBCPP_INLINE_VISIBILITY
__forward_list_base()
@ -1050,7 +1059,7 @@ template <class... _Args>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::emplace_after(const_iterator __p, _Args&&... __args)
{
__node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
__node_pointer const __r = __p.__ptr_;
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@ -1067,7 +1076,7 @@ template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, value_type&& __v)
{
__node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
__node_pointer const __r = __p.__ptr_;
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@ -1083,7 +1092,7 @@ template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, const value_type& __v)
{
__node_pointer const __r = const_cast<__node_pointer>(__p.__ptr_);
__node_pointer const __r = __p.__ptr_;
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(__node_traits::allocate(__a, 1), _Dp(__a, 1));
@ -1098,7 +1107,7 @@ typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p, size_type __n,
const value_type& __v)
{
__node_pointer __r = const_cast<__node_pointer>(__p.__ptr_);
__node_pointer __r = __p.__ptr_;
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
@ -1148,7 +1157,7 @@ typename enable_if
forward_list<_Tp, _Alloc>::insert_after(const_iterator __p,
_InputIterator __f, _InputIterator __l)
{
__node_pointer __r = const_cast<__node_pointer>(__p.__ptr_);
__node_pointer __r = __p.__ptr_;
if (__f != __l)
{
__node_allocator& __a = base::__alloc();
@ -1192,7 +1201,7 @@ template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f)
{
__node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
__node_pointer __p = __f.__ptr_;
__node_pointer __n = __p->__next_;
__p->__next_ = __n->__next_;
__node_allocator& __a = base::__alloc();
@ -1205,10 +1214,10 @@ template <class _Tp, class _Alloc>
typename forward_list<_Tp, _Alloc>::iterator
forward_list<_Tp, _Alloc>::erase_after(const_iterator __f, const_iterator __l)
{
__node_pointer __e = const_cast<__node_pointer>(__l.__ptr_);
__node_pointer __e = __l.__ptr_;
if (__f != __l)
{
__node_pointer __p = const_cast<__node_pointer>(__f.__ptr_);
__node_pointer __p = __f.__ptr_;
__node_pointer __n = __p->__next_;
if (__n != __e)
{
@ -1302,12 +1311,10 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
const_iterator __lm1 = __x.before_begin();
while (__lm1.__ptr_->__next_ != nullptr)
++__lm1;
const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
const_cast<__node_pointer>(__p.__ptr_)->__next_;
__lm1.__ptr_->__next_ = __p.__ptr_->__next_;
}
const_cast<__node_pointer>(__p.__ptr_)->__next_ =
const_cast<__node_pointer>(__x.__before_begin())->__next_;
const_cast<__node_pointer>(__x.__before_begin())->__next_ = nullptr;
__p.__ptr_->__next_ = __x.__before_begin()->__next_;
__x.__before_begin()->__next_ = nullptr;
}
}
@ -1320,12 +1327,9 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
const_iterator __lm1 = _VSTD::next(__i);
if (__p != __i && __p != __lm1)
{
const_cast<__node_pointer>(__i.__ptr_)->__next_ =
const_cast<__node_pointer>(__lm1.__ptr_)->__next_;
const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
const_cast<__node_pointer>(__p.__ptr_)->__next_;
const_cast<__node_pointer>(__p.__ptr_)->__next_ =
const_cast<__node_pointer>(__lm1.__ptr_);
__i.__ptr_->__next_ = __lm1.__ptr_->__next_;
__lm1.__ptr_->__next_ = __p.__ptr_->__next_;
__p.__ptr_->__next_ = __lm1.__ptr_;
}
}
@ -1342,12 +1346,9 @@ forward_list<_Tp, _Alloc>::splice_after(const_iterator __p,
++__lm1;
if (__f != __lm1)
{
const_cast<__node_pointer>(__lm1.__ptr_)->__next_ =
const_cast<__node_pointer>(__p.__ptr_)->__next_;
const_cast<__node_pointer>(__p.__ptr_)->__next_ =
const_cast<__node_pointer>(__f.__ptr_)->__next_;
const_cast<__node_pointer>(__f.__ptr_)->__next_ =
const_cast<__node_pointer>(__l.__ptr_);
__lm1.__ptr_->__next_ = __p.__ptr_->__next_;
__p.__ptr_->__next_ = __f.__ptr_->__next_;
__f.__ptr_->__next_ = __l.__ptr_;
}
}
}

View File

@ -16,6 +16,8 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
int main()
{
{
@ -36,4 +38,24 @@ int main()
assert(c.front() == 0);
assert(*c.begin() == 0);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_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));
assert(c.front() == 0);
c.front() = 10;
assert(c.front() == 10);
assert(*c.begin() == 10);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const C c(std::begin(t), std::end(t));
assert(c.front() == 0);
assert(*c.begin() == 0);
}
#endif
}

View File

@ -16,6 +16,7 @@
#include "../../../test_allocator.h"
#include "../../../NotConstructible.h"
#include "../../../min_allocator.h"
int main()
{
@ -27,4 +28,14 @@ int main()
assert(c.get_allocator() == A(12));
assert(c.empty());
}
#if __cplusplus >= 201103L
{
typedef min_allocator<NotConstructible> A;
typedef A::value_type T;
typedef std::forward_list<T, A> C;
C c(A{});
assert(c.get_allocator() == A());
assert(c.empty());
}
#endif
}

View File

@ -16,6 +16,7 @@
#include <iterator>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -116,4 +117,30 @@ int main()
assert(c1 == c0);
assert(c1.get_allocator() == A(10));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<int> A;
typedef std::forward_list<T, A> C;
const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const T t1[] = {10, 11, 12, 13};
C c0(std::begin(t0), std::end(t0), A());
C c1(std::begin(t1), std::end(t1), A());
c1 = c0;
assert(c1 == c0);
assert(c1.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<int> A;
typedef std::forward_list<T, A> C;
const T t0[] = {10, 11, 12, 13};
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c0(std::begin(t0), std::end(t0), A());
C c1(std::begin(t1), std::end(t1), A());
c1 = c0;
assert(c1 == c0);
assert(c1.get_allocator() == A());
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@ -40,5 +42,29 @@ int main()
assert(*i == 10+n);
assert(n == 4);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {10, 11, 12, 13};
C c(std::begin(t1), std::end(t1));
c.assign({0, 1, 2, 3, 4, 5, 6, 7, 8, 9});
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == n);
assert(n == 10);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t1), std::end(t1));
c.assign({10, 11, 12, 13});
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == 10+n);
assert(n == 4);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -17,6 +17,7 @@
#include "../../../test_allocator.h"
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -158,5 +159,41 @@ int main()
assert(c1.get_allocator() == A(10));
assert(c0.empty());
}
#if __cplusplus >= 201103L
{
typedef MoveOnly T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
T t1[] = {10, 11, 12, 13};
typedef std::move_iterator<T*> I;
C c0(I(std::begin(t0)), I(std::end(t0)), A());
C c1(I(std::begin(t1)), I(std::end(t1)), A());
c1 = std::move(c0);
int n = 0;
for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
assert(*i == n);
assert(n == 10);
assert(c1.get_allocator() == A());
assert(c0.empty());
}
{
typedef MoveOnly T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
T t0[] = {10, 11, 12, 13};
T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
typedef std::move_iterator<T*> I;
C c0(I(std::begin(t0)), I(std::end(t0)), A());
C c1(I(std::begin(t1)), I(std::end(t1)), A());
c1 = std::move(c0);
int n = 0;
for (C::const_iterator i = c1.cbegin(); i != c1.cend(); ++i, ++n)
assert(*i == 10+n);
assert(n == 4);
assert(c1.get_allocator() == A());
assert(c0.empty());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -15,6 +15,8 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@ -40,5 +42,29 @@ int main()
assert(*i == 10+n);
assert(n == 4);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {10, 11, 12, 13};
C c(std::begin(t1), std::end(t1));
c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == n);
assert(n == 10);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t1), std::end(t1));
c = {10, 11, 12, 13};
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == 10+n);
assert(n == 4);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -17,6 +17,7 @@
#include <iterator>
#include "test_iterators.h"
#include "../../../min_allocator.h"
int main()
{
@ -46,4 +47,32 @@ int main()
assert(*i == 10+n);
assert(n == 4);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t0[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const T t1[] = {10, 11, 12, 13};
C c(std::begin(t1), std::end(t1));
typedef input_iterator<const T*> I;
c.assign(I(std::begin(t0)), I(std::end(t0)));
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == n);
assert(n == 10);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t0[] = {10, 11, 12, 13};
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t1), std::end(t1));
typedef input_iterator<const T*> I;
c.assign(I(std::begin(t0)), I(std::end(t0)));
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == 10+n);
assert(n == 4);
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
int main()
{
{
@ -39,4 +41,28 @@ int main()
assert(*i == 10);
assert(n == 4);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {10, 11, 12, 13};
C c(std::begin(t1), std::end(t1));
c.assign(10, 1);
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == 1);
assert(n == 10);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(std::begin(t1), std::end(t1));
c.assign(4, 10);
int n = 0;
for (C::const_iterator i = c.cbegin(); i != c.cend(); ++i, ++n)
assert(*i == 10);
assert(n == 4);
}
#endif
}

View File

@ -16,6 +16,7 @@
#include <iterator>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -49,4 +50,20 @@ int main()
assert(c.get_allocator() == A(-2));
}
#endif // _LIBCPP_HAS_NO_ADVANCED_SFINAE
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<int> A;
typedef std::forward_list<T, A> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c0(std::begin(t), std::end(t), A());
C c = c0;
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
assert(c == c0);
assert(c.get_allocator() == A());
}
#endif
}

View File

@ -16,6 +16,7 @@
#include <iterator>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -47,4 +48,20 @@ int main()
assert(c == c0);
assert(c.get_allocator() == A(9));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<int> A;
typedef std::forward_list<T, A> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c0(std::begin(t), std::end(t), A());
C c(c0, A());
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
assert(c == c0);
assert(c.get_allocator() == A());
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -22,4 +24,12 @@ int main()
C c;
assert(c.empty());
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
assert(c.empty());
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@ -26,5 +28,16 @@ int main()
assert(*i == n);
assert(n == 10);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == 10);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -30,5 +31,18 @@ int main()
assert(n == 10);
assert(c.get_allocator() == A(14));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
C c({0, 1, 2, 3, 4, 5, 6, 7, 8, 9}, A());
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == 10);
assert(c.get_allocator() == A());
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -17,6 +17,7 @@
#include "../../../test_allocator.h"
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -51,5 +52,22 @@ int main()
assert(c0.empty());
assert(c.get_allocator() == A(10));
}
#if __cplusplus >= 201103L
{
typedef MoveOnly T;
typedef min_allocator<int> A;
typedef std::forward_list<T, A> C;
T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
typedef std::move_iterator<T*> I;
C c0(I(std::begin(t)), I(std::end(t)), A());
C c = std::move(c0);
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
assert(c0.empty());
assert(c.get_allocator() == A());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -17,6 +17,7 @@
#include "../../../test_allocator.h"
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -51,5 +52,22 @@ int main()
assert(!c0.empty());
assert(c.get_allocator() == A(9));
}
#if __cplusplus >= 201103L
{
typedef MoveOnly T;
typedef min_allocator<int> A;
typedef std::forward_list<T, A> C;
T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
typedef std::move_iterator<T*> I;
C c0(I(std::begin(t)), I(std::end(t)), A());
C c(std::move(c0), A());
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
assert(c0.empty());
assert(c.get_allocator() == A());
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -17,6 +17,7 @@
#include <iterator>
#include "test_iterators.h"
#include "../../../min_allocator.h"
int main()
{
@ -31,4 +32,17 @@ int main()
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef input_iterator<const T*> I;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(I(std::begin(t)), I(std::end(t)));
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
}
#endif
}

View File

@ -19,6 +19,7 @@
#include "../../../test_allocator.h"
#include "test_iterators.h"
#include "../../../min_allocator.h"
int main()
{
@ -35,4 +36,19 @@ int main()
assert(n == std::end(t) - std::begin(t));
assert(c.get_allocator() == A(13));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
typedef input_iterator<const T*> I;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
C c(I(std::begin(t)), I(std::end(t)), A());
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == n);
assert(n == std::end(t) - std::begin(t));
assert(c.get_allocator() == A());
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -32,4 +33,20 @@ int main()
#endif
assert(n == N);
}
#if __cplusplus >= 201103L
{
typedef DefaultOnly T;
typedef std::forward_list<T, min_allocator<T>> C;
unsigned N = 10;
C c(N);
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
assert(*i == T());
#else
;
#endif
assert(n == N);
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -27,4 +29,17 @@ int main()
assert(*i == v);
assert(n == N);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
T v(6);
unsigned N = 10;
C c(N, v);
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == v);
assert(n == N);
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -31,4 +32,19 @@ int main()
assert(n == N);
assert(c.get_allocator() == A(12));
}
#if __cplusplus >= 201103L
{
typedef min_allocator<int> A;
typedef A::value_type T;
typedef std::forward_list<T, A> C;
T v(6);
unsigned N = 10;
C c(N, v, A());
unsigned n = 0;
for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
assert(*i == v);
assert(n == N);
assert(c.get_allocator() == A());
}
#endif
}

View File

@ -17,6 +17,8 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
int main()
{
{
@ -58,4 +60,45 @@ int main()
C::const_iterator i = c.before_begin();
assert(std::distance(i, c.end()) == 11);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
C::iterator i = c.before_begin();
assert(std::distance(i, c.end()) == 1);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const C c;
C::const_iterator i = c.before_begin();
assert(std::distance(i, c.end()) == 1);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const C c;
C::const_iterator i = c.cbefore_begin();
assert(std::distance(i, c.end()) == 1);
assert(c.cbefore_begin() == c.before_begin());
}
{
typedef int T;
typedef std::forward_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.before_begin();
assert(std::distance(i, c.end()) == 11);
assert(std::next(c.before_begin()) == c.begin());
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
const C c(std::begin(t), std::end(t));
C::const_iterator i = c.before_begin();
assert(std::distance(i, c.end()) == 11);
}
#endif
}

View File

@ -20,6 +20,8 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
int main()
{
{
@ -69,4 +71,53 @@ int main()
C::iterator i;
C::const_iterator j;
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_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::forward_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::forward_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::forward_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::forward_list<T, min_allocator<T>> C;
C::iterator i;
C::const_iterator j;
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../NotConstructible.h"
#include "../../../min_allocator.h"
int main()
{
@ -37,4 +38,25 @@ int main()
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
#if __cplusplus >= 201103L
{
typedef NotConstructible T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
c.clear();
assert(distance(c.begin(), c.end()) == 0);
c.clear();
assert(distance(c.begin(), c.end()) == 0);
}
#endif
}

View File

@ -16,6 +16,7 @@
#include <cassert>
#include "../../../Emplaceable.h"
#include "../../../min_allocator.h"
int main()
{
@ -51,5 +52,38 @@ int main()
assert(*next(c.begin(), 3) == Emplaceable(2, 3.5));
assert(distance(c.begin(), c.end()) == 4);
}
#if __cplusplus >= 201103L
{
typedef Emplaceable T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef C::iterator I;
C c;
I i = c.emplace_after(c.cbefore_begin());
assert(i == c.begin());
assert(c.front() == Emplaceable());
assert(distance(c.begin(), c.end()) == 1);
i = c.emplace_after(c.cbegin(), 1, 2.5);
assert(i == next(c.begin()));
assert(c.front() == Emplaceable());
assert(*next(c.begin()) == Emplaceable(1, 2.5));
assert(distance(c.begin(), c.end()) == 2);
i = c.emplace_after(next(c.cbegin()), 2, 3.5);
assert(i == next(c.begin(), 2));
assert(c.front() == Emplaceable());
assert(*next(c.begin()) == Emplaceable(1, 2.5));
assert(*next(c.begin(), 2) == Emplaceable(2, 3.5));
assert(distance(c.begin(), c.end()) == 3);
i = c.emplace_after(c.cbegin(), 3, 4.5);
assert(i == next(c.begin()));
assert(c.front() == Emplaceable());
assert(*next(c.begin(), 1) == Emplaceable(3, 4.5));
assert(*next(c.begin(), 2) == Emplaceable(1, 2.5));
assert(*next(c.begin(), 3) == Emplaceable(2, 3.5));
assert(distance(c.begin(), c.end()) == 4);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../Emplaceable.h"
#include "../../../min_allocator.h"
int main()
{
@ -31,5 +32,19 @@ int main()
assert(*next(c.begin()) == Emplaceable());
assert(distance(c.begin(), c.end()) == 2);
}
#if __cplusplus >= 201103L
{
typedef Emplaceable T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.emplace_front();
assert(c.front() == Emplaceable());
assert(distance(c.begin(), c.end()) == 1);
c.emplace_front(1, 2.5);
assert(c.front() == Emplaceable(1, 2.5));
assert(*next(c.begin()) == Emplaceable());
assert(distance(c.begin(), c.end()) == 2);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -82,4 +84,72 @@ int main()
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 0);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_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.erase_after(next(c.cbefore_begin(), 4), next(c.cbefore_begin(), 4));
assert(i == next(c.cbefore_begin(), 4));
assert(distance(c.begin(), c.end()) == 10);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 3);
assert(*next(c.begin(), 4) == 4);
assert(*next(c.begin(), 5) == 5);
assert(*next(c.begin(), 6) == 6);
assert(*next(c.begin(), 7) == 7);
assert(*next(c.begin(), 8) == 8);
assert(*next(c.begin(), 9) == 9);
i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 5));
assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 8);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 4);
assert(*next(c.begin(), 3) == 5);
assert(*next(c.begin(), 4) == 6);
assert(*next(c.begin(), 5) == 7);
assert(*next(c.begin(), 6) == 8);
assert(*next(c.begin(), 7) == 9);
i = c.erase_after(next(c.cbefore_begin(), 2), next(c.cbefore_begin(), 3));
assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 8);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 4);
assert(*next(c.begin(), 3) == 5);
assert(*next(c.begin(), 4) == 6);
assert(*next(c.begin(), 5) == 7);
assert(*next(c.begin(), 6) == 8);
assert(*next(c.begin(), 7) == 9);
i = c.erase_after(next(c.cbefore_begin(), 5), next(c.cbefore_begin(), 9));
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 5);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 4);
assert(*next(c.begin(), 3) == 5);
assert(*next(c.begin(), 4) == 6);
i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 2));
assert(i == c.begin());
assert(distance(c.begin(), c.end()) == 4);
assert(*next(c.begin(), 0) == 1);
assert(*next(c.begin(), 1) == 4);
assert(*next(c.begin(), 2) == 5);
assert(*next(c.begin(), 3) == 6);
i = c.erase_after(next(c.cbefore_begin(), 0), next(c.cbefore_begin(), 5));
assert(i == c.begin());
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 0);
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -53,4 +55,43 @@ int main()
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 0);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
C::iterator i = c.erase_after(next(c.cbefore_begin(), 4));
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 4);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 3);
i = c.erase_after(next(c.cbefore_begin(), 0));
assert(i == c.begin());
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 1);
assert(*next(c.begin(), 1) == 2);
assert(*next(c.begin(), 2) == 3);
i = c.erase_after(next(c.cbefore_begin(), 1));
assert(i == next(c.begin()));
assert(distance(c.begin(), c.end()) == 2);
assert(*next(c.begin(), 0) == 1);
assert(*next(c.begin(), 1) == 3);
i = c.erase_after(next(c.cbefore_begin(), 1));
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 1);
assert(*next(c.begin(), 0) == 1);
i = c.erase_after(next(c.cbefore_begin(), 0));
assert(i == c.begin());
assert(i == c.end());
assert(distance(c.begin(), c.end()) == 0);
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -48,4 +50,38 @@ int main()
assert(*next(c.begin(), 3) == 2);
assert(distance(c.begin(), c.end()) == 4);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef C::iterator I;
C c;
I i = c.insert_after(c.cbefore_begin(), 0);
assert(i == c.begin());
assert(c.front() == 0);
assert(c.front() == 0);
assert(distance(c.begin(), c.end()) == 1);
i = c.insert_after(c.cbegin(), 1);
assert(i == next(c.begin()));
assert(c.front() == 0);
assert(*next(c.begin()) == 1);
assert(distance(c.begin(), c.end()) == 2);
i = c.insert_after(next(c.cbegin()), 2);
assert(i == next(c.begin(), 2));
assert(c.front() == 0);
assert(*next(c.begin()) == 1);
assert(*next(c.begin(), 2) == 2);
assert(distance(c.begin(), c.end()) == 3);
i = c.insert_after(c.cbegin(), 3);
assert(i == next(c.begin()));
assert(c.front() == 0);
assert(*next(c.begin(), 1) == 3);
assert(*next(c.begin(), 2) == 1);
assert(*next(c.begin(), 3) == 2);
assert(distance(c.begin(), c.end()) == 4);
}
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
@ -42,5 +44,32 @@ int main()
assert(*next(c.begin(), 3) == 1);
assert(*next(c.begin(), 4) == 2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef C::iterator I;
C c;
I i = c.insert_after(c.cbefore_begin(), {});
assert(i == c.before_begin());
assert(distance(c.begin(), c.end()) == 0);
i = c.insert_after(c.cbefore_begin(), {0, 1, 2});
assert(i == next(c.before_begin(), 3));
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
i = c.insert_after(c.begin(), {3, 4});
assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 5);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 3);
assert(*next(c.begin(), 2) == 4);
assert(*next(c.begin(), 3) == 1);
assert(*next(c.begin(), 4) == 2);
}
#endif
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
}

View File

@ -17,6 +17,7 @@
#include <cassert>
#include "test_iterators.h"
#include "../../../min_allocator.h"
int main()
{
@ -47,4 +48,33 @@ int main()
assert(*next(c.begin(), 3) == 1);
assert(*next(c.begin(), 4) == 2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef C::iterator I;
typedef input_iterator<const T*> J;
C c;
const T t[] = {0, 1, 2, 3, 4};
I i = c.insert_after(c.cbefore_begin(), J(t), J(t));
assert(i == c.before_begin());
assert(distance(c.begin(), c.end()) == 0);
i = c.insert_after(c.cbefore_begin(), J(t), J(t+3));
assert(i == next(c.before_begin(), 3));
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
i = c.insert_after(c.begin(), J(t+3), J(t+5));
assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 5);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 3);
assert(*next(c.begin(), 2) == 4);
assert(*next(c.begin(), 3) == 1);
assert(*next(c.begin(), 4) == 2);
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -51,5 +52,39 @@ int main()
assert(*next(c.begin(), 3) == 2);
assert(distance(c.begin(), c.end()) == 4);
}
#if __cplusplus >= 201103L
{
typedef MoveOnly T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef C::iterator I;
C c;
I i = c.insert_after(c.cbefore_begin(), 0);
assert(i == c.begin());
assert(c.front() == 0);
assert(c.front() == 0);
assert(distance(c.begin(), c.end()) == 1);
i = c.insert_after(c.cbegin(), 1);
assert(i == next(c.begin()));
assert(c.front() == 0);
assert(*next(c.begin()) == 1);
assert(distance(c.begin(), c.end()) == 2);
i = c.insert_after(next(c.cbegin()), 2);
assert(i == next(c.begin(), 2));
assert(c.front() == 0);
assert(*next(c.begin()) == 1);
assert(*next(c.begin(), 2) == 2);
assert(distance(c.begin(), c.end()) == 3);
i = c.insert_after(c.cbegin(), 3);
assert(i == next(c.begin()));
assert(c.front() == 0);
assert(*next(c.begin(), 1) == 3);
assert(*next(c.begin(), 2) == 1);
assert(*next(c.begin(), 3) == 2);
assert(distance(c.begin(), c.end()) == 4);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -41,4 +43,31 @@ int main()
assert(*next(c.begin(), 3) == 3);
assert(*next(c.begin(), 4) == 3);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef C::iterator I;
C c;
I i = c.insert_after(c.cbefore_begin(), 0, 0);
assert(i == c.before_begin());
assert(distance(c.begin(), c.end()) == 0);
i = c.insert_after(c.cbefore_begin(), 3, 3);
assert(i == next(c.before_begin(), 3));
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 3);
assert(*next(c.begin(), 1) == 3);
assert(*next(c.begin(), 2) == 3);
i = c.insert_after(c.begin(), 2, 2);
assert(i == next(c.begin(), 2));
assert(distance(c.begin(), c.end()) == 5);
assert(*next(c.begin(), 0) == 3);
assert(*next(c.begin(), 1) == 2);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 3);
assert(*next(c.begin(), 4) == 3);
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -45,4 +46,33 @@ int main()
assert(distance(c.begin(), c.end()) == 0);
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.push_front(1);
c.push_front(3);
c.pop_front();
assert(distance(c.begin(), c.end()) == 1);
assert(c.front() == 1);
c.pop_front();
assert(distance(c.begin(), c.end()) == 0);
}
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
typedef MoveOnly T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.push_front(1);
c.push_front(3);
c.pop_front();
assert(distance(c.begin(), c.end()) == 1);
assert(c.front() == 1);
c.pop_front();
assert(distance(c.begin(), c.end()) == 0);
}
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -28,4 +30,18 @@ int main()
assert(*next(c.begin()) == 1);
assert(distance(c.begin(), c.end()) == 2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.push_front(1);
assert(c.front() == 1);
assert(distance(c.begin(), c.end()) == 1);
c.push_front(3);
assert(c.front() == 3);
assert(*next(c.begin()) == 1);
assert(distance(c.begin(), c.end()) == 2);
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../MoveOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -31,5 +32,19 @@ int main()
assert(*next(c.begin()) == 1);
assert(distance(c.begin(), c.end()) == 2);
}
#if __cplusplus >= 201103L
{
typedef MoveOnly T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.push_front(1);
assert(c.front() == 1);
assert(distance(c.begin(), c.end()) == 1);
c.push_front(3);
assert(c.front() == 3);
assert(*next(c.begin()) == 1);
assert(distance(c.begin(), c.end()) == 2);
}
#endif
#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -63,4 +64,51 @@ int main()
assert(*next(c.begin(), 4) == 0);
assert(*next(c.begin(), 5) == 0);
}
#if __cplusplus >= 201103L
{
typedef DefaultOnly T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
c.resize(0);
assert(distance(c.begin(), c.end()) == 0);
c.resize(10);
assert(distance(c.begin(), c.end()) == 10);
c.resize(20);
assert(distance(c.begin(), c.end()) == 20);
c.resize(5);
assert(distance(c.begin(), c.end()) == 5);
c.resize(0);
assert(distance(c.begin(), c.end()) == 0);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
c.resize(3);
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
c.resize(6);
assert(distance(c.begin(), c.end()) == 6);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 0);
assert(*next(c.begin(), 4) == 0);
assert(*next(c.begin(), 5) == 0);
c.resize(6);
assert(distance(c.begin(), c.end()) == 6);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 0);
assert(*next(c.begin(), 4) == 0);
assert(*next(c.begin(), 5) == 0);
}
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
int main()
{
@ -48,4 +49,36 @@ int main()
assert(*next(c.begin(), 4) == 10);
assert(*next(c.begin(), 5) == 10);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t[] = {0, 1, 2, 3, 4};
C c(std::begin(t), std::end(t));
c.resize(3, 10);
assert(distance(c.begin(), c.end()) == 3);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
c.resize(6, 10);
assert(distance(c.begin(), c.end()) == 6);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 10);
assert(*next(c.begin(), 4) == 10);
assert(*next(c.begin(), 5) == 10);
c.resize(6, 12);
assert(distance(c.begin(), c.end()) == 6);
assert(*next(c.begin(), 0) == 0);
assert(*next(c.begin(), 1) == 1);
assert(*next(c.begin(), 2) == 2);
assert(*next(c.begin(), 3) == 10);
assert(*next(c.begin(), 4) == 10);
assert(*next(c.begin(), 5) == 10);
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <iterator>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -29,4 +31,18 @@ int main()
C c3(std::begin(t3), std::end(t3));
assert(c1 == c3);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {3, 5, 6, 7, 12, 13};
const T t2[] = {0, 1, 2, 4, 8, 9, 10, 11, 14, 15};
const T t3[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.merge(c2);
C c3(std::begin(t3), std::end(t3));
assert(c1 == c3);
}
#endif
}

View File

@ -16,6 +16,8 @@
#include <functional>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -30,4 +32,18 @@ int main()
C c3(std::begin(t3), std::end(t3));
assert(c1 == c3);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {13, 12, 7, 6, 5, 3};
const T t2[] = {15, 14, 11, 10, 9, 8, 4, 2, 1, 0};
const T t3[] = {15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.merge(c2, std::greater<T>());
C c3(std::begin(t3), std::end(t3));
assert(c1 == c3);
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <iterator>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -64,4 +66,53 @@ int main()
c1.remove(0);
assert(c1 == c2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 5, 5, 0, 0, 0, 5};
const T t2[] = {5, 5, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.remove(0);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 0, 0, 0};
C c1(std::begin(t1), std::end(t1));
C c2;
c1.remove(0);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5};
const T t2[] = {5, 5, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.remove(0);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c1;
C c2;
c1.remove(0);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5, 0};
const T t2[] = {5, 5, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.remove(0);
assert(c1 == c2);
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <iterator>
#include <cassert>
#include "../../../min_allocator.h"
bool g(int i)
{
return i < 3;
@ -69,4 +71,53 @@ int main()
c1.remove_if(g);
assert(c1 == c2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 5, 5, 0, 0, 0, 5};
const T t2[] = {5, 5, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.remove_if(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 0, 0, 0};
C c1(std::begin(t1), std::end(t1));
C c2;
c1.remove_if(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5};
const T t2[] = {5, 5, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.remove_if(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c1;
C c2;
c1.remove_if(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5, 0};
const T t2[] = {5, 5, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.remove_if(g);
assert(c1 == c2);
}
#endif
}

View File

@ -16,16 +16,17 @@
#include <algorithm>
#include <cassert>
#include "../../../min_allocator.h"
template <class C>
void test(int N)
{
typedef int T;
typedef std::forward_list<T> C;
C c;
for (int i = 0; i < N; ++i)
c.push_front(i);
c.reverse();
assert(distance(c.begin(), c.end()) == N);
C::const_iterator j = c.begin();
typename C::const_iterator j = c.begin();
for (int i = 0; i < N; ++i, ++j)
assert(*j == i);
}
@ -33,5 +34,9 @@ void test(int N)
int main()
{
for (int i = 0; i < 10; ++i)
test(i);
test<std::forward_list<int> >(i);
#if __cplusplus >= 201103L
for (int i = 0; i < 10; ++i)
test<std::forward_list<int, min_allocator<int>> >(i);
#endif
}

View File

@ -17,10 +17,12 @@
#include <vector>
#include <cassert>
#include "../../../min_allocator.h"
template <class C>
void test(int N)
{
typedef int T;
typedef std::forward_list<T> C;
typedef typename C::value_type T;
typedef std::vector<T> V;
V v;
for (int i = 0; i < N; ++i)
@ -29,7 +31,7 @@ void test(int N)
C c(v.begin(), v.end());
c.sort();
assert(distance(c.begin(), c.end()) == N);
C::const_iterator j = c.begin();
typename C::const_iterator j = c.begin();
for (int i = 0; i < N; ++i, ++j)
assert(*j == i);
}
@ -37,5 +39,9 @@ void test(int N)
int main()
{
for (int i = 0; i < 40; ++i)
test(i);
test<std::forward_list<int> >(i);
#if __cplusplus >= 201103L
for (int i = 0; i < 40; ++i)
test<std::forward_list<int, min_allocator<int>> >(i);
#endif
}

View File

@ -18,10 +18,12 @@
#include <functional>
#include <cassert>
#include "../../../min_allocator.h"
template <class C>
void test(int N)
{
typedef int T;
typedef std::forward_list<T> C;
typedef typename C::value_type T;
typedef std::vector<T> V;
V v;
for (int i = 0; i < N; ++i)
@ -30,7 +32,7 @@ void test(int N)
C c(v.begin(), v.end());
c.sort(std::greater<T>());
assert(distance(c.begin(), c.end()) == N);
C::const_iterator j = c.begin();
typename C::const_iterator j = c.begin();
for (int i = 0; i < N; ++i, ++j)
assert(*j == N-1-i);
}
@ -38,5 +40,9 @@ void test(int N)
int main()
{
for (int i = 0; i < 40; ++i)
test(i);
test<std::forward_list<int> >(i);
#if __cplusplus >= 201103L
for (int i = 0; i < 40; ++i)
test<std::forward_list<int, min_allocator<int>> >(i);
#endif
}

View File

@ -15,17 +15,19 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
typedef int T;
typedef std::forward_list<T> C;
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
const T t2[] = {10, 11, 12, 13, 14, 15};
const int size_t1 = std::end(t1) - std::begin(t1);
const int size_t2 = std::end(t2) - std::begin(t2);
template <class C>
void
testd(const C& c, int p, int l)
{
C::const_iterator i = c.begin();
typename C::const_iterator i = c.begin();
int n1 = 0;
for (; n1 < p; ++n1, ++i)
assert(*i == t1[n1]);
@ -38,7 +40,9 @@ testd(const C& c, int p, int l)
int main()
{
{
// splicing different containers
typedef std::forward_list<T> C;
for (int l = 0; l <= size_t2; ++l)
{
for (int p = 0; p <= size_t1; ++p)
@ -50,4 +54,22 @@ int main()
testd(c1, p, l);
}
}
}
#if __cplusplus >= 201103L
{
// splicing different containers
typedef std::forward_list<T, min_allocator<T>> C;
for (int l = 0; l <= size_t2; ++l)
{
for (int p = 0; p <= size_t1; ++p)
{
C c1(std::begin(t1), std::end(t1));
C c2(t2, t2+l);
c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2));
testd(c1, p, l);
}
}
}
#endif
}

View File

@ -15,17 +15,19 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
typedef int T;
typedef std::forward_list<T> C;
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
const T t2[] = {10, 11, 12};
const int size_t1 = std::end(t1) - std::begin(t1);
const int size_t2 = std::end(t2) - std::begin(t2);
template <class C>
void
testd(const C& c, int p, int f)
{
C::const_iterator i = c.begin();
typename C::const_iterator i = c.begin();
int n1 = 0;
for (; n1 < p; ++n1, ++i)
assert(*i == t1[n1]);
@ -36,10 +38,11 @@ testd(const C& c, int p, int f)
assert(distance(c.begin(), c.end()) == size_t1 + 1);
}
template <class C>
void
tests(const C& c, int p, int f)
{
C::const_iterator i = c.begin();
typename C::const_iterator i = c.begin();
int n = 0;
int d = 1;
if (p == f || p == f+1)
@ -74,7 +77,9 @@ tests(const C& c, int p, int f)
int main()
{
{
// splicing different containers
typedef std::forward_list<T> C;
for (int f = 0; f <= size_t2-1; ++f)
{
for (int p = 0; p <= size_t1; ++p)
@ -100,4 +105,36 @@ int main()
tests(c1, p, f);
}
}
}
#if __cplusplus >= 201103L
{
// splicing different containers
typedef std::forward_list<T, min_allocator<T>> C;
for (int f = 0; f <= size_t2-1; ++f)
{
for (int p = 0; p <= size_t1; ++p)
{
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2),
next(c2.cbefore_begin(), f));
testd(c1, p, f);
}
}
// splicing within same container
for (int f = 0; f <= size_t1-1; ++f)
{
for (int p = 0; p <= size_t1; ++p)
{
C c1(std::begin(t1), std::end(t1));
c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1),
next(c1.cbefore_begin(), f));
tests(c1, p, f);
}
}
}
#endif
}

View File

@ -16,17 +16,19 @@
#include <cassert>
#include <iterator>
#include "../../../min_allocator.h"
typedef int T;
typedef std::forward_list<T> C;
const T t1[] = {0, 1, 2, 3, 4, 5, 6, 7};
const T t2[] = {10, 11, 12, 13, 14, 15};
const int size_t1 = std::end(t1) - std::begin(t1);
const int size_t2 = std::end(t2) - std::begin(t2);
template <class C>
void
testd(const C& c, int p, int f, int l)
{
C::const_iterator i = c.begin();
typename C::const_iterator i = c.begin();
int n1 = 0;
for (; n1 < p; ++n1, ++i)
assert(*i == t1[n1]);
@ -37,10 +39,11 @@ testd(const C& c, int p, int f, int l)
assert(distance(c.begin(), c.end()) == size_t1 + (l > f+1 ? l-1-f : 0));
}
template <class C>
void
tests(const C& c, int p, int f, int l)
{
C::const_iterator i = c.begin();
typename C::const_iterator i = c.begin();
int n = 0;
int d = l > f+1 ? l-1-f : 0;
if (d == 0 || p == f)
@ -75,7 +78,9 @@ tests(const C& c, int p, int f, int l)
int main()
{
{
// splicing different containers
typedef std::forward_list<T> C;
for (int f = 0; f <= size_t2+1; ++f)
{
for (int l = f; l <= size_t2+1; ++l)
@ -115,4 +120,50 @@ int main()
}
}
}
}
#if __cplusplus >= 201103L
{
// splicing different containers
typedef std::forward_list<T, min_allocator<T>> C;
for (int f = 0; f <= size_t2+1; ++f)
{
for (int l = f; l <= size_t2+1; ++l)
{
for (int p = 0; p <= size_t1; ++p)
{
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.splice_after(next(c1.cbefore_begin(), p), std::move(c2),
next(c2.cbefore_begin(), f), next(c2.cbefore_begin(), l));
testd(c1, p, f, l);
}
}
}
// splicing within same container
for (int f = 0; f <= size_t1+1; ++f)
{
for (int l = f; l <= size_t1; ++l)
{
for (int p = 0; p <= f; ++p)
{
C c1(std::begin(t1), std::end(t1));
c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1),
next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l));
tests(c1, p, f, l);
}
for (int p = l; p <= size_t1; ++p)
{
C c1(std::begin(t1), std::end(t1));
c1.splice_after(next(c1.cbefore_begin(), p), std::move(c1),
next(c1.cbefore_begin(), f), next(c1.cbefore_begin(), l));
tests(c1, p, f, l);
}
}
}
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <iterator>
#include <cassert>
#include "../../../min_allocator.h"
int main()
{
{
@ -65,4 +67,54 @@ int main()
c1.unique();
assert(c1 == c2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 5, 5, 0, 0, 0, 5};
const T t2[] = {0, 5, 0, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique();
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 0, 0, 0};
const T t2[] = {0};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique();
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5};
const T t2[] = {5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique();
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c1;
C c2;
c1.unique();
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5, 0};
const T t2[] = {5, 0};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique();
assert(c1 == c2);
}
#endif
}

View File

@ -15,6 +15,8 @@
#include <iterator>
#include <cassert>
#include "../../../min_allocator.h"
bool g(int x, int y)
{
return x == y;
@ -70,4 +72,54 @@ int main()
c1.unique(g);
assert(c1 == c2);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 5, 5, 0, 0, 0, 5};
const T t2[] = {0, 5, 0, 5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {0, 0, 0, 0};
const T t2[] = {0};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5};
const T t2[] = {5};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c1;
C c2;
c1.unique(g);
assert(c1 == c2);
}
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
const T t1[] = {5, 5, 5, 0};
const T t2[] = {5, 0};
C c1(std::begin(t1), std::end(t1));
C c2(std::begin(t2), std::end(t2));
c1.unique(g);
assert(c1 == c2);
}
#endif
}

View File

@ -22,10 +22,12 @@
#include <algorithm>
#include <cassert>
#include "../../../min_allocator.h"
template <class C>
void test(int N, int M)
{
typedef int T;
typedef std::forward_list<T> C;
typedef typename C::value_type T;
C c1;
for (int i = 0; i < N; ++i)
c1.push_front(i);
@ -49,5 +51,10 @@ int main()
{
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
test(i, j);
test<std::forward_list<int> >(i, j);
#if __cplusplus >= 201103L
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
test<std::forward_list<int, min_allocator<int>> >(i, j);
#endif
}

View File

@ -15,6 +15,7 @@
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -175,4 +176,84 @@ int main()
assert(distance(c2.begin(), c2.end()) == 0);
assert(c2.get_allocator() == A(1));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
const T t1[] = {0, 1, 2, 3, 4, 5};
C c1(std::begin(t1), std::end(t1), A());
const T t2[] = {10, 11, 12};
C c2(std::begin(t2), std::end(t2), A());
c1.swap(c2);
assert(distance(c1.begin(), c1.end()) == 3);
assert(*next(c1.begin(), 0) == 10);
assert(*next(c1.begin(), 1) == 11);
assert(*next(c1.begin(), 2) == 12);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 6);
assert(*next(c2.begin(), 0) == 0);
assert(*next(c2.begin(), 1) == 1);
assert(*next(c2.begin(), 2) == 2);
assert(*next(c2.begin(), 3) == 3);
assert(*next(c2.begin(), 4) == 4);
assert(*next(c2.begin(), 5) == 5);
assert(c2.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
const T t1[] = {0, 1, 2, 3, 4, 5};
C c1(std::begin(t1), std::end(t1), A());
C c2(A{});
c1.swap(c2);
assert(distance(c1.begin(), c1.end()) == 0);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 6);
assert(*next(c2.begin(), 0) == 0);
assert(*next(c2.begin(), 1) == 1);
assert(*next(c2.begin(), 2) == 2);
assert(*next(c2.begin(), 3) == 3);
assert(*next(c2.begin(), 4) == 4);
assert(*next(c2.begin(), 5) == 5);
assert(c2.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
C c1(A{});
const T t2[] = {10, 11, 12};
C c2(std::begin(t2), std::end(t2), A());
c1.swap(c2);
assert(distance(c1.begin(), c1.end()) == 3);
assert(*next(c1.begin(), 0) == 10);
assert(*next(c1.begin(), 1) == 11);
assert(*next(c1.begin(), 2) == 12);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 0);
assert(c2.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
C c1(A{});
C c2(A{});
c1.swap(c2);
assert(distance(c1.begin(), c1.end()) == 0);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 0);
assert(c2.get_allocator() == A());
}
#endif
}

View File

@ -16,6 +16,7 @@
#include <cassert>
#include "../../../test_allocator.h"
#include "../../../min_allocator.h"
int main()
{
@ -176,4 +177,84 @@ int main()
assert(distance(c2.begin(), c2.end()) == 0);
assert(c2.get_allocator() == A(1));
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
const T t1[] = {0, 1, 2, 3, 4, 5};
C c1(std::begin(t1), std::end(t1), A());
const T t2[] = {10, 11, 12};
C c2(std::begin(t2), std::end(t2), A());
swap(c1, c2);
assert(distance(c1.begin(), c1.end()) == 3);
assert(*next(c1.begin(), 0) == 10);
assert(*next(c1.begin(), 1) == 11);
assert(*next(c1.begin(), 2) == 12);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 6);
assert(*next(c2.begin(), 0) == 0);
assert(*next(c2.begin(), 1) == 1);
assert(*next(c2.begin(), 2) == 2);
assert(*next(c2.begin(), 3) == 3);
assert(*next(c2.begin(), 4) == 4);
assert(*next(c2.begin(), 5) == 5);
assert(c2.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
const T t1[] = {0, 1, 2, 3, 4, 5};
C c1(std::begin(t1), std::end(t1), A());
C c2(A{});
swap(c1, c2);
assert(distance(c1.begin(), c1.end()) == 0);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 6);
assert(*next(c2.begin(), 0) == 0);
assert(*next(c2.begin(), 1) == 1);
assert(*next(c2.begin(), 2) == 2);
assert(*next(c2.begin(), 3) == 3);
assert(*next(c2.begin(), 4) == 4);
assert(*next(c2.begin(), 5) == 5);
assert(c2.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
C c1(A{});
const T t2[] = {10, 11, 12};
C c2(std::begin(t2), std::end(t2), A());
swap(c1, c2);
assert(distance(c1.begin(), c1.end()) == 3);
assert(*next(c1.begin(), 0) == 10);
assert(*next(c1.begin(), 1) == 11);
assert(*next(c1.begin(), 2) == 12);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 0);
assert(c2.get_allocator() == A());
}
{
typedef int T;
typedef min_allocator<T> A;
typedef std::forward_list<T, A> C;
C c1(A{});
C c2(A{});
swap(c1, c2);
assert(distance(c1.begin(), c1.end()) == 0);
assert(c1.get_allocator() == A());
assert(distance(c2.begin(), c2.end()) == 0);
assert(c2.get_allocator() == A());
}
#endif
}

View File

@ -30,10 +30,12 @@
#include <algorithm>
#include <cassert>
#include "../../../min_allocator.h"
template <class C>
void test(int N, int M)
{
typedef int T;
typedef std::forward_list<T> C;
typedef typename C::value_type T;
C c1;
for (int i = 0; i < N; ++i)
c1.push_front(i);
@ -54,5 +56,10 @@ int main()
{
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
test(i, j);
test<std::forward_list<int> >(i, j);
#if __cplusplus >= 201103L
for (int i = 0; i < 10; ++i)
for (int j = 0; j < 10; ++j)
test<std::forward_list<int, min_allocator<int>> >(i, j);
#endif
}

View File

@ -14,6 +14,8 @@
#include <forward_list>
#include <cassert>
#include "../../min_allocator.h"
int main()
{
{
@ -22,4 +24,12 @@ int main()
C c;
assert(c.max_size() > 0);
}
#if __cplusplus >= 201103L
{
typedef int T;
typedef std::forward_list<T, min_allocator<T>> C;
C c;
assert(c.max_size() > 0);
}
#endif
}

View File

@ -28,6 +28,8 @@
#include <forward_list>
#include <type_traits>
#include "../../min_allocator.h"
int main()
{
static_assert((std::is_same<std::forward_list<char>::value_type, char>::value), "");
@ -38,4 +40,14 @@ int main()
static_assert((std::is_same<std::forward_list<char>::const_pointer, const char*>::value), "");
static_assert((std::is_same<std::forward_list<char>::size_type, std::size_t>::value), "");
static_assert((std::is_same<std::forward_list<char>::difference_type, std::ptrdiff_t>::value), "");
#if __cplusplus >= 201103L
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::value_type, char>::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::allocator_type, min_allocator<char> >::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::reference, char&>::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::const_reference, const char&>::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::pointer, min_pointer<char>>::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::const_pointer, min_pointer<const char>>::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::size_type, std::size_t>::value), "");
static_assert((std::is_same<std::forward_list<char, min_allocator<char>>::difference_type, std::ptrdiff_t>::value), "");
#endif
}