C++ use a number of arguments in variadic macro (implementing optional argument) -



C++ use a number of arguments in variadic macro (implementing optional argument) -

i writing macro (yes know it's evil, helps me create more optimized code) looks this:

#define huggle_debug(debug, verbosity) if (huggle::configuration::huggleconfiguration->verbosity >= verbosity) \ huggle::syslog::hugglelogs->debuglog(debug, verbosity)

function debuglog(qstring, unsigned int verbosity = 1) has optional parameter verbosity , create optional in macro well, can call

huggle_debug("some debug text");

as as:

huggle_debug("more verbose text", 10);

is somehow possible? note: using sec variable in macro, if didn't have it, substitute 1

my thought create variadic macro this, work this:

#define huggle_debug(debug, ...) syslog::hugglelogs->debuglog(debug, ##__va_args__)

which work kind of not utilize optimization did in first one

seeing you're using macro already, won't mind hacky solution:

#define huggle_debug(...) \ if (huggle::configuration::huggleconfiguration->verbosity >= ((int)(bool)__va_args__)) \ huggle::syslog::hugglelogs->debuglog(__va_args__)

when called 1 argument:

huggle_debug("abc") // expands if (huggle::configuration::huggleconfiguration->verbosity >= ((int)(bool)"abc")) huggle::syslog::hugglelogs->debuglog("abc")

(bool)"abc" true, (int)(bool)"abc" 1.

when called 2 arguments:

huggle_debug("abc", 10) // expands if (huggle::configuration::huggleconfiguration->verbosity >= ((int)(bool)"abc", 10)) huggle::syslog::hugglelogs->debuglog("abc", 10)

(int)(bool)"abc", 10 uses comma operator, evaluates 10.

but please please, consider using inline function instead. there's no need utilize macro this.

c++ macros

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -