Boost logo

Boost :

From: William Kempf (sirwillard_at_[hidden])
Date: 2001-01-03 10:14:50


--- In boost_at_[hidden], "David Abrahams" <abrahams_at_m...> wrote:
>
> ----- Original Message -----
> From: "Daryle Walker" <darylew_at_m...>
>
>
> > I haven't looked at the 'scoped_ptr' stuff, but aren't these
suggestions
> > overkill? No other object ('tcpipbuf' is noncopyable) or subclass
> > ('tcpip_data_' is private) is supposed to look at the
implementation. The
> > 'tcpipbuf' class could take care of the destruction itself.
>
> It depends what you mean by "overkill", I guess. The suggestions
eliminate
> casting, some exception-safety issues, and probably the need to
write a
> destructor in your class. Sounds like simplification to me. What's
the
> downside?

Increased compile time dependencies. You'll have yet another header
to include and another name brought into the namespace indirectly.

You also have problems with visibility of the destructor for the impl
class, as discussed in an early thread on this list.

For the "Pimpl Idiom" I prefer to use code like this:

class my_class
{
   ...
private:
   class impl; // scope it in the class to prevent name clashes
   impl* pimpl;
};

This requires code in my_class to manage the lifetime of the impl
instance, but this is trivial and impacts only the implementation of
my_class, while making visibility of the destructor a non-issue and
requires no further compile time dependencies. This just seems to be
the safest approach to this pattern.

Bill Kempf


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