The following code compiles. Anyone can explain why? I've been digging the standard to figure out why it's legal.
template <bool B, typename T = void> struct enable_if { }; template <typename T> struct enable_if<true, T> { typedef T type; }; template <typename T, typename Enable = void> struct A; template <typename T> struct A<T, typename enable_if<(sizeof(T) <= ~0ULL)>::type> { void f() { } }; int main() { A<int> a; a.f(); } At the statement:
A<int> a; As there's only one template paramerter "int", the compiler should go to use the primary template, which is:
template <typename T, typename Enable = void> struct A; which is undefined, thus causing an error.
std::enable_if?