I have a function build with function pointers. I think it might be faster to try to exchange this function with pre processor macro. At least, I would like to try out the macro so I can measure if it generates faster code.
It's more or less like this:
typedef int (Item::*GetterPtr)(void)const;
typedef void (Item::*SetterPtr)(int);
void doStuff(Item* item, GetterPtr getter, SetterPtr setter, int k)
{
int value = (item->*getter)();
// .. Do some stuff
(item->*setter)(newValue);
}
And it's called like
// ...
doStuff(&item, &Item::a, &Item::setA, _a);
doStuff(&item, &Item::b, &Item::setB, _b);
doStuff(&item, &Item::c, &Item::setC, _c);
// ...
I think it might be possible to swap this with something like:
#define DO_STUFF(item, getter, setter, k) do { \
int value = item ## -> ## getter ## (); \
//... \
item ## -> ## setter ## (newValue); \
} while(0);
but it gives me errors like:
error: pasting ")" and "setA" does not give a valid preprocessing token
There's a way to concatenate the function names and it's object?