From: John Maddock (John_Maddock_at_[hidden])
Date: 2002-01-11 07:15:48
>One thing I want which I don't think is in the proposal is the ability to
determine at compile-time whether or not a type is polymorphic.
I am building a runtime representation of the inheritance hierarchy for
conversion in Boost.Python. For polymorphic types, I need to generate
downcasts. As it stands, the interface is clumsy because the user has to
tell the library whether a given base class is polymorphic.
If a type X is not polymorphic, it is illegal to even write
where typeid(a)==typeid(X), unless Y is a base class of X.
Since it seems highly unlikely that we'll get the compile-time "tell me
whether this expression would be an error" operator, we ought to be
aggressive about pursuing things that help us avoid making errors in the
first place ;-)
Funny you should mention that, I came up with a reasonably protable
implementation for that the other day - I just haven't had a chance to try
it out. Heres my rather quickly knocked up code:
template <class T>
struct d1 : public T
struct d2 : public T
virtual void foo();
BOOST_STATIC_CONSTANT(bool, value = (sizeof(d2) == sizeof(d1)));
int main(int argc, char* argv)
unsigned int expected_failures = 0;
Works for Borland/gcc/VC6 and VC7.
- John Maddock
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk