Boost logo

Boost :

From: Kevlin Henney (Kevlin.Henney_at_[hidden])
Date: 1999-09-03 02:55:23


> If the safety improvement Kevlin Henney suggested holds up, we can
> stick with the "safe_downcast" name if we want. But otherwise a
> change is in order.

This is overkill. The point of this cast is simple:
1. you have a pointer to an instance of a class B with a virtual function.
2. You know the object being pointed to is in fact of some class D derived
from B
3. You need to get at the D instance
4. You want an assertion to fire (in debug mode of course) if you made an
error in reasoning such that you don't in fact have a D instance.

     5. The same compilation constraints exist regardless of NDEBUG.

The function was written with the assumption that the code using it would
be
compiled (and tested) in debug mode, and shipped with NDEBUG defined. If we
assume that people compile once without NDEBUG defined, Kevlin's suggestion
does nothing to improve safety. Even if we don't make that assumption, the
only thing Kevlin's suggestion accomplishes is a compile-time check that B
is in fact polymorphic when compiled with NDEBUG defined.

     It is a strange point of view that sees type safety as overkill -- the
     "only thing" indeed! I would suggest that we keep type safety until
     someone can prove it is irrelevant -- and I mean prove, not these
     unenforceable conventions of "people should compile like so".

Usually a simple component is better than one that tries to "do everything"

     Indeed, and we should also avoid "do nothing" or "do not quite the
     right thing" components.

     Kevlin


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