With the following template and specialization:
template<typename T, typename = void>
struct A {
void operator()() {
std::cout << "primary" << std::endl;
}
};
template<typename T>
struct A<T, decltype(T().f())> {
void operator()() {
std::cout << "specialization" << std::endl;
}
};
used like this:
struct X {
bool f() { return false; }
};
int main()
{
A<X>()();
return 0;
}
the primary template is resolved, when one would expect partial specialisation to be selected. However, when changed to:
template<typename T>
struct A<T, typename std::enable_if<std::is_object<decltype(T().f())>::value>::type> {
void operator()() {
std::cout << "specialization" << std::endl;
}
};
the specialization is chosen. Why isn't specialization chosen in the original example?