With curiosity, I tried an alternative implementation of is_class using the sizeof() trick. Below is the code:
template<typename T> struct is_class { typedef char (&yes)[7]; typedef char (&no)[3]; static yes check (int T::*); static no check (...); enum { value = (sizeof(check(0)) == sizeof(yes)) }; };
The problem is that when I instantiate is_class<int> , it gives a compilation error:
error: creating pointer to member of non-class type 'int'
Now, my question is: if int T::* not applicable for int (or void* , etc.), then why does not perform a replacement for yes check . Should the compiler choose no check ?
source share