Let's say I have a function sum
that takes a variadic parameter pack.
This function needs to ADD UP all of the parameters of the parameter pack using the operator +
.
NOTE: It CANNOT use the operator +=
in any way and can use only operator +
(as the program CANNOT assume that all parameters have operator+=
overloaded).
Then, function sum
needs to return the whole "sum" or accumulative add-up.
Here is the basic structure of what it would look like:
template <class... Args>
auto sum(Args... args)
{
// ... The code
}
NOTE: All arguments may not be of the same type AND you can assume that a corresponding overload of the operator+
exists for all types of the parameter pack.
It may be helpful to know that I am using C++ 20.