Boost logo

Boost :

From: Mathias Gaunard (mathias.gaunard_at_[hidden])
Date: 2008-07-22 11:52:40

Scott McMurray wrote:

> I'm not convinced that this is useful. It doesn't protect against
> real nulls of pointer type

Yes, you would have to assume that whenever you're initializing from a
pointer, that pointer points to a valid object.

A possible alternative way to solve that problem would be to make the
constructor private, only accessible by boost::addressof which would be
used instead of &. Since you would apply adressof on an object (and thus
moving the requirement that the object is valid to the user), you cannot
end up with a null pointer.

boost::ref is actually quite similar to that.

> and if I see a failure talking about int
> when I want a null pointer, my first instinct would be to assume it's
> an overload or deduction error, and just cast it, at which point it
> will compile.

If you cast, you're dropping type safety, so you're on your own.
A code that performs casting, outside of low-level coding or a few
idioms like CRTCP, is a bad thing.

Boost list run by bdawes at, gregod at, cpdaniel at, john at