Given many inline functions with identical signatures. All functions are small and performance critical.
int inline f1(int);
int inline f2(int);
...
int inline f5(int);
I need to write high level functions to automate certain tasks – one high level function per each inline function. n-th high level function uses only n-th low level function, otherwise all high level functions are identical.
int F_n(int x) {
int y;
// use n-th low level function to compute y from x
// for example
y = x*f_n(x);
return y;
}
I could use function pointers for call back, but I think it will prevent inclining and the performance will suffer. Or I could just copy&paster and manually fix function names.
Is there a way to do it with macros? A macro that can generates high level functions automatically?
#define GEN_FUNC( HIGH_LEVEL_FUNC, LOW_LEVEL_FUNC ) \
??????? \
??????? \
GEN_FUNC(F1, f1); // generate F1
GEN_FUNC(F2, f2); // generate F2
.........
GEN_FUNC(F_N, f_N); // generate F_N
Is it possible?
Thanks.
P.S. I could use function objects, but it should work in C too.
Why not use templates?
Edit: If it should work in C, use a macro like this:
And using BOOST_PP_REPEAT: