On 2008-07-22 08:57:16 -0400, puzzlecracker <ir*********@gmail.comsaid:
On Jul 22, 7:46Â*am, ManicQin <Manic...@gmail.comwrote:
>Hi all.
Is there a way to iterate through a pre-defined list in pre-compile
time?
(not with for)
something like:
#define LIST int,double,float,string......
#define MAX 10
#define functionPattern(type) \
void return##type() { \
cout << #type << endl; \
}
//Replacing the next macro
#define functionCreator Â*\
functionPattern(LIST[1]) \
functionPattern(LIST[2]) \
.
.
.
functionPattern(LIST[MAX])
Thanks
Please explain what this means:
void return##type() { \
cout << #type << endl; \
}
Is it even legal C++ code?
No, but that's not the full text of the macro. The full text is:
#define functionPattern(type) \
void return##type(){\
cout << #type << endl;\
}
and, yes, it's legal. return##type concatenates "return" and the
replacement text for "type" into a single token. And #type is simply
the replacement text for "type" surrounded by quotes. So, for example:
functionPattern(foo)
would expand to
void returnfoo(){
cout << "foo" << endl;
}
Try it.
--
Pete
Roundhouse Consulting, Ltd. (
www.versatilecoding.com) Author of "The
Standard C++ Library Extensions: a Tutorial and Reference
(
www.petebecker.com/tr1book)