LWG Issue 2210 (Part #2 & #3): list and forward_list

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@190279 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Marshall Clow 2013-09-08 19:11:51 +00:00
parent ab04aadaf4
commit 955f2c88a1
4 changed files with 94 additions and 2 deletions

View File

@ -38,6 +38,7 @@ public:
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit forward_list(const allocator_type& a);
explicit forward_list(size_type n);
explicit forward_list(size_type n, const Allocator& a); // C++14
forward_list(size_type n, const value_type& v);
forward_list(size_type n, const value_type& v, const allocator_type& a);
template <class InputIterator>
@ -571,6 +572,9 @@ public:
{} // = default;
explicit forward_list(const allocator_type& __a);
explicit forward_list(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit forward_list(size_type __n, const allocator_type& __a);
#endif
forward_list(size_type __n, const value_type& __v);
forward_list(size_type __n, const value_type& __v, const allocator_type& __a);
template <class _InputIterator>
@ -794,6 +798,28 @@ forward_list<_Tp, _Alloc>::forward_list(size_type __n)
}
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(size_type __n, const allocator_type& __a)
: base ( __a )
{
if (__n > 0)
{
__node_allocator& __a = base::__alloc();
typedef __allocator_destructor<__node_allocator> _Dp;
unique_ptr<__node, _Dp> __h(nullptr, _Dp(__a, 1));
for (__node_pointer __p = base::__before_begin(); __n > 0; --__n,
__p = __p->__next_)
{
__h.reset(__node_traits::allocate(__a, 1));
__node_traits::construct(__a, _VSTD::addressof(__h->__value_));
__h->__next_ = nullptr;
__p->__next_ = __h.release();
}
}
}
#endif
template <class _Tp, class _Alloc>
forward_list<_Tp, _Alloc>::forward_list(size_type __n, const value_type& __v)
{

View File

@ -40,6 +40,7 @@ public:
noexcept(is_nothrow_default_constructible<allocator_type>::value);
explicit list(const allocator_type& a);
explicit list(size_type n);
explicit list(size_type n, const Allocator& a); // C++14
list(size_type n, const value_type& value);
list(size_type n, const value_type& value, const allocator_type& a);
template <class Iter>
@ -842,13 +843,16 @@ public:
#endif
}
_LIBCPP_INLINE_VISIBILITY
list(const allocator_type& __a) : base(__a)
explicit list(const allocator_type& __a) : base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
}
list(size_type __n);
explicit list(size_type __n);
#if _LIBCPP_STD_VER > 11
explicit list(size_type __n, const allocator_type& __a);
#endif
list(size_type __n, const value_type& __x);
list(size_type __n, const value_type& __x, const allocator_type& __a);
template <class _InpIter>
@ -1100,6 +1104,22 @@ list<_Tp, _Alloc>::list(size_type __n)
#endif
}
#if _LIBCPP_STD_VER > 11
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(size_type __n, const allocator_type& __a) : base(__a)
{
#if _LIBCPP_DEBUG_LEVEL >= 2
__get_db()->__insert_c(this);
#endif
for (; __n > 0; --__n)
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
emplace_back();
#else
push_back(value_type());
#endif
}
#endif
template <class _Tp, class _Alloc>
list<_Tp, _Alloc>::list(size_type __n, const value_type& __x)
{

View File

@ -10,6 +10,7 @@
// <forward_list>
// explicit forward_list(size_type n);
// explicit forward_list(size_type n, const Alloc& a);
#include <forward_list>
#include <cassert>
@ -17,6 +18,17 @@
#include "../../../DefaultOnly.h"
#include "../../../min_allocator.h"
template <class T, class Allocator>
void check_allocator(unsigned n, Allocator const &alloc = Allocator())
{
#if _LIBCPP_STD_VER > 11
typedef std::forward_list<T, Allocator> C;
C d(n, alloc);
assert(d.get_allocator() == alloc);
assert(std::distance(l.begin(), l.end()) == 3);
#endif
}
int main()
{
{
@ -47,6 +59,8 @@ int main()
;
#endif
assert(n == N);
check_allocator<T, min_allocator<T>> ( 0 );
check_allocator<T, min_allocator<T>> ( 3 );
}
#endif
}

View File

@ -17,6 +17,23 @@
#include "../../../stack_allocator.h"
#include "../../../min_allocator.h"
template <class T, class Allocator>
void
test3(unsigned n, Allocator const &alloc = Allocator())
{
#if _LIBCPP_STD_VER > 11
typedef std::list<T, Allocator> C;
typedef typename C::const_iterator const_iterator;
{
C d(n, alloc);
assert(d.size() == n);
assert(std::distance(d.begin(), d.end()) == 3);
assert(d.get_allocator() == alloc);
}
#endif
}
int main()
{
{
@ -41,6 +58,21 @@ int main()
++i;
assert(*i == 0);
}
#if _LIBCPP_STD_VER > 11
{
typedef std::list<int, min_allocator<int> > C;
C l(3, min_allocator<int> ());
assert(l.size() == 3);
assert(std::distance(l.begin(), l.end()) == 3);
C::const_iterator i = l.begin();
assert(*i == 0);
++i;
assert(*i == 0);
++i;
assert(*i == 0);
test3<int, min_allocator<int>> (3);
}
#endif
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
{
std::list<DefaultOnly> l(3);