I would like to know which of these (if any) options would be preferable.
For example, I implement the sum function, taking an arbitrary number of arguments. Main template then
template <typename T, typename... Ts>
auto sum(T t, Ts... ts)
{
return t + sum(ts...);
}
In the base case, I see at least two options:
Base Register - Amount ():
auto sum()
{
return 0;
}
The base case is equal to the sum (T):
template <typename T>
auto sum(T t)
{
return t;
}
Both of these seem to work the same way in this case, but which one is usually preferable?
source
share