|
Boost Users : |
From: Howard Hinnant (hinnant_at_[hidden])
Date: 2006-11-29 12:11:25
On Nov 29, 2006, at 11:45 AM, Maitre Bart wrote:
> Still, the method used by shared_ptr<> is very useful: it hides the
> deleter in
> a template class the derives from a normal base class that is a
> member of the
> shared_ptr<>. So when you defines the smart pointer with a deleter,
> you avoid
> describing the full specialization.
>
> That is the reason why I suggested to reuse the shared_ptr<> astuce in
> scoped_ptr<>.
You might want to check out Jonathan Turkanis' dynamic_move_ptr:
http://home.comcast.net/~jturkanis/move_ptr/
which does this. It costs an associated size swelling, but can be
handy if you're willing to pay for it.
Fwiw, here's a poor man's version of that using unique_ptr (or
Jonathan's static_move_ptr):
typedef unique_ptr<A, void (*)(void*)> PtrType;
Now you can use PtrType with any function pointer. You just have to
supply the function pointer in the constructor. Template aliases
would make this a little nicer (or a templated wrapper class). It's
a compromise between a fully dynamic deleter (like shared_ptr) and a
fully static deleter (like unique_ptr). The cost is sizeof(PtrType)
is two words, but there's no extra internal allocation.
-Howard
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