Check at compile time whether one template parameter is derived from another
I have some templates of the form:
Code:
template < typename Base, typename Derived >
void Foo(...)
Where it should only be instantiated if Derived derives from Base. Currently, I'm using a helper template:
Code:
template < typename Base, typename Derived >
class Inherits
{
public:
Inherits() { Base *b = (Derived *)NULL; }
};
Then I instantiate a temporary Inherits< Base, Derived >() when I want to check the constraint.
Is there a cleverer method?