Hi
I'd like to create a special cast template function that can be used to
cast a base pointer to a derived one, and uses dynamic_cast if virtual
inheritance is involved, and static_cast otherwise. Unfortunately I
don't know how to properly detect VI.
I've seen a trick for detecting VI, that goes something like:
template <class B, class D>
struct IsVirtualBaseAndDerived
{
class Helper1: public D, public virtual B {};
class Helper2: public D {};
public:
enum { value = (sizeof(Helper1) == sizeof(Helper2)) };
};
This works well, but can't be used to detect if there are additional
inheritance levels between B and D, and VI is used somewhere in the
middle. For example:
class A {};
class B: public A {}; // not virtual
class C: public virtual B {}; // virtual
A is not really a VB of C here, but still, if we are to do an A* -> C*
cast, we should use dynamic_cast due to the VI between B and C.
So, my question is: how could I create some
IsVirtualInheritanceInvolved<B, D> template metafunction?
Thanks,
Imre