Skip to content

Instantly share code, notes, and snippets.

@thejohnfreeman
Last active December 10, 2015 08:29
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 thejohnfreeman/4408325 to your computer and use it in GitHub Desktop.
Save thejohnfreeman/4408325 to your computer and use it in GitHub Desktop.
Generic concatenation
#include <iostream>
#include <sstream>
struct Tester {
static void print(std::ostream& out) {}
template <typename Head, typename... Tail>
static void print(std::ostream& out, const Head& head, const Tail&... tail) {
out << head;
print(out, tail...);
}
};
int main() {
std::ostringstream ss;
Tester::print(ss, "abc", 1, 2, 3);
ss << std::endl;
Tester::print(ss, "xyz");
ss << std::endl;
Tester::print(ss, 4);
ss << std::endl;
std::cout << ss.str();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment