On the book C++ templates - The Complete Guide, Vandevoorde & Josuttis, it was suggested the following snippet to determine whether a type is a class or not. The argument was: "For class types we can rely on the observation that the pointer to member type construct int C::* is valid only if C is a class type" as a strategy to decide whether a type is a "class" type or not.
I have two questions:
1) Do you think the argument is valid? 2) How would you modify (preserving the strategy) the snippet below to make it work, since it doesn't compile on MSVC2013?
using namespace std;
template<typename T>
class IsClass
{
typedef char One;
typedef struct
{
char a[2];
} Two;
template<typename C> static One test(int C::*);
template<typename C> static Two test(...);
public:
enum { YES = (sizeof(IsClass<T>::test<T>(0) == 1)) };
};
class C{};
void main()
{
if (IsClass<C>::YES)
std::cout << "C Is a Class" << endl;
}