Boost logo

Boost :

From: Andrei Alexandrescu (andrewalex_at_[hidden])
Date: 2002-05-01 23:23:27


"David B. Held" <dheld_at_[hidden]> wrote in message
news:aaqcf7$8dn$1_at_main.gmane.org...
> The subject says it all.

Way cool, David!

> The only thing missing is support for custom deleters. The
> only reason I didn't add that was because I didn't get to it, and
> because it would change smart_ptr's public interface. It seems
> reasonable to add, but I'd like Andrei to comment on it, since
> it's his baby.

I'd like smart_ptr to not be seen that way. It's becoming your and
Gennadiy and others' baby as we all contribute to it.

In what way would the interface change?

If I guess right, it's about the two-argument constructor that takes a
deleter. I think that could be added, given that if it's not used it's
not compiled.

This being said, my opinion on the deleter not being part of the type
is often more dangerous than useful.

Consider this:

shared_ptr<HANDLE> sp1(someGdiHandle, ::GdiReleaseObject);
shared_ptr<HANDLE> sp2(someKernelHandle, ::KernelReleaseObject);

Now note that the two pointers have the same type, but belong to very
different worlds. Given that, what is the semantics of the following
code?

if (sp1 == sp2)
{
    ...
}

That would not be a compile-time error, but more than sure it's a bug.
And it's better to detect bugs at compile time. I could come with many
examples when you don't really enjoy that pointers with different
deleters have the same types. Then, I think there are also examples
when you do want to bind deleters at runtime, though my personal
impression is that they are not so numerous. But that impression might
be wrong.

> I did two other things: ported it to VC6, and added array support
> (taking a hint from Beman's reference implementation).

You said what? Yay!!!

If you also add the EBO optimization that I mentioned in my other
post, I will believe I died and I'm in Heaven :o).

Andrei


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