$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r81265 - in trunk: boost/smart_ptr boost/smart_ptr/detail libs/smart_ptr libs/smart_ptr/test
From: glenfe_at_[hidden]
Date: 2012-11-09 12:12:58
Author: glenfe
Date: 2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
New Revision: 81265
URL: http://svn.boost.org/trac/boost/changeset/81265
Log:
Add overloads to support fixed size arrays, T[N], to allocate_shared (variadic) and make_shared (variadic) and make_shared_noinit.
Text files modified: 
   trunk/boost/smart_ptr/allocate_shared_array.hpp                 |    17 +++++++++++++++++                       
   trunk/boost/smart_ptr/detail/array_traits.hpp                   |     4 ++++                                    
   trunk/boost/smart_ptr/detail/sp_if_array.hpp                    |     5 ++++-                                   
   trunk/boost/smart_ptr/make_shared_array.hpp                     |    34 ++++++++++++++++++++++++++++++++++      
   trunk/libs/smart_ptr/make_shared_array.html                     |    23 ++++++++++++++++++++---                 
   trunk/libs/smart_ptr/test/allocate_shared_array_create_test.cpp |    36 ++++++++++++++++++++++++++++++++++++    
   trunk/libs/smart_ptr/test/make_shared_array_create_test.cpp     |    36 ++++++++++++++++++++++++++++++++++++    
   trunk/libs/smart_ptr/test/make_shared_arrays_test.cpp           |    26 ++++++++++++++++++++++++++              
   8 files changed, 177 insertions(+), 4 deletions(-)
Modified: trunk/boost/smart_ptr/allocate_shared_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/allocate_shared_array.hpp	(original)
+++ trunk/boost/smart_ptr/allocate_shared_array.hpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -51,6 +51,23 @@
         d2->construct(p2, n1, std::forward<Args>(args)...);
         return shared_ptr<T>(s1, p1);
     }
+    template<typename T, typename A, typename... Args>
+    inline typename detail::sp_if_size_array<T>::type
+    allocate_shared(const A& allocator, Args&&... args) {
+        typedef typename detail::array_inner<T>::type T1;
+        typedef typename detail::array_base<T1>::type T2;
+        T1* p1 = 0;
+        T2* p2 = 0;
+        size_t n1 = detail::array_size<T>::size;
+        detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
+        detail::array_deleter<T2> d1;
+        shared_ptr<T> s1(p1, d1, a1);
+        detail::array_deleter<T2>* d2;
+        p1 = reinterpret_cast<T1*>(p2);
+        d2 = get_deleter<detail::array_deleter<T2> >(s1);
+        d2->construct(p2, n1, std::forward<Args>(args)...);
+        return shared_ptr<T>(s1, p1);
+    }
 #endif
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     template<typename T, typename A>
Modified: trunk/boost/smart_ptr/detail/array_traits.hpp
==============================================================================
--- trunk/boost/smart_ptr/detail/array_traits.hpp	(original)
+++ trunk/boost/smart_ptr/detail/array_traits.hpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -44,6 +44,10 @@
         struct array_inner<T[]> {
             typedef T type;
         };
+        template<typename T, size_t N>
+        struct array_inner<T[N]> {
+            typedef T type;
+        };
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
         template<typename T>
         struct array_list {
Modified: trunk/boost/smart_ptr/detail/sp_if_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/detail/sp_if_array.hpp	(original)
+++ trunk/boost/smart_ptr/detail/sp_if_array.hpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -20,8 +20,11 @@
         struct sp_if_array<T[]> {
             typedef boost::shared_ptr<T[]> type;
         };
+        template<typename T>
+        struct sp_if_size_array {
+        };
         template<typename T, size_t N>
-        struct sp_if_array<T[N]> {
+        struct sp_if_size_array<T[N]> {
             typedef boost::shared_ptr<T[N]> type;
         };
     }
Modified: trunk/boost/smart_ptr/make_shared_array.hpp
==============================================================================
--- trunk/boost/smart_ptr/make_shared_array.hpp	(original)
+++ trunk/boost/smart_ptr/make_shared_array.hpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -51,6 +51,23 @@
         d2->construct(p2, n1, std::forward<Args>(args)...);
         return shared_ptr<T>(s1, p1);
     }
