This is very useful, but as you say, C ++ does not allow you to do this directly. However, you can do almost the same with partial specialization.
This is especially convenient if you use variable templates in C ++ 11, since you can do the following:
template <typename... T> struct A;
Effectively this allows you to have A<T, U> and A<T> as completely separate types. Attempting to create an instance of A with a large number of template parameters will result in a compilation error, since the general case is undefined (you could use static_assert to give a good error message if you want).
Something similar can be achieved in C ++ 03 using the default template options (set to an empty dummy structure or void ), but C ++ 11 is much better than IMO.
source share