Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81681 - in trunk/boost/smart_ptr: . detail
From: glenfe_at_[hidden]
Date: 2012-12-02 17:05:32


Author: glenfe
Date: 2012-12-02 17:05:31 EST (Sun, 02 Dec 2012)
New Revision: 81681
URL: http://svn.boost.org/trac/boost/changeset/81681

Log:
Make specializations of detail array_deleter consistent.
Text files modified:
   trunk/boost/smart_ptr/allocate_shared_array.hpp | 16 ++++++------
   trunk/boost/smart_ptr/detail/array_deleter.hpp | 51 +++++++++++++++++++++++----------------
   trunk/boost/smart_ptr/make_shared_array.hpp | 20 +++++++-------
   3 files changed, 48 insertions(+), 39 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-12-02 17:05:31 EST (Sun, 02 Dec 2012)
@@ -29,12 +29,12 @@
         T2* p2 = 0;
         std::size_t n1 = size * boost::detail::array_total<T1>::size;
         boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct(p2, n1);
+ d2->construct(p2);
         return boost::shared_ptr<T>(s1, p1);
     }
 #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
@@ -47,12 +47,12 @@
         T2* p2 = 0;
         std::size_t n1 = size * boost::detail::array_total<T1>::size;
         boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct(p2, n1, boost::detail::sp_forward<Args>(args)...);
+ d2->construct(p2, boost::detail::sp_forward<Args>(args)...);
         return boost::shared_ptr<T>(s1, p1);
     }
     template<typename T, typename A, typename... Args>
@@ -88,13 +88,13 @@
         T3* p3 = 0;
         std::size_t n1 = list.size() * boost::detail::array_total<T1>::size;
         boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p3 = reinterpret_cast<T3*>(list.begin());
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct_list(p2, n1, p3);
+ d2->construct_list(p2, p3);
         return boost::shared_ptr<T>(s1, p1);
     }
 #endif
@@ -136,13 +136,13 @@
         T3* p3 = 0;
         std::size_t n1 = M * size;
         boost::detail::allocate_array_helper<A, T2[]> a1(allocator, n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p3 = reinterpret_cast<T3*>(list);
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct_list(p2, n1, p3, M);
+ d2->construct_list(p2, p3, M);
         return boost::shared_ptr<T>(s1, p1);
     }
     template<typename T, typename A>

Modified: trunk/boost/smart_ptr/detail/array_deleter.hpp
==============================================================================
--- trunk/boost/smart_ptr/detail/array_deleter.hpp (original)
+++ trunk/boost/smart_ptr/detail/array_deleter.hpp 2012-12-02 17:05:31 EST (Sun, 02 Dec 2012)
@@ -19,42 +19,48 @@
         template<typename T>
         class array_deleter<T[]> {
         public:
- array_deleter()
- : size(0) {
+ array_deleter(std::size_t size)
+ : size(size),
+ object(0) {
             }
             ~array_deleter() {
                 destroy();
             }
- void construct(T* memory, std::size_t count) {
- for (object = memory; size < count; size++) {
- void* p1 = object + size;
+ void construct(T* memory) {
+ object = memory;
+ for (std::size_t i = 0; i < size; i++) {
+ void* p1 = object + i;
                     ::new(p1) T();
                 }
             }
 #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
             template<typename... Args>
- void construct(T* memory, std::size_t count, Args&&... args) {
- for (object = memory; size < count; size++) {
- void* p1 = object + size;
+ void construct(T* memory, Args&&... args) {
+ object = memory;
+ for (std::size_t i = 0; i < size; i++) {
+ void* p1 = object + i;
                     ::new(p1) T(args...);
                 }
             }
 #endif
- void construct_list(T* memory, std::size_t count, const T* list) {
- for (object = memory; size < count; size++) {
- void* p1 = object + size;
- ::new(p1) T(list[size]);
+ void construct_list(T* memory, const T* list) {
+ object = memory;
+ for (std::size_t i = 0; i < size; i++) {
+ void* p1 = object + i;
+ ::new(p1) T(list[i]);
                 }
             }
- void construct_list(T* memory, std::size_t count, const T* list, std::size_t n) {
- for (object = memory; size < count; size++) {
- void* p1 = object + size;
- ::new(p1) T(list[size % n]);
+ void construct_list(T* memory, const T* list, std::size_t n) {
+ object = memory;
+ for (std::size_t i = 0; i < size; i++) {
+ void* p1 = object + i;
+ ::new(p1) T(list[i % n]);
                 }
             }
- void construct_noinit(T* memory, std::size_t count) {
- for (object = memory; size < count; size++) {
- void* p1 = object + size;
+ void construct_noinit(T* memory) {
+ object = memory;
+ for (std::size_t i = 0; i < size; i++) {
+ void* p1 = object + i;
                     ::new(p1) T;
                 }
             }
@@ -63,8 +69,11 @@
             }
         private:
             void destroy() {
- while (size > 0) {
- object[--size].~T();
+ if (object) {
+ for (std::size_t i = size; i > 0; ) {
+ object[--i].~T();
+ }
+ object = 0;
                 }
             }
             std::size_t size;

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-12-02 17:05:31 EST (Sun, 02 Dec 2012)
@@ -29,12 +29,12 @@
         T2* p2 = 0;
         std::size_t n1 = size * boost::detail::array_total<T1>::size;
         boost::detail::make_array_helper<T2[]> a1(n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct(p2, n1);
+ d2->construct(p2);
         return boost::shared_ptr<T>(s1, p1);
     }
 #if defined(BOOST_HAS_VARIADIC_TMPL) && defined(BOOST_HAS_RVALUE_REFS)
@@ -47,12 +47,12 @@
         T2* p2 = 0;
         std::size_t n1 = size * boost::detail::array_total<T1>::size;
         boost::detail::make_array_helper<T2[]> a1(n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct(p2, n1, boost::detail::sp_forward<Args>(args)...);
+ d2->construct(p2, boost::detail::sp_forward<Args>(args)...);
         return boost::shared_ptr<T>(s1, p1);
     }
     template<typename T, typename... Args>
@@ -87,13 +87,13 @@
         T3* p3 = 0;
         std::size_t n1 = list.size() * boost::detail::array_total<T1>::size;
         boost::detail::make_array_helper<T2[]> a1(n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p3 = reinterpret_cast<T3*>(list.begin());
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct_list(p2, n1, p3);
+ d2->construct_list(p2, p3);
         return boost::shared_ptr<T>(s1, p1);
     }
 #endif
@@ -135,13 +135,13 @@
         T3* p3 = 0;
         std::size_t n1 = M * size;
         boost::detail::make_array_helper<T2[]> a1(n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p3 = reinterpret_cast<T3*>(list);
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct_list(p2, n1, p3, M);
+ d2->construct_list(p2, p3, M);
         return boost::shared_ptr<T>(s1, p1);
     }
     template<typename T>
@@ -177,12 +177,12 @@
         T2* p2 = 0;
         std::size_t n1 = size * boost::detail::array_total<T1>::size;
         boost::detail::make_array_helper<T2[]> a1(n1, &p2);
- boost::detail::array_deleter<T2[]> d1;
+ boost::detail::array_deleter<T2[]> d1(n1);
         boost::shared_ptr<T> s1(p1, d1, a1);
         boost::detail::array_deleter<T2[]>* d2;
         p1 = reinterpret_cast<T1*>(p2);
         d2 = get_deleter<boost::detail::array_deleter<T2[]> >(s1);
- d2->construct_noinit(p2, n1);
+ d2->construct_noinit(p2);
         return boost::shared_ptr<T>(s1, p1);
     }
     template<typename T>


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