+    template<typename T, typename... Args>
+    inline typename detail::sp_if_size_array<T>::type
+    make_shared(Args&&... args) {
+        typedef typename detail::array_inner<T>::type T1;
+        typedef typename detail::array_base<T1>::type T2;
+        T1* p1 = 0;
+        T2* p2 = 0;
+        size_t n1 = detail::array_size<T>::size;
+        detail::make_array_helper<T2> a1(n1, &p2);
+        detail::array_deleter<T2> d1;
+        shared_ptr<T> s1(p1, d1, a1);
+        detail::array_deleter<T2>* d2;
+        p1 = reinterpret_cast<T1*>(p2);        
+        d2 = get_deleter<detail::array_deleter<T2> >(s1);
+        d2->construct(p2, n1, std::forward<Args>(args)...);
+        return shared_ptr<T>(s1, p1);
+    }
 #endif
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     template<typename T>
@@ -91,6 +108,23 @@
         d2->construct_noinit(p2, n1);
         return shared_ptr<T>(s1, p1);
     }
+    template<typename T>
+    inline typename detail::sp_if_size_array<T>::type
+    make_shared_noinit() {
+        typedef typename detail::array_inner<T>::type T1;
+        typedef typename detail::array_base<T1>::type T2;
+        T1* p1 = 0;
+        T2* p2 = 0;
+        size_t n1 = detail::array_size<T>::size;
+        detail::make_array_helper<T2> a1(n1, &p2);
+        detail::array_deleter<T2> d1;
+        shared_ptr<T> s1(p1, d1, a1);
+        detail::array_deleter<T2>* d2;
+        p1 = reinterpret_cast<T1*>(p2);        
+        d2 = get_deleter<detail::array_deleter<T2> >(s1);
+        d2->construct_noinit(p2, n1);
+        return shared_ptr<T>(s1, p1);
+    }
 }
 
 #endif
Modified: trunk/libs/smart_ptr/make_shared_array.html
==============================================================================
--- trunk/libs/smart_ptr/make_shared_array.html	(original)
+++ trunk/libs/smart_ptr/make_shared_array.html	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -28,21 +28,38 @@
     <h2><a name="Synopsis">Synopsis</a></h2>
     <pre>namespace boost {
     template<typename T>
-    shared_ptr<T> make_shared(size_t size);
+    shared_ptr<T[]> make_shared(size_t size);
 
     template<typename T, typename A>
-    shared_ptr<T> allocate_shared(const A& allocator, size_t size);
+    shared_ptr<T[]> allocate_shared(const A& allocator, size_t size);
     
 #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
     template<typename T, typename... Args>
-    shared_ptr<T> make_shared(size_t size, Args&&... args);
+    shared_ptr<T[]> make_shared(size_t size, Args&&... args);
+    
+    template<typename T, typename... Args>
+    shared_ptr<T[N]> make_shared(Args&&... args);
     
     template<typename T, typename A, typename... Args>
     shared_ptr<T> allocate_shared(const A& allocator, size_t size, Args&&... args);
+    
+    template<typename T, typename A, typename... Args>
+    shared_ptr<T[N]> allocate_shared(const A& allocator, Args&&... args);
+#endif
+
+#if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
+    template<typename T, typename... Args>
+    shared_ptr<T[]> make_shared(std::initializer_list<T> list);
+        
+    template<typename T, typename A, typename... Args>
+    shared_ptr<T[]> allocate_shared(const A& allocator, std::initializer_list<T> list);
 #endif
 
     template<typename T>
     shared_ptr<T> make_shared_noinit(size_t size);
+    
+    template<typename T>
+    shared_ptr<T[N]> make_shared_noinit();
 }</pre>
     <h2><a name="functions">Free Functions</a></h2>
     <pre>template<typename T, typename... Args>
Modified: trunk/libs/smart_ptr/test/allocate_shared_array_create_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/allocate_shared_array_create_test.cpp	(original)
+++ trunk/libs/smart_ptr/test/allocate_shared_array_create_test.cpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -48,6 +48,15 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2]> a1 = boost::allocate_shared<type[2]>(std::allocator<type>(), 1, 2, 3, 4, 5, 6, 7, 8, 9);
+        BOOST_TEST(type::instances == 2);
+        BOOST_TEST(a1[0].a == 1);
+        BOOST_TEST(a1[0].d == 4);
+        BOOST_TEST(a1[1].f == 6);
+        BOOST_TEST(a1[1].i == 9);
+    }
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<type[][2]> a1 = boost::allocate_shared<type[][2]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5, 6, 7);
         BOOST_TEST(type::instances == 4);
         BOOST_TEST(a1[0][0].a == 1);
@@ -57,6 +66,15 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2][2]> a1 = boost::allocate_shared<type[2][2]>(std::allocator<type>(), 1, 2, 3, 4, 5, 6, 7);
+        BOOST_TEST(type::instances == 4);
+        BOOST_TEST(a1[0][0].a == 1);
+        BOOST_TEST(a1[0][1].d == 4);
+        BOOST_TEST(a1[1][0].f == 6);
+        BOOST_TEST(a1[1][1].i == 0);
+    }
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<type[][2][2]> a1 = boost::allocate_shared<type[][2][2]>(std::allocator<type>(), 2, 1, 2, 3, 4, 5);
         BOOST_TEST(type::instances == 8);
         BOOST_TEST(a1[0][0][0].a == 1);
@@ -66,6 +84,15 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2][2][2]> a1 = boost::allocate_shared<type[2][2][2]>(std::allocator<type>(), 1, 2, 3, 4, 5);
+        BOOST_TEST(type::instances == 8);
+        BOOST_TEST(a1[0][0][0].a == 1);
+        BOOST_TEST(a1[0][1][0].c == 3);
+        BOOST_TEST(a1[1][0][1].e == 5);
+        BOOST_TEST(a1[1][1][1].i == 0);
+    }
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<type[][2][2][2]> a1 = boost::allocate_shared<type[][2][2][2]>(std::allocator<type>(), 2, 1, 2, 3);
         BOOST_TEST(type::instances == 16);
         BOOST_TEST(a1[0][0][0][1].a == 1);
@@ -73,6 +100,15 @@
         BOOST_TEST(a1[0][1][0][0].f == 0);
         BOOST_TEST(a1[1][0][0][0].i == 0);
     }
+    BOOST_TEST(type::instances == 0);
+    {
+        boost::shared_ptr<type[2][2][2][2]> a1 = boost::allocate_shared<type[2][2][2][2]>(std::allocator<type>(), 1, 2, 3);
+        BOOST_TEST(type::instances == 16);
+        BOOST_TEST(a1[0][0][0][1].a == 1);
+        BOOST_TEST(a1[0][0][1][0].c == 3);
+        BOOST_TEST(a1[0][1][0][0].f == 0);
+        BOOST_TEST(a1[1][0][0][0].i == 0);
+    }
 #endif
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     {
Modified: trunk/libs/smart_ptr/test/make_shared_array_create_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/make_shared_array_create_test.cpp	(original)
+++ trunk/libs/smart_ptr/test/make_shared_array_create_test.cpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -48,6 +48,15 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2]> a1 = boost::make_shared<type[2]>(1, 2, 3, 4, 5, 6, 7, 8, 9);
+        BOOST_TEST(type::instances == 2);
+        BOOST_TEST(a1[0].a == 1);
+        BOOST_TEST(a1[0].d == 4);
+        BOOST_TEST(a1[1].f == 6);
+        BOOST_TEST(a1[1].i == 9);
+    }
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<type[][2]> a1 = boost::make_shared<type[][2]>(2, 1, 2, 3, 4, 5, 6, 7);
         BOOST_TEST(type::instances == 4);
         BOOST_TEST(a1[0][0].a == 1);
@@ -57,6 +66,15 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2][2]> a1 = boost::make_shared<type[2][2]>(1, 2, 3, 4, 5, 6, 7);
+        BOOST_TEST(type::instances == 4);
+        BOOST_TEST(a1[0][0].a == 1);
+        BOOST_TEST(a1[0][1].d == 4);
+        BOOST_TEST(a1[1][0].f == 6);
+        BOOST_TEST(a1[1][1].i == 0);
+    }    
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<type[][2][2]> a1 = boost::make_shared<type[][2][2]>(2, 1, 2, 3, 4, 5);
         BOOST_TEST(type::instances == 8);
         BOOST_TEST(a1[0][0][0].a == 1);
@@ -66,6 +84,15 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared<type[2][2][2]>(1, 2, 3, 4, 5);
+        BOOST_TEST(type::instances == 8);
+        BOOST_TEST(a1[0][0][0].a == 1);
+        BOOST_TEST(a1[0][1][0].c == 3);
+        BOOST_TEST(a1[1][0][1].e == 5);
+        BOOST_TEST(a1[1][1][1].i == 0);
+    }
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<type[][2][2][2]> a1 = boost::make_shared<type[][2][2][2]>(2, 1, 2, 3);
         BOOST_TEST(type::instances == 16);
         BOOST_TEST(a1[0][0][0][1].a == 1);
@@ -73,6 +100,15 @@
         BOOST_TEST(a1[0][1][0][0].f == 0);
         BOOST_TEST(a1[1][0][0][0].i == 0);
     }
+    BOOST_TEST(type::instances == 0);
+    {
+        boost::shared_ptr<type[2][2][2][2]> a1 = boost::make_shared<type[2][2][2][2]>(1, 2, 3);
+        BOOST_TEST(type::instances == 16);
+        BOOST_TEST(a1[0][0][0][1].a == 1);
+        BOOST_TEST(a1[0][0][1][0].c == 3);
+        BOOST_TEST(a1[0][1][0][0].f == 0);
+        BOOST_TEST(a1[1][0][0][0].i == 0);
+    }
 #endif
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     {
Modified: trunk/libs/smart_ptr/test/make_shared_arrays_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/make_shared_arrays_test.cpp	(original)
+++ trunk/libs/smart_ptr/test/make_shared_arrays_test.cpp	2012-11-09 12:12:56 EST (Fri, 09 Nov 2012)
@@ -75,11 +75,21 @@
         boost::shared_ptr<int[][2][2]> a1 = boost::make_shared_noinit<int[][2][2]>(2);
         BOOST_TEST(a1.get() != 0);
         BOOST_TEST(a1.use_count() == 1);
+    }
+    {
+        boost::shared_ptr<int[2][2][2]> a1 = boost::make_shared_noinit<int[2][2][2]>();
+        BOOST_TEST(a1.get() != 0);
+        BOOST_TEST(a1.use_count() == 1);
     }    
     {
         boost::shared_ptr<const int[][2][2]> a1 = boost::make_shared_noinit<const int[][2][2]>(2);
         BOOST_TEST(a1.get() != 0);
         BOOST_TEST(a1.use_count() == 1);
+    }
+    {
+        boost::shared_ptr<const int[2][2][2]> a1 = boost::make_shared_noinit<const int[2][2][2]>();
+        BOOST_TEST(a1.get() != 0);
+        BOOST_TEST(a1.use_count() == 1);
     }    
     BOOST_TEST(type::instances == 0);
     {
@@ -92,10 +102,26 @@
     }
     BOOST_TEST(type::instances == 0);
     {
+        boost::shared_ptr<type[2][2][2]> a1 = boost::make_shared_noinit<type[2][2][2]>();
+        BOOST_TEST(a1.get() != 0);
+        BOOST_TEST(a1.use_count() == 1);
+        BOOST_TEST(type::instances == 8);
+        a1.reset();
+        BOOST_TEST(type::instances == 0);
+    }
+    BOOST_TEST(type::instances == 0);
+    {
         boost::shared_ptr<const type[][2][2]> a1 = boost::make_shared_noinit<const type[][2][2]>(2);
         BOOST_TEST(a1.get() != 0);
         BOOST_TEST(a1.use_count() == 1);
         BOOST_TEST(type::instances == 8);
     }
+    BOOST_TEST(type::instances == 0);
+    {
+        boost::shared_ptr<const type[2][2][2]> a1 = boost::make_shared_noinit<const type[2][2][2]>();
+        BOOST_TEST(a1.get() != 0);
+        BOOST_TEST(a1.use_count() == 1);
+        BOOST_TEST(type::instances == 8);
+    }
     return boost::report_errors();
 }