Created
August 13, 2017 07:53
-
-
Save saginadir/8feb740041a16fc3afe79473e336f2d8 to your computer and use it in GitHub Desktop.
Always wanted the JavaScript console.log function in cpp? well now you have it:
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
void consoleLogHelper() {}; | |
template <typename T> | |
void print(T t) { | |
std::cout << t << " "; | |
} | |
template <typename T, typename...Ts> | |
void consoleLogHelper(T &&first, Ts&&... rest) { | |
// print it | |
print(std::forward<T>(first)); | |
// Forward the rest. | |
consoleLogHelper(std::forward<Ts>(rest)...); | |
} | |
template <typename...Ts> | |
void consoleLog(Ts&&... rest) { | |
consoleLogHelper((rest)...); | |
std::cout << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Use case: