From: Beman Dawes (beman_at_[hidden])
Date: 1999-09-02 10:27:38
Kevlin Henney wrote:
> However, as it probably now stands (I'm looking at code from
> polymorphic_cast as was), it is not actually particularly safe.
Yes, and we should change the name to down_cast, or whatever, unless
there is some magic way to make it totally safe.
> NDEBUG is set, I lose all of the compile time checking as well
> runtime checking -- baby has been thrown out w/ the bath water!
> can be fixed, and at no extra execution cost, by adding a dummy
> dynamic_cast that is parsed and checked, but is not executed
and -- on
> a good compiler -- will not have code gen'd for it either:
> template<class Derived, class Base>
> inline Derived safe_downcast(Base* x)
> assert(dynamic_cast<Derived>(x) != 0);
> return static_cast<Derived>(x);
Kevlin, after wading throught the standard's description of
dynamic_cast twice, I am still having trouble knowing which errors
your added code will detect, and which will still get through. Could
you enlighten me?
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk