A MACRO question

M

ManicQin

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
 
P

puzzlecracker

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?
 
M

ManicQin

Yes, the Boost library provides some sophisticated (really unbelievable) macro
magic.

Thanks I looked at how Boost do it and because I cant use Boost
I could only steal their code... but it's too much work more work
than I can afford to spent on just saving few lines...


Thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,171
Messages
2,570,936
Members
47,472
Latest member
KarissaBor

Latest Threads

Top