Getting ready

The examples in this recipe are based on the variadic function template add() that we wrote in the previous recipe, Writing a function template with a variable number of arguments. That implementation is a left-folding operation. For simplicity, we present the function again:

    template <typename T> 
T add(T value)
{
return value;
}

template <typename T, typename... Ts>
T add(T head, Ts... rest)
{
return head + add(rest...);
}