I would like to run macros on a list of class names to avoid copy/pasting errors and hassle.
Imagine, as a simple example, that every class in my SDK needs to call a static allocation method before it is used. So, every time I add a new class, I have to manually add the following line at initialization:
MyNewClass::allocate();
And I also need to do the same for initialization and destruction.
So, instead of doing this manually every time, I was wondering if there was a way to write a list of all my class names somewhere, then define a macro to call the corresponding methods for each class in the list. Something in the lines of:
#define ALLOCATE( TheClass ) TheClass ## ::allocate();
But instead of just passing TheClass
as an argument, I'd like to pass a list of my classes. So by calling:
ALLOCATE_ALL( ClassA, ClassB, ClassC )
it would expand to:
ClassA::allocate();
ClassB::allocate();
ClassC::allocate();
Ultimately, I would like to be able to define a class list and have multiple macros iterate over it. Something in the lines of:
ALLOCATE_ALL( MyClassList )
INIT_ALL( MyClassList )
DESTROY_ALL( MyClassList )
I've already taken a look at variadic macros but, if I understand the concept correctly, you have to define as many macros as the final number of arguments; and that is simply not viable in my case.
Is this possible at all?
Thanks for any help and/or feedback.