The preprocessor cannot split tokens. This means it is impossible to produce foo
from m_foo
or (as has recently been asked) foo
from "foo"
.
If you can use variadic macros (as Matthieu M. points out, this means C99 or C++0x) Jens Gustedt’s P99 library would be helpful here. There are macros to make this even easier, but let’s make this readable to people who aren’t familiar with the library, OK?
Simplified case: there are either two or three arguments passed.
#define MANIP2(a, b) \
f(a, b) \
g(#a, #b)
#define MANIP3(a, b, c) \
f(a, b, c) \
g(#a, #b, #c)
#define MANIP(...) \
MANIP_( \
P99_PASTE2(MANIP, P99_NARG(__VA_ARGS__)), \
__VA_ARGS__) \
#define MANIP_(MANIPMAC, ...) MANIPMAC(__VA_ARGS__)
This illustrates the basic principle. In practice, there are foreach-style macros (analogous to Boost’s) to make this easier to code (though, as I mentioned, harder to read for the uninitiated). See the P99 library documentation for details.