How can I achieve the opposite effect of VA_OPT(), expanding only, if there are no variadic arguments in VA_ARGS. Something like VA_NOT_OPT().
Example:
#define MY_MACRO(...) __VA_NOT_OPT__(default) __VA_ARGS__
MY_MACRO() expands to default
MY_MACRO(arg) expands to arg
What I really want is a single optional parameter with a default value. But I think the C-Preprocessor doesn't support this. But maybe someone knows better than me.
You can build a little conditional expansion macro pretty easily, so that
VALUE_IFNOT(1, args)expands to nothing andVALUE_IF(0, args)(or in this caseVALUE_IF(, args)too) expands toargs:Then your "opposite of
__VA_OPT__" macro looks likeVALUE_IF(__VA_OPT__(1), value). This will expand toVALUE_IF(1, value)and nothing if there were variadic arguments andVALUE_IF(, value)andvalueif there weren't.For example https://godbolt.org/z/Kbc5jxEKf