(this question is not related to C ++ 11 / C ++ 14: examples compiled using C ++ 03)
enable_bool<T>
has a member ::type
only when T
there 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>::type
already matches T
(when T
there is bool
),
we tend to factor the parameters T
and 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 T
in this partial specialization?