-
-
Notifications
You must be signed in to change notification settings - Fork 259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
debug print on some condition #115
Comments
Thank you for the feedback. This is not supported right now (and I'm not sure if I want to integrate it). But it might be possible to write a macro on your own, similar to: #define dbg_if(condition, arg) \
if (condition) { \
dbg(arg); \
} ... but with multiple args. |
That's simply and smart. It works for me. Let's just forget about multiple args for now. (That simple?... Never came to my mind...) |
Check this out: #define DBG_MACRO_NO_WARNING
#include "dbg.h"
#define dbg_if_2(condition, arg1) if (condition) { dbg(arg1); }
#define dbg_if_3(condition, arg1, arg2) if (condition) { dbg(arg1, arg2); }
#define dbg_if_4(condition, arg1, arg2, arg3) if (condition) { dbg(arg1, arg2, arg3); }
// https://stackoverflow.com/questions/11761703/overloading-macro-on-number-of-arguments
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define dbg_if(...) GET_MACRO(__VA_ARGS__, dbg_if_4, dbg_if_3, dbg_if_2, UNUSED)(__VA_ARGS__)
int main()
{
std::vector<double> vecs{1, 2, 3};
for (bool verbose: std::vector<bool>{true, false}) {
dbg("--------------");
dbg(verbose);
dbg_if(verbose, vecs);
dbg_if(verbose, vecs, vecs[0]);
dbg_if(verbose, vecs, vecs[0], verbose);
}
dbg("--------------");
} Output:
wanbox link: https://wandbox.org/permlink/PCPQ5xMfIFTPIRT9 |
I'd like to configure
dbg
to print on some condition.dbg
is a macro so these are not what I'm looking for:Related?: #109
Is it possible to expand the macro on some condition? So I can use it like:
Macros are not expanded at running time, so... Is there any other solutions?
Thank you guys.
The text was updated successfully, but these errors were encountered: