Boost logo

Boost :

From: Larry Evans (cppljevans_at_[hidden])
Date: 2006-03-31 05:05:37


On 03/30/2006 11:46 PM, Vaclav Vesely wrote:
> Larry Evans wrote:
>
>>It's the class template version of your function template, new_.
>>IOW, it's something like:
>
[snip]
> I'm afraid I still don't grasp.
>
> In paticular I'm missing an motivating example (use case) of what can be
> done with auto_overhead but not with new_.

Thanks Vaclev for replying. Obviously I'm having a problem explaining.
I'm wondering if it's because my auto_overhead's purpose is different
than new_'s. IOW new_'s purpose if for exception safety (AFAICT), but
auto_overhead's purpose is:

   1) Allow allocation of overhead (e.g. refcount ) at the same time
      as the T.
   2) Never allow exposure of the raw T* to code outside of either
      auto_overhead or the receiving smart_ptr, whatever that may
      be.

IOW, the smart_ptr, say sp<T,O>, where T is the referent type
and O is the overhead type, would have, *intead* of a CTOR taking
a raw T*:

    sp<T,O>::sp(T* a_T)
      : my_ovhd(new O)
      , my_ref(a_T)
    {...}

or an auto_ptr:

    sp<T,O>::sp(std::auto_ptr<T> a_T)
      : my_ovhd(new O)
      , my_ref(a_T.release())
    {...}

a CTOR taking a auto_overhead:

    sp<T,O>::sp(auto_overhead<T,0>& a_ovhd)
      : my_ovhd(a_ovhd.overhead())
      , my_ref(a_ovhd.release())
    {...}

<USE_CASE>

Although new_ does satisfy purpose 2 above, it doesn't
allow sp to satisfy purpose 2 above also because it would allow:

   T* a_Tptr=new T; //exposes raw pointer
   std::auto_ptr<T> a_Taptr(a_Tptr);
   sp<T,O> a_spT(a_Taptr);

</USE_CASE>

I'm not familiar enough with the exception safety issue to know
whether auto_overhead could avoid that problem also, but I'm
guessing it could.

Is that any clearer? Please let me know because I obviously
need to work on my communication skills :(


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk