Boost logo

Boost :

From: Daniel James (daniel_at_[hidden])
Date: 2004-07-08 05:54:50


Max Khesin wrote:
> As of version 3.1 boost shared_ptr has a constructor that takes a
> user-defined deleter:
> template<class Y, class D> shared_ptr(Y * p, D d): px(p), pn(p, d)
> {
> detail::sp_enable_shared_from_this(p, p, pn);
> }
> Maybe I missed something, but what is your library adding to this?

His library can handle non-pointers that can't be stored directly in a
shared pointer. Another possible example it to store sockets:

scoped_handle<int> sock(::socket(AF_INET, SOCK_STREAM, 0), ::close);

Something similar has been mentioned before, for example see:

http://lists.boost.org/MailArchives/boost/msg49290.php

I think there might have been talk of getting a policy base smart
pointer to do this kind of thing as well.

I guess that nothing much has happened yet because the need isn't that
great. On the rare occasions that you need something like this,
emulating it with smart pointers is usually good enough. And if it
isn't, then it's not that hard to write it in a non-generic way. There
aren't as many problems as writing a smart pointer. For example, you
don't need to deal with the different operator overloads.

Daniel


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