Monday, 15 July 2013

c++ - Dropping the last comma in a macro -



c++ - Dropping the last comma in a macro -

i using x macro pattern maintain bunch of arrays/items in sync, , want create argument list it, can't work out way formed list. here's mean:

#define my_data \ x(var_one, e_one, 1) \ x(var_two, e_two, 2) \ x(var_three, e_three, 3) \ #define x(a,b,c) b, enum mynumbers { my_data }; #undef x #define x(a,b,c) c, int myvalues[] = { my_data }; #undef x void my_func(int a, int b, int c) {} // illustration do-nothing proc void main(void) { int var_one = myvalues[e_one]; int var_two = myvalues[e_two]; int var_three = myvalues[e_three]; #define x(a,b,c) a, my_func(my_data); // fails because of trailing comma #undef x }

macros not forte, can't think of way of getting rid of final comma in function call. can think of way stop it?

look @ boost preprocessor library “preprocessor metaprogramming tools including repetition , recursion.”

even if don't utilize finish package, chapter linked explains techniques, including iteration build info structures , statements.

here's idea: write

my_func(my_data 0);

and declare my_func take (ignored) argument.

void my_func(int a, int b, int c, int)

c++ templates

No comments:

Post a Comment