Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81267 - in trunk/boost/smart_ptr: . detail
From: glenfe_at_[hidden]
Date: 2012-11-09 13:01:40


Author: glenfe
Date: 2012-11-09 13:01:39 EST (Fri, 09 Nov 2012)
New Revision: 81267
URL: http://svn.boost.org/trac/boost/changeset/81267

Log:
Add assertion to overload of make_shared and allocate_shared for T[N] with initializer lists. Rename detail type to be more intuitive.
Text files modified:
   trunk/boost/smart_ptr/allocate_shared_array.hpp | 11 ++++++-----
   trunk/boost/smart_ptr/detail/array_traits.hpp | 14 +++++++++++---
   trunk/boost/smart_ptr/detail/sp_if_array.hpp | 2 +-
   trunk/boost/smart_ptr/make_shared_array.hpp | 15 ++++++++-------
   4 files changed, 26 insertions(+), 16 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 13:01:39 EST (Fri, 09 Nov 2012)
@@ -23,7 +23,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = size * detail::array_size<T1>::size;
+ size_t n1 = size * detail::array_total<T1>::size;
         detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -41,7 +41,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = size * detail::array_size<T1>::size;
+ size_t n1 = size * detail::array_total<T1>::size;
         detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -58,7 +58,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = detail::array_size<T>::size;
+ size_t n1 = detail::array_total<T>::size;
         detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -79,7 +79,7 @@
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- size_t n1 = list.size() * detail::array_size<T1>::size;
+ size_t n1 = list.size() * detail::array_total<T1>::size;
         detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -93,13 +93,14 @@
     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) {
+ BOOST_ASSERT(list.size() == detail::array_size<T>::size);
         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;
+ size_t n1 = detail::array_total<T>::size;
         detail::allocate_array_helper<A, T2> a1(allocator, n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);

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 13:01:39 EST (Fri, 09 Nov 2012)
@@ -13,7 +13,6 @@
 #if !defined(BOOST_NO_CXX11_HDR_INITIALIZER_LIST)
 #include <initializer_list>
 #endif
-#include <cstddef>
 
 namespace boost {
     namespace detail {
@@ -27,14 +26,23 @@
         };
         template<typename T>
         struct array_size {
+ };
+ template<typename T, size_t N>
+ struct array_size<T[N]> {
+ enum {
+ size = N
+ };
+ };
+ template<typename T>
+ struct array_total {
             enum {
                 size = 1
             };
         };
         template<typename T, std::size_t N>
- struct array_size<T[N]> {
+ struct array_total<T[N]> {
             enum {
- size = N * array_size<T>::size
+ size = N * array_total<T>::size
             };
         };
         template<typename T>

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 13:01:39 EST (Fri, 09 Nov 2012)
@@ -23,7 +23,7 @@
         template<typename T>
         struct sp_if_size_array {
         };
- template<typename T, size_t N>
+ template<typename T, std::size_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 13:01:39 EST (Fri, 09 Nov 2012)
@@ -23,7 +23,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = size * detail::array_size<T1>::size;
+ size_t n1 = size * detail::array_total<T1>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -41,7 +41,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = size * detail::array_size<T1>::size;
+ size_t n1 = size * detail::array_total<T1>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -58,7 +58,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = detail::array_size<T>::size;
+ size_t n1 = detail::array_total<T>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -79,7 +79,7 @@
         T1* p1 = 0;
         T2* p2 = 0;
         T3* p3 = 0;
- size_t n1 = list.size() * detail::array_size<T1>::size;
+ size_t n1 = list.size() * detail::array_total<T1>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -93,13 +93,14 @@
     template<typename T>
     inline typename detail::sp_if_size_array<T>::type
     make_shared(typename detail::array_list<T>::type list) {
+ BOOST_ASSERT(list.size() == detail::array_size<T>::size);
         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;
+ size_t n1 = detail::array_total<T>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -118,7 +119,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = size * detail::array_size<T1>::size;
+ size_t n1 = size * detail::array_total<T1>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);
@@ -135,7 +136,7 @@
         typedef typename detail::array_base<T1>::type T2;
         T1* p1 = 0;
         T2* p2 = 0;
- size_t n1 = detail::array_size<T>::size;
+ size_t n1 = detail::array_total<T>::size;
         detail::make_array_helper<T2> a1(n1, &p2);
         detail::array_deleter<T2> d1;
         shared_ptr<T> s1(p1, d1, a1);


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