Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Simple variadic template example
#include <iostream>
using namespace std;
// Support single argument
auto sumElements() {
return 0;
template <typename T, typename... Ts>
T sumElements(T t, Ts... ts) {
return t + sumElements(ts...);
int main() {
cout << "Example 1: sum elements" << endl;
cout << "Sum: " << sumElements(4, 5.f, 6L) << endl;
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment