views:

78

answers:

0

Possible Duplicate:
Possible for C++ template to check for a function's existence?

Do you know of any metaprogramming tricks in C++ that allow me to check whether a class has a specific method. I has been thinking about something like this:

template <class T, class Enable = void> 
class A { ... };

// This version of the class will be compiled if T doesn't have my_method
template <class T>
class A<T, typename enable_if<has_method<T, T::my_method> >::type> { ... };

// This version of the class will be compiled if T has my_method
template <class T>
class A<T, typename disable_if<has_method<T, T::my_method> >::type> { ... };

One of the options is to define my_method in a class that others may inherit and then use is_base_of, but is there nother options that don't require inheritance?