C++11 initializer lists can be used to initialize vectors and arrays with argument passing to constructors.
I have a piece of code below
The MACRO solution.
#include
#include
#define COLORS(V,E) \
V(RED) \
V(GREEN) \
E(BLUE)
#define COMMA(V) \
V,
#define NCOMMA(V) \
V
#define SCOMMA(V) \
#V,
#define SNCOMMA(E) \
#E
enum Colors {
COLORS(COMMA,NCOMMA)
};
const char * colors[] = {
COLORS(SCOMMA,SNCOMMA)
};
#define INIT_LIST(V) \
{ V(COMMA,NCOMMA) }
int main(int argc, char **argv) {
for ( auto i : INIT_LIST(COLORS) ) {
printf("%s\n", colors[i]);
}
}