Boost logo

Boost :

From: John Torjo (john.groups_at_[hidden])
Date: 2007-11-06 22:00:03


We should be able to solve this ;)

We have:

template<class Y, class D> shared_ptr <http://www.boost.org/libs/smart_ptr/shared_ptr.htm#constructors>(Y * p, D d);

So, for type 'Y', we can have the default deleter
default_delete<Y*>();

template<class Y> struct default_delete { void do_delete(Y p) { delete p; } };

template<> struct default_delete<FILE*> { void do_delete(FILE* p) { if (p) fclose(p); } };
...etc

Users can even specialize default_delete for their custom classes if they wish.

Best,
John

> I agree but it quickly becomes a pain because you end up writing a
> wrapper for every thing of this type to satisfy this 'wart' with
> shared_ptr:
>
> pthread_create ...
> opendir
> fopen
> open
> free
> COM objects
>
> the list goes on.
>
>

-- 
http://John.Torjo.com -- C++ expert
... call me only if you want things done right

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