I would like to write a macro in C++ that, based on a comparison, returns either comma and a value, or nothing at all.
#define TEST1(x) \
x == 1 ? COMMA 2 : NADA
#define COMMA ,
#define NADA
The idea is that when the argument is 1 the macro will return , 2
and otherwise will return nothing, so that
int foo[5] = { 0 TEST1(1) TEST1(2) };
would compile as:
int foo[5] = { 0 , 1 };
The first error is: missing '}' before constant
.