Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created August 8, 2014 10:34
Show Gist options
  • Save bananu7/8403762ea711db84cdf4 to your computer and use it in GitHub Desktop.
Save bananu7/8403762ea711db84cdf4 to your computer and use it in GitHub Desktop.
Variadic print
#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