Last active
November 10, 2019 09:53
-
-
Save byBretema/9511c5ded05f8ce49599c46d75420d9d to your computer and use it in GitHub Desktop.
A quick print function that wraps std::cout and allow pass elems of any type to be printed in a function-like way.
This file contains hidden or 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> | |
// ------------------------------------------ | |
// Quick print | |
// ------------------------------------------ | |
void _printRest(void){} | |
template <typename H, typename ...T> | |
void _printRest(const H& head, T&&... tail){ std::cout << " " << head; _printRest(tail...); } | |
void _printFirst(void){} | |
template <typename H, typename ...T> | |
void _printFirst(const H& head, T&&... tail){ std::cout << head; _printRest(tail...); } | |
auto qprint = [] (auto... param){ _printFirst(param...); }; | |
auto qprintln = [] (auto... param){ _printFirst(param...); std::cout << "\n"; }; | |
// ------------------------------------------ | |
/* | |
USAGE EXAMPLE: | |
qprint("My favourite number is:", 42, "\nWhich is yours?"); | |
int n; | |
std::cin >> n; | |
qprint("My favourite is:", n); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment