views:

256

answers:

3

Using a trick (described by Olivier Langlois), I can determine whether a class has a type defined:

template<typename T> struct hasType
{
    template<typename C> static char test( typename C::Type );
    template<typename C> static char* test(...);
    enum{ Value= sizeof(test<T>(0))==1 };
};

I can also determine whether a class has a variable:

template<typename T> struct hasType
{
    template<typename C> static char test( decltype(C::var) );
    template<typename C> static char* test(...);
    enum{ Value= sizeof(test<T>(0))==1 };
};

However, neither decltype(c::func) nur decltype(c::func()) (which depends on the parameters) works for member functions. Is there a way to do this or will I have to create a functor in every class and detect it with typename C::functor?

Edit: You're both right, but since I'll also have to test for a type I'll use decltype(&C::func) (which should obviously be a pointer).

A: 

If this isn't what you need, I don't think you'll find it.

sbi
A: 

MS has a non-standard solution.

Ofek Shilon
Doesn't work for me, as I mostly use gcc/icc
tstenner