473,385 Members | 1,402 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

A MACRO question

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
Jul 22 '08 #1
3 1532
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?
Jul 22 '08 #2
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)

Jul 22 '08 #3
On Jul 22, 1:54*pm, "Alf P. Steinbach" <al...@start.nowrote:
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!

Jul 22 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Andrew Dalke | last post by:
Here's a proposed Q&A for the FAQ based on a couple recent threads. Appropriate comments appreciated X.Y: Why doesn't Python have macros like in Lisp or Scheme? Before answering that, a...
699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
5
by: Eric Lilja | last post by:
Using a macro, can I change what type an object is being cast to? I know, the initial respone to question might be an instinctive "ugly, don't even think about it!" or "don't use macros at all",...
0
by: Spiro Trikaliotis | last post by:
Hello, assume I define a macro like #if <somecondition> # define MACRO(_x, _y) _x #else # define MACRO(_x, _y) _y #endif
5
by: Mason | last post by:
I'm having some problems converting VBA for Word 2000 to code that VB.Net understands. I recorded a macro in Word to add numbering (a. b. c.) to my paragraphs. I managed to translate quite a bit...
17
by: sounak | last post by:
How could we get a macro name from a macro value such that in a header file #define a 100 #define b 200 now the source file will be such that the user gives 100 then the value is outputted as...
7
by: fei.liu | last post by:
#define ONCFILE_ERR1(funcname, name) \ { \ #ifdef DEBUG\ cerr << __FILE__ << ":" << __LINE__ << " duplicated call to " << funcname << " " << name << endl; \ #endif \ } I want to have...
11
by: Remo | last post by:
Hi All I Have Quation About Macro's plz help why do we have # symbol before any macro line #define STOP 0 ... why con't we use the any other symbol like $, @,, plz answer if any one knows...
5
by: krbyxtrm | last post by:
Hi is there a way to 'manage' function execution using macros? #define MY_CALL_MACRO(MacroName) { g_MacroStack.push_back(MacroName); <some code here...>} such that when i use the...
6
by: pedroalves | last post by:
Hi all, This is not a question about how to #define COMMA , Please keep reading. Recently in binutils, we introduced a macro like this: #define STRING_COMMA_LEN(STR) \ (STR), ((STR) ?...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.