Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81641 - in trunk: boost/smart_ptr boost/smart_ptr/detail libs/smart_ptr libs/smart_ptr/test
From: glenfe_at_[hidden]
Date: 2012-11-30 23:36:42


Author: glenfe
Date: 2012-11-30 23:36:41 EST (Fri, 30 Nov 2012)
New Revision: 81641
URL: http://svn.boost.org/trac/boost/changeset/81641

Log:
Use const T (&)[N] for fixed size arrays instead of std::initializer<T> in overloads of make_shared and allocate_shared for arrays.
Text files modified:
   trunk/boost/smart_ptr/allocate_shared_array.hpp | 31 ++++++++++++++++++-------------
   trunk/boost/smart_ptr/detail/array_traits.hpp | 13 +++----------
   trunk/boost/smart_ptr/make_shared_array.hpp | 34 +++++++++++++++++++++-------------
   trunk/libs/smart_ptr/make_shared_array.html | 16 ++++++++--------
   trunk/libs/smart_ptr/test/allocate_shared_arrays_create_test.cpp | 14 ++++++++++++++
   trunk/libs/smart_ptr/test/make_shared_arrays_create_test.cpp | 14 ++++++++++++++
   6 files changed, 78 insertions(+), 44 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-30 23:36:41 EST (Fri, 30 Nov 2012)
@@ -60,9 +60,11 @@
     allocate_shared(const A& allocator, Args&&... args) {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
- enum { N = boost::detail::array_total<T>::size };
         boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);
@@ -97,21 +99,21 @@
     }
     template<typename T, typename A>
     inline typename boost::detail::sp_if_size_array<T>::type
- allocate_shared(const A& allocator,
- std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
+ allocate_shared(const A& allocator, const T& list) {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
         typedef const T2 T3;
- BOOST_ASSERT(list.size() == boost::detail::array_size<T>::size);
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- enum { N = boost::detail::array_total<T>::size };
         boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[N]>* d2;
- p3 = reinterpret_cast<T3*>(list.begin());
+ p3 = reinterpret_cast<T3*>(list);
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
         d2->construct_list(p2, p3);
@@ -124,10 +126,12 @@
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
         typedef const T2 T3;
+ enum {
+ M = boost::detail::array_total<T1>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- enum { M = boost::detail::array_total<T1>::size };
         std::size_t n1 = M * list.size();
         boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
         boost::detail::array_deleter<T2[]> d1;
@@ -142,21 +146,22 @@
     template<typename T, typename A>
     inline typename boost::detail::sp_if_size_array<T>::type
     allocate_shared(const A& allocator,
- std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
+ const typename boost::detail::array_inner<T>::type& list) {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
         typedef const T2 T3;
- BOOST_ASSERT(list.size() == boost::detail::array_size<T1>::size);
+ enum {
+ M = boost::detail::array_total<T1>::size,
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
- T3* p3 = 0;
- enum { M = boost::detail::array_total<T1>::size };
- enum { N = boost::detail::array_total<T>::size };
+ T3* p3 = 0;
         boost::detail::allocate_array_helper<A, T2[N]> a1(allocator, &p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[N]>* d2;
- p3 = reinterpret_cast<T3*>(list.begin());
+ p3 = reinterpret_cast<T3*>(list);
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
         d2->construct_list(p2, p3, M);

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-30 23:36:41 EST (Fri, 30 Nov 2012)
@@ -22,8 +22,7 @@
             typedef typename array_base<T>::type type;
         };
         template<typename T>
- struct array_size {
- };
+ struct array_size;
         template<typename T, std::size_t N>
         struct array_size<T[N]> {
             enum {
@@ -43,8 +42,7 @@
             };
         };
         template<typename T>
- struct array_inner {
- };
+ struct array_inner;
         template<typename T>
         struct array_inner<T[]> {
             typedef T type;
@@ -54,16 +52,11 @@
             typedef T type;
         };
         template<typename T>
- struct arrays_inner {
- };
+ struct arrays_inner;
         template<typename T, std::size_t N>
         struct arrays_inner<T[][N]> {
             typedef T type;
         };
- template<typename T, std::size_t M, std::size_t N>
- struct arrays_inner<T[M][N]> {
- typedef T 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-30 23:36:41 EST (Fri, 30 Nov 2012)
@@ -60,9 +60,11 @@
     make_shared(Args&&... args) {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
- enum { N = boost::detail::array_total<T>::size };
         boost::detail::make_array_helper<T2[N]> a1(&p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);
@@ -93,23 +95,24 @@
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
         d2->construct_list(p2, n1, p3);
         return boost::shared_ptr<T>(s1, p1);
- }
+ }
     template<typename T>
     inline typename boost::detail::sp_if_size_array<T>::type
- make_shared(std::initializer_list<typename boost::detail::array_inner<T>::type> list) {
+ make_shared(const T& list) {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
         typedef const T2 T3;
- BOOST_ASSERT(list.size() == boost::detail::array_size<T>::size);
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- enum { N = boost::detail::array_total<T>::size };
         boost::detail::make_array_helper<T2[N]> a1(&p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[N]>* d2;
- p3 = reinterpret_cast<T3*>(list.begin());
+ p3 = reinterpret_cast<T3*>(list);
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
         d2->construct_list(p2, p3);
@@ -122,10 +125,12 @@
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
         typedef const T2 T3;
+ enum {
+ M = boost::detail::array_total<T1>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- enum { M = boost::detail::array_total<T1>::size };
         std::size_t n1 = M * size;
         boost::detail::make_array_helper<T2[]> a1(n1, &p2);
         boost::detail::array_deleter<T2[]> d1;
@@ -139,21 +144,22 @@
     }
     template<typename T>
     inline typename boost::detail::sp_if_size_array<T>::type
- make_shared(std::initializer_list<typename boost::detail::arrays_inner<T>::type> list) {
+ make_shared(const typename boost::detail::array_inner<T>::type& list) {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
         typedef const T2 T3;
- BOOST_ASSERT(list.size() == boost::detail::array_size<T1>::size);
+ enum {
+ M = boost::detail::array_total<T1>::size,
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- enum { M = boost::detail::array_total<T1>::size };
- enum { N = boost::detail::array_total<T>::size };
         boost::detail::make_array_helper<T2[N]> a1(&p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[N]>* d2;
- p3 = reinterpret_cast<T3*>(list.begin());
+ p3 = reinterpret_cast<T3*>(list);
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[N]> >(s1);
         d2->construct_list(p2, p3, M);
@@ -182,9 +188,11 @@
     make_shared_noinit() {
         typedef typename boost::detail::array_inner<T>::type T1;
         typedef typename boost::detail::array_base<T1>::type T2;
+ enum {
+ N = boost::detail::array_total<T>::size
+ };
         T1* p1 = 0;
         T2* p2 = 0;
- enum { N = boost::detail::array_total<T>::size };
         boost::detail::make_array_helper<T2[N]> a1(&p2);
         boost::detail::array_deleter<T2[N]> d1;
         boost::shared_ptr<T> s1(p1, d1, a1);

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-30 23:36:41 EST (Fri, 30 Nov 2012)
@@ -54,25 +54,25 @@
     shared_ptr&lt;T[]&gt; make_shared(initializer_list&lt;T&gt; list);
 
     template&lt;typename T, typename... Args&gt;
- shared_ptr&lt;T[N]&gt; make_shared(initializer_list&lt;T&gt; list);
+ shared_ptr&lt;T[N]&gt; make_shared(const T (&amp;list)[N]);
 
     template&lt;typename T, typename... Args&gt;
     shared_ptr&lt;T[][N]&gt; make_shared(size_t size, initializer_list&lt;T&gt; list);
 
     template&lt;typename T, typename... Args&gt;
- shared_ptr&lt;T[M][N]&gt; make_shared(initializer_list&lt;T&gt; list);
+ shared_ptr&lt;T[M][N]&gt; make_shared(const T (&amp;list)[N]);
 
     template&lt;typename T, typename A, typename... Args&gt;
     shared_ptr&lt;T[]&gt; allocate_shared(const A&amp; allocator, 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, initializer_list&lt;T&gt; list);
+ shared_ptr&lt;T[N]&gt; allocate_shared(const A&amp; allocator, const T (&amp;list)[N]);
 
     template&lt;typename T, typename A, typename... Args&gt;
     shared_ptr&lt;T[][N]&gt; allocate_shared(const A&amp; allocator, size_t size, initializer_list&lt;T&gt; list);
 
     template&lt;typename T, typename A, typename... Args&gt;
- shared_ptr&lt;T[M][N]&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);
+ shared_ptr&lt;T[M][N]&gt; allocate_shared(const A&amp; allocator, const T (&amp;list)[N]);
 #endif
 
     template&lt;typename T&gt;
@@ -141,9 +141,9 @@
         from the initializer list.</p>
     </blockquote>
     <pre>template&lt;typename T, typename... Args&gt;
- shared_ptr&lt;T[N]&gt; make_shared(initializer_list&lt;T&gt; list);
+ shared_ptr&lt;T[N]&gt; make_shared(const T (&amp;list)[N]);
 template&lt;typename T, typename A, typename... Args&gt;
- shared_ptr&lt;T[N]&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);</pre>
+ shared_ptr&lt;T[N]&gt; allocate_shared(const A&amp; allocator, const T (&amp;list)[N]);</pre>
     <blockquote>
       <p><b>Description:</b> These overloads of the utilities above are for a
         fixed size array.</p>
@@ -157,9 +157,9 @@
         from the initializer list.</p>
     </blockquote>
     <pre>template&lt;typename T, typename... Args&gt;
- shared_ptr&lt;T[M][N]&gt; make_shared(initializer_list&lt;T&gt; list);
+ shared_ptr&lt;T[M][N]&gt; make_shared(const T (&amp;list)[N]);
 template&lt;typename T, typename A, typename... Args&gt;
- shared_ptr&lt;T[M][N]&gt; allocate_shared(const A&amp; allocator, initializer_list&lt;T&gt; list);</pre>
+ shared_ptr&lt;T[M][N]&gt; allocate_shared(const A&amp; allocator, const T (&amp;list)[N]);</pre>
     <blockquote>
       <p><b>Description:</b> These overloads of the utilities above are for a
         fixed size array.</p>

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-30 23:36:41 EST (Fri, 30 Nov 2012)
@@ -12,6 +12,20 @@
 int main() {
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     {
+ boost::shared_ptr<int[]> a1 = boost::allocate_shared<int[]>(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);
+ }
+ {
+ 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);
+ }
+ {
         boost::shared_ptr<int[][2]> a1 = boost::allocate_shared<int[][2]>(std::allocator<int>(), { {0, 1}, {2, 3} });
         BOOST_TEST(a1[0][0] == 0);
         BOOST_TEST(a1[0][1] == 1);

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-30 23:36:41 EST (Fri, 30 Nov 2012)
@@ -13,6 +13,20 @@
 int main() {
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
     {
+ boost::shared_ptr<int[]> a1 = boost::make_shared<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);
+ }
+ {
+ 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);
+ }
+ {
         boost::shared_ptr<int[][2]> a1 = boost::make_shared<int[][2]>({ {0, 1}, {2, 3} });
         BOOST_TEST(a1[0][0] == 0);
         BOOST_TEST(a1[0][1] == 1);


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