(this question is not related to C ++ 11 / C ++ 14: examples compiled using C ++ 03)
enable_bool<T>has a member ::typeonly when Tthere isbool
template <class T>
struct enable_bool
{};
template <>
struct enable_bool< bool >
{ typedef bool type; };
In the following snippet, the partial specialization is correct (see gcc.godbolt.org )
template <class T, class U, class Enable = T>
struct Foo
{
static int bar() { return 0; }
};
template <class T, class U>
struct Foo< T, U, typename enable_bool<T>::type >
{
static int bar() { return 1; }
};
int main()
{
return Foo <int, bool>::bar();
}
Since it enable_bool<T>::typealready matches T(when Tthere is bool),
we tend to factor the parameters Tand Enable.
But the compiler complains (see gcc.godbolt.org )
template <class T, class U>
struct Foo
{
static int bar() { return 0; }
};
template <class T, class U> //ERROR non-deducible template parameter 'T'
struct Foo< typename enable_bool<T>::type, U >
{
static int bar() { return 1; }
};
Why can't the compiler output the template parameter Tin this partial specialization?