I have written a variadic template function with recursive evaluation. For the final parameter I implemented a specialization without the variadic pack and everything worked fine.
Now I want to convert the variadic function parameters into template parameters.
This is my try:
template<typename N, int p> // specialization
N constexpr myadd(const N &n)
{
return n + p;
}
template<typename N, int p, int ... v> // variadic
N constexpr myadd(const N &n)
{
return myadd<N, v...>(n) + p;
}
int testfun()
{
return myadd<int, 2>(7);
}
gcc and clang are reporting an ambiguous overload and can not decide between 'specialization' and 'variadic' with an empty parameter pack.
I tried removing the specialization and check for the pack size in the variadic template, but without the specialization the compilers are failing to deduce parameter 'p'.