Created
August 8, 2014 10:34
-
-
Save bananu7/8403762ea711db84cdf4 to your computer and use it in GitHub Desktop.
Variadic print
This file contains hidden or 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> | |
#include <string> | |
#include <vector> | |
template<typename T> | |
void print(T const& t) { | |
std::cout << t << " "; | |
} | |
void print(std::string const& s) { | |
std::cout << s; | |
} | |
void print(const char* s) { | |
std::cout << s; | |
} | |
template<typename T, typename... Args> | |
void print(T const& t, Args const&... args) { | |
print(t); | |
print(args...); | |
} | |
int main() | |
{ | |
int a = 5; | |
int& b = a; | |
int& c = b; | |
print(a, b, c, "\n"); | |
print("test\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment