Last active
December 10, 2015 08:29
-
-
Save thejohnfreeman/4408325 to your computer and use it in GitHub Desktop.
Generic concatenation
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> | |
#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