Skip to content

Instantly share code, notes, and snippets.

@qwertyowmx
Created January 18, 2023 14:53
Show Gist options
  • Save qwertyowmx/47f183ab4133c48f564eb4a7e9403830 to your computer and use it in GitHub Desktop.
Save qwertyowmx/47f183ab4133c48f564eb4a7e9403830 to your computer and use it in GitHub Desktop.
C++ fold println
#include <iostream>
template <const char sep = ' ', typename ... Args>
void print(Args ... args) {
((std::cout << args << sep), ...);
}
template <const char sep = ' ', typename ... Args>
void println(Args ... args) {
print<sep>(args...);
std::cout << std::endl;
}
int main()
{
println<'_'>(1, 2, 3, 4, 5);
println();
println("abc", "cde", 2, 3, 1, 5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment