Boost logo

Boost Users :

From: Bruno Martínez (br1_at_[hidden])
Date: 2005-11-12 16:15:08


Hi.

intrusive_ptr's constructor takes an bool to signal whether the refcount
should be initially incremented or not. The default is true.

I find that the default is different for different types, so I propose to
add a hook to specify the policy for each type. At first I thought to do
this with traits, but now I think a function is better because this
doesn't need to be compile-time and a function overload works fine with
ADL. I'm no expert in this, so maybe I'm mistaken somewhere.

What I propose is to add:

namespace boost {
     template <class T>
     bool intrusive_ptr_add_ref_at_construction(T*)
     {
         return true;
     }

     template<class T> class intrusive_ptr
     {
         intrusive_ptr(T * p, bool add_ref =
intrusive_ptr_add_ref_at_construction((T*)0)): p_(p)
         {
             if(p_ != 0 && add_ref) intrusive_ptr_add_ref(p_);
         }
         ...
     }
}

then I can do

bool intrusive_ptr_add_ref_at_construction(MyType*)
{
     return false;
}

What do you think of this feature?

Regards,
Bruno


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net