If you can use C++11, this is completely trivial:
template
struct has_nested_option{
typedef char yes;
typedef yes (&no)[2];
template
static yes test(decltype(U::option)*);
template
static no test(...);
static bool const value = sizeof(test(0)) == sizeof(yes);
};
The C++03 version is (surprisingly) similar:
template
struct has_nested_option{
typedef char yes;
typedef yes (&no)[2];
template
struct test2;
template
static yes test(test2*);
template
static no test(...);
static bool const value = sizeof(test(0)) == sizeof(yes);
};
Usage:
struct foo{
enum { option = 1 };
};
struct bar{};
#include
template
typename std::enable_if<
has_nested_option::value
>::type Do(){
}
int main(){
Do();
Do(); // error here, since you provided no other viable overload
}