Boost logo

Boost :

From: Fernando Cacciola (fernando_cacciola_at_[hidden])
Date: 2003-02-21 13:50:32


"Peter Dimov" <pdimov_at_[hidden]> wrote in message
news:006901c2d9c2$1db8fa60$1d00a8c0_at_pdimov2...
> Fernando Cacciola (Home) wrote:
> [...]
> > One is initialization from a null pointer value, as in:
> >
> > struct C
> > {
> > C() : ptr(0) {}
> >
> > shared_ptr<X> ptr ;
> > } ;
> >
> > this one is very useful because its very idiomatic.
>
> Use
>
> C() : ptr() {}
>
> instead; it is supposed to work for any pointer.
>
I know I can do this instead.
But my point is that we rarely do it :-)
Value-initialization is not as idiomatic as it should, specially if you
consider the highly generic case of a 'general' pointer (either built-in or
smart).
Neither is (!p) and (!!p) or (p) instead of (p==0) and (p!=0),
unfortunately.

Just take a look at almost any boost code (shared_ptr.hpp, for example); the
null pointer value is used a lot (not only in initialization but in testing
too)

So, having support for null-pointer-value in a smart ptr makes it more
'pointer-like' in light on the de-facto idioms still in broad usage today.

Anyway, I agree with Daniel Frey in that putting this into shared_ptr will
disallow stricter guidelines.

--
Fernando Cacciola

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