Skip to content

Instantly share code, notes, and snippets.

@Robbepop
Created June 10, 2015 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Robbepop/5fada43b783c0907e821 to your computer and use it in GitHub Desktop.
Save Robbepop/5fada43b783c0907e821 to your computer and use it in GitHub Desktop.
Variadic Templates playground
#include <iostream>
template<typename T>
void print_counted_acc(size_t acc, T head) {
std::cout << acc << ' ' << head << '\n';
}
template<typename T, typename... Args>
void print_counted_acc(size_t acc, T head, Args... tail) {
std::cout << acc << ' ' << head << '\n';
print_counted_acc(acc + 1, tail...);
}
template<typename... Args>
void print_counted(Args... args) {
print_counted_acc(0, args...);
}
void test() {
print_counted(5, 4, -1, 0, 123);
print_counted(true, 4, -1, "Hello, World!");
}
auto main() -> int {
test();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment