I would like to write a templated function with varidiac tempate parameters. (I do not want a variable number of function parameters). When I try to do it, I get this ambiguity:
#include <iostream>
template<int arg>
int sum()
{
return arg;
}
template <int d, int... arguments>
int sum()
{
return d + sum<arguments...>();
}
int main()
{
std::cout << sum<2, 5, 7>() << std::endl;
return 0;
}
main.cpp:12:16: error: call to ‘sum’ is ambiguous return d + sum<arguments…>();
main.cpp:12:16: note: in instantiation of function template specialization ‘sum<5, 7>’ > requested here
main.cpp:17:18: note: in instantiation of function template specialization ‘sum<2, 5, 7>’ requested here
How do I make this non-ambiguous?