Skip to content

Instantly share code, notes, and snippets.

@kantoniak
Last active February 27, 2017 16:08
Show Gist options
  • Save kantoniak/ba0ca485449551a3f5e3ca5b480b9383 to your computer and use it in GitHub Desktop.
Save kantoniak/ba0ca485449551a3f5e3ca5b480b9383 to your computer and use it in GitHub Desktop.
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