I'm working on generating some large static meta data structures right now, and would like to optimize the size of some the generated c++ files.
static constexpr MetaData* metaDataArray[] = {
&MetaDataObject0,
&MetaDataObject1,
&MetaDataObject2,
&MetaDataObject3,
&MetaDataObject4,
&MetaDataObject5,
&MetaDataObject6,
&MetaDataObject7,
&MetaDataObject8,
&MetaDataObject9,
&MetaDataObject10,
&MetaDataObject11,
&MetaDataObject12,
&MetaDataObject13,
&MetaDataObject14,
&MetaDataObject15,
&MetaDataObject16,
&MetaDataObject17,
&MetaDataObject18,
&MetaDataObject19,
&MetaDataObject20
}
This is an example of an array that I would like to wrap into a macro. Preferrably something like this:
METADATA_ARRAY(MetaDataObject,20);
I realize this is probably quite tricky. I haven't really found a solution this problem yet, maybe it's not even possible to create a recursive macro that expands while keeping an index counter variable?
Maybe it's more feasible to aim for a macro more along these lines:
METADATA_ARRAY(MetaDataObject,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
I have found some references to variadic macros like this (along these lines: https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s).
This approach seems to be limited to 64 arguments though. Some of the arrays in our generated code have 3000+ elements. Is this possible to work around with some creative preprocessor black magic?