Re: [Boost-bugs] [Boost C++ Libraries] #5381: get_deleter<D>(ptr) needs D to be exactly known

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #5381: get_deleter<D>(ptr) needs D to be exactly known
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2011-04-07 18:25:42

#5381: get_deleter<D>(ptr) needs D to be exactly known
  Reporter: christian.kotz@… | Owner: pdimov
      Type: Feature Requests | Status: new
 Milestone: To Be Determined | Component: smart_ptr
   Version: Boost 1.45.0 | Severity: Problem
Resolution: | Keywords:

Comment (by christian.kotz@…):

 For a copy on write pointer it is not sufficient to use the actual type in
 the constructor only, where it is known, a la make_shared. On dereference
 (not construction time) it may be necessary to lazily clone (create a
 copy) of the pointee. In this case splicing must be avoided, so even if we
 have a shared_ptr<Base> which has been constructed from a
 make_shared<Derived> invokation the actual pointee carrier must be cloned
 (Derived not Base!).

 here some code fragments, which sketch the "deleter"

 class Carrier_base

 ... most omitted

   virtual Carrier_base *clone() = 0;

 template <typename T, typename A = ::std::allocator<T> >
 class Carrier :
   private A::template rebind<T>::other
 ... most ommitted
   typedef typename A::template rebind<T>::other allocator_type;

   template <typename Other_A, typename... Args>
   static Carrier<T,A> * create(Other_A allocator, Args... args);

   T * address() const;

   template <typename Other_A, typename... Args>
   explicit Carrier(Other_A allocator, Args... args);

   Carrier<T,A> * clone() const{ // override
      Carrier<T,A> * result = allocate(1,0);
         new (allocator_type(*this)) Carrier<T,A>(*this);
      } catch(...)
      return result;

 If I only allow construction in a make_shared like fashion, I know on
 clone time that only a class derived from Carrier_base can be the deleter.
 This is sufficient to invoke cloning. The actual Carrier<X> need not and
 cannot be in general be known.
 Note COW pointer is not a ::boost::shared_ptr but privatrely inherits from
 one or has a private member.

Ticket URL: <>
Boost C++ Libraries <>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:06 UTC