How can I write a macro (for gcc) that would be used like this:
CREATE_STRUCT(my_struct1,foo);
CREATE_STRUCT(my_struct2,foo,bar);
and expands to
struct my_struct1 {
std::string foo;
};
struct my_struct2 {
std::string foo;
std::string bar;
};
?
I certainly do need the flexibility of different number of members, but already a small number would be fine for me (something like 4 or 5).
I found a couple of related questions, eg this and this, but I am completely lost when trying to apply such arcane macro magic to this problem.
PS: I know how I could write 5 macros (one for each number of params) that would do the job, so actually the question is: Is there an "easy" way to write a variadic macro that does the job? On the other hand, I will add more stuff to the structs, so having it all in one place would save lots of boilerplate.