Using macros to build typelists incrementally

Discussion in 'C++' started by greek_bill@yahoo.com, Dec 5, 2006.

  1. Guest

    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, 2006
    #1
    1. Advertising

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

    code here:
    http://www.google.com/codesearch?hl...s_f=austria-0.8/src/austria/code/at_factory.h
    Gianni Mariani, Dec 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Moosebumps

    Capturing stdout incrementally

    Moosebumps, Apr 3, 2004, in forum: Python
    Replies:
    5
    Views:
    503
    David Bolen
    Apr 7, 2004
  2. Replies:
    0
    Views:
    349
  3. Jon Slaughter

    Loki Typelists

    Jon Slaughter, Sep 28, 2005, in forum: C++
    Replies:
    5
    Views:
    447
    Jon Slaughter
    Sep 29, 2005
  4. Dave Branton
    Replies:
    0
    Views:
    274
    Dave Branton
    Nov 2, 2006
  5. Thant Tessman

    macros that build macros

    Thant Tessman, Sep 11, 2007, in forum: C Programming
    Replies:
    6
    Views:
    368
    Dave Hansen
    Sep 11, 2007
Loading...

Share This Page