- Solution

Let's have a look at the solution review for the last exercise.

We'll cover the following...

Solution Review

Press + to interact
// sum.cpp
#include <iostream>
template<typename ...Args> // Without an initial value
auto sum(Args&& ... args){
return ( ... + args);
}
template<typename T, typename ...Args> // with an initial value
auto sumWithStart(T&& t, Args&& ... args){
return ( t + ... + args);
}
int main(){
std::cout << sum(1, 2, 3) << std::endl;
std::cout << sumWithStart(20, 1, 2, 3) << std::endl;
}

Explanation

In the above code, we have ...