Boost logo

Boost :

From: Dave Abrahams (abrahams_at_[hidden])
Date: 1999-09-02 21:26:41


> postmast.root.admi.gov_at_[hidden] wrote:
>
>>... Seems about as
>>safe as static_cast, only it happens to be checked during debugging
>>(only). Safe to me implies what dynamic_cast provides, and nothing
>>less. Perhaps debug_static_cast (or something along those lines)
> would
>>be clearer?
>
> After I sent the message using the "safe_downcast" name, I remembered
> Dave Abrahams had already pointed out it wasn't really "safe" as
> written.

Ugh. The last name Beman and I settled on, with my full agreement, was
"polymorphic_downcast".

> 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.

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.

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

-Dave

P.S. I am concerned that this list, and the boost libraries, are now
suffering from "design-by-committee" syndrome, where nothing appears to be
acceptable unless everyone's pet issue is addressed. That is the dynamic
which produces bloated software, poorly integrated APIs, and cluttered
user-interfaces. I prefer instead "design-by-collaboration", where a few
people can get together and produce a product, which either thrives (and
evolves) or dies on the strength of its usability.


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