Created
January 18, 2023 14:53
-
-
Save qwertyowmx/47f183ab4133c48f564eb4a7e9403830 to your computer and use it in GitHub Desktop.
C++ fold println
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> | |
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