Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81266 - 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:30:08


Author: glenfe
Date: 2012-11-09 12:30:07 EST (Fri, 09 Nov 2012)
New Revision: 81266
URL: http://svn.boost.org/trac/boost/changeset/81266

Log:
Add additional overload for make_shared and allocate_shared for arrays for fixed size arrays and initializer lists.
Text files modified:
   trunk/boost/smart_ptr/allocate_shared_array.hpp | 20 ++++++++++++++++++++
   trunk/boost/smart_ptr/detail/array_traits.hpp | 4 ++++
   trunk/boost/smart_ptr/make_shared_array.hpp | 20 ++++++++++++++++++++
   trunk/libs/smart_ptr/make_shared_array.html | 6 ++++++
   trunk/libs/smart_ptr/test/allocate_shared_array_create_test.cpp | 7 +++++++
   trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp | 7 +++++++
   trunk/libs/smart_ptr/test/make_shared_array_create_test.cpp | 7 +++++++
   trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp | 7 +++++++
   8 files changed, 78 insertions(+), 0 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:30:07 EST (Fri, 09 Nov 2012)
@@ -90,6 +90,26 @@
         d2->construct(p2, n1, p3);
         return shared_ptr<T>(s1, p1);
     }
+ template<typename T, typename A>
+ inline typename detail::sp_if_size_array<T>::type
+ allocate_shared(const A& allocator, typename detail::array_list<T>::type list) {
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
+ typedef const T2 T3;
+ T1* p1 = 0;
+ T2* p2 = 0;
+ T3* p3 = 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;
+ p3 = reinterpret_cast<T3*>(list.begin());
+ p1 = reinterpret_cast<T1*>(p2);
+ d2 = get_deleter<detail::array_deleter<T2> >(s1);
+ d2->construct(p2, n1, p3);
+ return shared_ptr<T>(s1, p1);
+ }
 #endif
 }
 

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:30:07 EST (Fri, 09 Nov 2012)
@@ -56,6 +56,10 @@
         struct array_list<T[]> {
             typedef std::initializer_list<T> type;
         };
+ template<typename T, size_t N>
+ struct array_list<T[N]> {
+ typedef std::initializer_list<T> type;
+ };
 #endif
     }
 }

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:30:07 EST (Fri, 09 Nov 2012)
@@ -90,6 +90,26 @@
         d2->construct(p2, n1, p3);
         return shared_ptr<T>(s1, p1);
     }
+ template<typename T>
+ inline typename detail::sp_if_size_array<T>::type
+ make_shared(typename detail::array_list<T>::type list) {
+ typedef typename detail::array_inner<T>::type T1;
+ typedef typename detail::array_base<T1>::type T2;
+ typedef const T2 T3;
+ T1* p1 = 0;
+ T2* p2 = 0;
+ T3* p3 = 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;
+ p3 = reinterpret_cast<T3*>(list.begin());
+ p1 = reinterpret_cast<T1*>(p2);
+ d2 = get_deleter<detail::array_deleter<T2> >(s1);
+ d2->construct(p2, n1, p3);
+ return shared_ptr<T>(s1, p1);
+ }
 #endif
     template<typename T>
     inline typename detail::sp_if_array<T>::type

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:30:07 EST (Fri, 09 Nov 2012)
@@ -50,9 +50,15 @@
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     template&lt;typename T, typename... Args&gt;
     shared_ptr&lt;T[]&gt; make_shared(std::initializer_list&lt;T&gt; list);
+
+ template&lt;typename T, typename... Args&gt;
+ shared_ptr&lt;T[N]&gt; make_shared(std::initializer_list&lt;T&gt; list);
         
     template&lt;typename T, typename A, typename... Args&gt;
     shared_ptr&lt;T[]&gt; allocate_shared(const A&amp; allocator, std::initializer_list&lt;T&gt; list);
+
+ template&lt;typename T, typename A, typename... Args&gt;
+ shared_ptr&lt;T[N]&gt; allocate_shared(const A&amp; allocator, std::initializer_list&lt;T&gt; list);
 #endif
 
     template&lt;typename T&gt;

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:30:07 EST (Fri, 09 Nov 2012)
@@ -118,6 +118,13 @@
         BOOST_TEST(a1[2] == 2);
         BOOST_TEST(a1[3] == 3);
     }
+ {
+ boost::shared_ptr<int[4]> a1 = boost::allocate_shared<int[4]>(std::allocator<int>(), { 0, 1, 2, 3 });
+ BOOST_TEST(a1[0] == 0);
+ BOOST_TEST(a1[1] == 1);
+ BOOST_TEST(a1[2] == 2);
+ BOOST_TEST(a1[3] == 3);
+ }
 #endif
     return boost::report_errors();
 }

Modified: trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp (original)
+++ trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp 2012-11-09 12:30:07 EST (Fri, 09 Nov 2012)
@@ -18,6 +18,13 @@
         BOOST_TEST(a1[1][0] == 2);
         BOOST_TEST(a1[1][1] == 3);
     }
+ {
+ boost::shared_ptr<int[2][2]> a1 = boost::allocate_shared<int[2][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
+ BOOST_TEST(a1[0][0] == 0);
+ BOOST_TEST(a1[0][1] == 1);
+ BOOST_TEST(a1[1][0] == 2);
+ BOOST_TEST(a1[1][1] == 3);
+ }
 #endif
     return boost::report_errors();
 }

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:30:07 EST (Fri, 09 Nov 2012)
@@ -118,6 +118,13 @@
         BOOST_TEST(a1[2] == 2);
         BOOST_TEST(a1[3] == 3);
     }
+ {
+ boost::shared_ptr<int[4]> a1 = boost::make_shared<int[4]>({ 0, 1, 2, 3 });
+ BOOST_TEST(a1[0] == 0);
+ BOOST_TEST(a1[1] == 1);
+ BOOST_TEST(a1[2] == 2);
+ BOOST_TEST(a1[3] == 3);
+ }
 #endif
     return boost::report_errors();
 }

Modified: trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp
==============================================================================
--- trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp (original)
+++ trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp 2012-11-09 12:30:07 EST (Fri, 09 Nov 2012)
@@ -18,6 +18,13 @@
         BOOST_TEST(a1[1][0] == 2);
         BOOST_TEST(a1[1][1] == 3);
     }
+ {
+ boost::shared_ptr<int[2][2]> a1 = boost::make_shared<int[2][2]>({ {0, 1}, {2, 3} });
+ BOOST_TEST(a1[0][0] == 0);
+ BOOST_TEST(a1[0][1] == 1);
+ BOOST_TEST(a1[1][0] == 2);
+ BOOST_TEST(a1[1][1] == 3);
+ }
 #endif
     return boost::report_errors();
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk