This
template<> class Factorial<1>
{
public:
enum {fact = 1};
};
is actually a template full specialization or explicit specialization of class template Factorial. There is also something called template partial specialization. Both are forms of template specialization.
Template specializations are special cases wherein when you instantiate a template with the parameter indicated by the template specialization, that specific template specialization is used, instead of the original template.
In your code, the original Factorial template class
template <int N> class Factorial
{
public:
enum {fact = N * Factorial<N-1>::fact};
};
is used when you instantiate, for example, the following:
Factorial<3>
Factorial<5>
Factorial<42>
But when you instantiate/use
Factorial<1>
the template specialization Factorial<1> is used instead. In other words, it is a special case that is used whenever you supply 1 as the template parameter.
One notable example of a template specialization is std::vector<bool>, though you must be careful whether to use it or not.
Also an example. That show's some minimal usage of template specializations for both class templates and function templates.