Облагороженный детектор методов с использование constexpr. Гонялось на gcc 4.6.1.
struct ProbeSet_method
{
template <class S,void (S::* M)()> struct Host;
template <class S>
static constexpr bool Probe(...) { return false; }
template <class S>
static constexpr bool Probe(Host<S,&S::method> *) { return true; }
};
template <class T,class ProbeSet>
struct Has
{
enum RetType { Ret = ProbeSet::template Probe<T>(0) };
};
template <class T>
struct Has_method : Has<T,ProbeSet_method> {};
struct Test1
{
void method();
};
struct Test2
{
void method(int);
};
#include <stdio.h>
int main()
{
printf("%d\n",Has_method<int>::Ret);
printf("%d\n",Has_method<Test1>::Ret);
printf("%d\n",Has_method<Test2>::Ret);
return 0;
}