473,508 Members | 2,218 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using macros to build typelists incrementally

Hi all,

I'd like to have code that looks like the following :

BEGIN(Foo)
ADD(float);
ADD(int);
ADD(char);
END()

I'd like the above code to somehow append each type into a typelist,
which is available as a symbol, i.e. something like (using Loki's
typelists):

typedef NullType FOO1;
typedef Loki::TL::Append<FOO1, float>::Result FOO2;
typedef Loki::TL::Append<FOO2, int>::Result FOO3;
typedef Loki::TL::Append<FOO3, char>::Result FOO4;
typedef FOO4 Foo;

I've been trying to think of various ways to achieve this (e.g. using
boost::preprocessor, using __LINE__, etc), but where I keep getting
stuck is the fact that I can't have 'variables' in macros. I need to
somehow use the result from one macro as input into another, to call
macros recursively, or to have a 'global' variable that keeps track of
some 'state'.

Any ideas?

Thanks,

Bill
PS I could, in theory, using __COUNTER__ to 'guess' the name of the
_previous_ result. I haven't pursued this much, because __COUNTER__ is
compiler specific :(

Dec 5 '06 #1
1 2084
gr********@yahoo.com wrote:
Hi all,

I'd like to have code that looks like the following :

BEGIN(Foo)
ADD(float);
ADD(int);
ADD(char);
END()

I'd like the above code to somehow append each type into a typelist,
which is available as a symbol, i.e. something like (using Loki's
typelists):

typedef NullType FOO1;
typedef Loki::TL::Append<FOO1, float>::Result FOO2;
typedef Loki::TL::Append<FOO2, int>::Result FOO3;
typedef Loki::TL::Append<FOO3, char>::Result FOO4;
typedef FOO4 Foo;

I've been trying to think of various ways to achieve this (e.g. using
boost::preprocessor, using __LINE__, etc), but where I keep getting
stuck is the fact that I can't have 'variables' in macros. I need to
somehow use the result from one macro as input into another, to call
macros recursively, or to have a 'global' variable that keeps track of
some 'state'.

Any ideas?

Thanks,

Bill
PS I could, in theory, using __COUNTER__ to 'guess' the name of the
_previous_ result. I haven't pursued this much, because __COUNTER__ is
compiler specific :(

I have done somthing like this before. Look at the "at_factory.h" header
in austria c++.

doxygen here:
http://austria.sourceforge.net/dox/h...Factories.html

code here:
http://www.google.com/codesearch?hl=...e/at_factory.h
Dec 5 '06 #2

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

Similar topics

16
2648
by: Suzanne Vogel | last post by:
Hi, I've been trying to write a function to test whether one class is derived from another class. I am given only id's of the two classes. Therefore, direct use of template methods is not an...
13
6056
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
5
13726
by: Veit Wiessner | last post by:
I wrote a program that handles the buildcount of projects (gets called every time I compile a project, it writes a header file which is #include-ed in the project). My question is this, is it...
4
1686
by: Chronologic | last post by:
All, I have an issue I would like some expert help on. I understand, or so I believe, that C# does not support the concept of a "compile time macro". At least not in the sense I'm looking...
1
1617
by: The Fox | last post by:
My VB.NET application will call a remote Web Service function that returns lots of data for reporting purpose. The data is finally binding to a DataGrid. It does take time! Is there any ways to...
8
2759
by: robert | last post by:
Hello, I want to put (incrementally) changed/new files from a big file tree "directly,compressed and password-only-encrypted" to a remote backup server incrementally via FTP,SFTP or DAV.... At...
10
2920
by: Ray | last post by:
I am reading Andrei Alexandrescu's book. The ideas presented there sound really good, but I wonder--is there really a lot of people using it? Or it's simply too esoteric for mortals? Cheers Ray
16
9332
by: Mark Rae | last post by:
Hi, Supposing I had a string made up of a person's name followed by their profession in parentheses e.g. string strText = "Tiger Woods (golfer)"; and I wanted to extract the portion of the...
6
2095
by: Thant Tessman | last post by:
Back before C++ templates, I was taught a trick whereby one built C macros that built other C macros. I can't remember how the heck we did it. The problem is that there seems to be no standard way...
0
7336
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7401
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7063
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7504
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5640
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5059
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4720
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3196
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1568
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.