[libcxx] r190279 - LWG Issue 2210 (Part #2 & #3): list and forward_list

Marshall Clow mclow.lists at gmail.com
Sun Sep 8 12:11:52 PDT 2013


Author: marshall
Date: Sun Sep  8 14:11:51 2013
New Revision: 190279

URL: http://llvm.org/viewvc/llvm-project?rev=190279&view=rev
Log:
LWG Issue 2210 (Part #2 & #3): list and forward_list

Modified:
    libcxx/trunk/include/forward_list
    libcxx/trunk/include/list
    libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp
    libcxx/trunk/test/containers/sequences/list/list.cons/size_type.pass.cpp

Modified: libcxx/trunk/include/forward_list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/forward_list?rev=190279&r1=190278&r2=190279&view=diff
==============================================================================
--- libcxx/trunk/include/forward_list (original)
+++ libcxx/trunk/include/forward_list Sun Sep  8 14:11:51 2013
@@ -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(
     }
 }
 
+#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)
 {

Modified: libcxx/trunk/include/list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/list?rev=190279&r1=190278&r2=190279&view=diff
==============================================================================
--- libcxx/trunk/include/list (original)
+++ libcxx/trunk/include/list Sun Sep  8 14:11:51 2013
@@ -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)
 {

Modified: libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp?rev=190279&r1=190278&r2=190279&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/forwardlist/forwardlist.cons/size.pass.cpp Sun Sep  8 14:11:51 2013
@@ -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
 }

Modified: libcxx/trunk/test/containers/sequences/list/list.cons/size_type.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/containers/sequences/list/list.cons/size_type.pass.cpp?rev=190279&r1=190278&r2=190279&view=diff
==============================================================================
--- libcxx/trunk/test/containers/sequences/list/list.cons/size_type.pass.cpp (original)
+++ libcxx/trunk/test/containers/sequences/list/list.cons/size_type.pass.cpp Sun Sep  8 14:11:51 2013
@@ -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);





More information about the cfe-commits mailing list