Hi
Let's suppose we have some metaclass templates. We use object instances
of these as runtime representations of class types. They have some
functions that return informations about the represented classes.
struct Class_
{
virtual bool IsEmpty() const = 0;
};
template <class Cls>
struct Class:
public Class_
{
virtual bool IsEmpty() const { return boost::is_empty<Cls>(); }
};
Easy so far. The problems begin if I want to add a bool
IsBaseOf(Class_* derived) function. Boost has a nice
is_base_and_derived<B, D> template, but I don't know how to dispatch
the call, based on the dynamic types of this and derived, to the
appropriate instance of is_base_and_derived.
By overriding IsBaseOf(), as with IsEmpty(), I can get one of the
types. Now if I could write something like return
derived->IsDerivedFrom<Cls>();, that would be fine, as IsDerivedFrom
could now easily call is_base_and_derived. But of course, it doesn't
work; IsDerivedFrom should be a virtual (we only have a Class_*)
function template, and such thing doesn't exist in C++.
I guess I somehow have to build my own function pointer table, but I
don't really know how. So any help would be appreciated.
Thanks,
Imre