Given the pattern
template <int n>
void f(){...};
I know that I can specialize it for certain values nby doing:
template <>
void f<2>(){...};
But is there a method that allows me to specialize it for all the positive n?
I thought of the following:
template <int n>
void f<n>(){
int dummy[n];
...
};
So, for n<0this code is not valid, and the compiler will apply the previous definition. Unfortunately, all I get is a mistake redefinition of 'void f<n>()'.
Note. I assume this is probably not supported by the standard. I ask if there is any method (possibly metaprogramming a template) to achieve this effect.
source
share