Using macros to build typelists incrementally

G

greek_bill

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 :(
 
G

Gianni Mariani

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/html/group__GenericFactories.html

code here:
http://www.google.com/codesearch?hl...s_f=austria-0.8/src/austria/code/at_factory.h
 

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
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top