Maybe something like:
Code:
typedef struct {
char c[2];
} tester_t;
template<class T>
struct inherits_checker {
static tester_t f(...);
static char f(T*);
};
template<class T1, class T2>
struct is_same {
enum {
value = 0
};
};
template<class T>
struct is_same<T, T> {
enum {
value = 1
};
};
template<class T1, class T2>
struct inherits {
enum {
value = sizeof(char) == sizeof(inherits_checker<T1>::f((T2*)0)) &&
!is_same<T1, T2>::value
};
};
struct foo {};
struct bar : foo {};
int main()
{
std::cout << inherits<foo, bar>::value << '\n';
}
I followed phantomotap's advice but it looks like my template looks different than what he was thinking. It's possible that I'm missing something since I only did that test.