Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2000-09-03 14:00:53


> They are fine the current way around and the behaviour is perfectly well
> defined: You are not modifying a const object.

OK
 
> It already works for this case. The type check is performed using the
> result of typeid rather than dynamic_cast: dynamic_cast<holder<const
> int> *> would fail but typeid(int) == typeid(const int) is true, so it
> works as it stands -- no deconsting through traits is required.

Not OK. The way typeid strips off cv-qualifiers is the problem. Yes,
this does compile, and works in probably 99% of cases, but the result
is still undefined. As you note, the dynamic_cast would fail, which
indicates that the static_cast is invalid. The remove_const is needed
in the target type of the static_cast (in which case you could dispense
with the typeid check and just use dynamic_cast).

Mark


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