Created
January 16, 2013 19:05
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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