C++ gurus,
I have a template metaprogramming question. Consider the following function declaration.
int foo(const int x[], char *y, size_t size);
I would like to be able to generate the function body as follows:
int foo(const int x[], char *y, size_t size)
{
return myfnc(x, y, size);
}
Is there a way to do this with C++ template metaprogramming? I can "wrap" the declaration in some macro, but I'd like to avoid the use of macros to do the full expansion. For example, I'd be happy if I can write something along the lines of:
DEFINE_FNC(foo, const int x[], char *y, size_t size)
where DEFINE_FNC
is defined as
#define DEFINE_FNC(fnc, ...) \
int fnc(__VA_ARGS__) { \
return myfnc(__VA_ARGS__); \ // This doesn't work; is there something else that can be done here?
} \
I'm aware of the solution mentioned here, but that requires me to add parenthesis around the parameter types, and I'd like to avoid that, if possible.
I tried to use variadic templates, but it doesn't do the exact thing I want.