I am programmatically generating bunch of functors, in order to keep the generated code more readable I am trying to come up with a macro that will expand line the following,
SET_STATE(FunctorA,a,b);
ref a;
ref b;
FunctorA(ref a, ref b){
this->a = a;
this->b = b;
}
Basically it will expand to the first arguments constructor. Variadic part is the number of arguments to the constructor. is it possible to loop inside the macro and generate this code during preprocessing even though it does not make sense for this particular case but I have some functors that have 20 or so variables that they have access to it will cleanup my generated code a lot.
All arguments will be of the same type, only names will differ.
Using the tricked found in this link http://cplusplus.co.il/2010/07/17/variadic-macro-to-count-number-of-arguments/ to count the number of arguments and using some really ugly macro I can generate the output you wanted.
I tested it using gcc (gcc -E test.cpp) and it works, It's not portable.
Code:
So the following:
will produce:
Note: you can continue the number of arguments following the obvious pattern.
If
boost::preprocessor
andSEQ
representation((a)(b)...
) are allowed, probably the following code will meet the purpose:The above code is expanded to
in my environment.