Boost logo

Boost :

From: Peter Dimov (pdimov_at_[hidden])
Date: 2000-07-31 12:54:41

> Unfortunately, we don't get a compile time constant out of this technique.
> To be honest though, I never found a use for it... is there one?

There are two scenarios where is_polymorphic is useful:

* You have a Base*, but you know that it really points to a Derived. You
can't static_cast, because this doesn't work with some contrived multiple
inheritance situations; and you can't dynamic_cast because you don't know
whether Base is polymorphic or not.

* You have a pointer to an object and you need to find the beginning of the
object (the original pointer may point inside the object when multiple
inheritance is involved.) dynamic_cast<void*> will do this for polymorphic
types, for the others you assume that the pointer you have is the beginning.

I think that both problems can't be solved in the general case, even with an
is_polymorphic predicate, but the cases where the solutions don't work can
be considered 'rare.'

The real solution to this is to modify dynamic_cast to work on
non-polymorphic types as well (when inside a template.)

Peter Dimov
Multi Media Ltd.

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