Skip to content

Instantly share code, notes, and snippets.

@thekvs
Created January 16, 2013 19:05
Show Gist options
  • Save thekvs/4549812 to your computer and use it in GitHub Desktop.
Save thekvs/4549812 to your computer and use it in GitHub Desktop.
Variadic templates example. Compilation tested on GCC 4.7 with $ g++ -Wall -W -std=c++11 vtt.cpp -o vtt
#include <iostream>
// Base of a recursion
void
print()
{
std::cout << std::endl;
}
// Function to print any type without type specifiers
template <typename T, typename ...P>
void
print(T t, P ...p)
{
std::cout << t << ' ';
if (sizeof...(p)) {
print(p...);
} else {
std::cout << std::endl;
}
}
int
main()
{
print();
print("Hello!", 'a', 1, -1, 12.43);
print(2.32e+30, -324.32, 1.3242e-10, 123ULL);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment