Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 5th, 2006, 09:35 PM
greek_bill@yahoo.com
Guest
 
Posts: n/a
Default 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 :(

  #2  
Old December 5th, 2006, 09:35 PM
Gianni Mariani
Guest
 
Posts: n/a
Default Re: Using macros to build typelists incrementally

greek_bill@yahoo.com wrote:
Quote:
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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles