
Hi, I think the preprocessor library could help me here but I'm having problems understanding it. Maybe someone will be so kind to explain it to me a bit. Here is what I want to produce: void foo(char); void foo(int); void foo(unsigned int); .... You got the idea. Something that repeats a list of things i.e. here, types. How can I do that? Thanks! Eric [Non-text portions of this message have been removed]

You can use BOOST_PP_LIST_FOR_EACH #define ARG_LIST (char, (int, (unsigned int, (long, ...)))) #define DO_IT(r, data, elem) void foo( elem ); BOOST_PP_LIST_FOR_EACH( DO_IT, , ARG_LIST ) The LIST_FOR_EACH macro repeatedly calls DO_IT for every member in ARG_LIST. In DO_IT, r is the next available LIST_FOR_EACH repetition. data is the middle argument to LIST_FOR_EACH (in our case, nothing), and elem is the current element under inspection (char or int or unsigned int, etc...) HTH, Tanton ----- Original Message ----- From: "Eric Robert" <synapzzz@hotmail.com> To: <Boost-Users@yahoogroups.com> Sent: Thursday, May 01, 2003 5:40 PM Subject: [Boost-Users] PP library...
Hi,
I think the preprocessor library could help me here but I'm having problems understanding it. Maybe someone will be so kind to explain it to me a bit. Here is what I want to produce:
void foo(char); void foo(int); void foo(unsigned int); ....
You got the idea. Something that repeats a list of things i.e. here, types. How can I do that?
Thanks! Eric
[Non-text portions of this message have been removed]
Info: <http://www.boost.org> Wiki: <http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl> Unsubscribe: <mailto:boost-users-unsubscribe@yahoogroups.com>
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/

Tanton Gibbs wrote:
You can use BOOST_PP_LIST_FOR_EACH
#define ARG_LIST (char, (int, (unsigned int, (long, ...)))) #define DO_IT(r, data, elem) void foo( elem );
BOOST_PP_LIST_FOR_EACH( DO_IT, , ARG_LIST ) ^ This empty argument is undefined in C++. In C99, it is allowed and called a "placemarker." Instead of passing nothing, just pass anything and ignore it.
// ----- // #include <boost/preprocessor/list/for_each.hpp> #define ARG_LIST \ (char, (int, (unsigned, (long, BOOST_PP_NIL)))) \ /**/ #define DO_IT(r, ignored, elem) \ void foo( elem ); \ /**/ BOOST_PP_LIST_FOR_EACH( DO_IT, ?, ARG_LIST ) #undef ARG_LIST #undef DO_IT // ----- // Note that there are other ways to do this also. For instance, use of "sequences" makes the definition of ARG_LIST easier: // ----- // #include <boost/preprocessor/seq/for_each.hpp> #define ARGS \ (char)(int)(unsigned)(long) \ /**/ #define DO_IT(r, ignored, elem) \ void foo( elem ); \ /**/ BOOST_PP_SEQ_FOR_EACH( DO_IT, ?, ARGS ) #undef ARGS #undef DO_IT // ----- // Of course, if what you want to generate is much larger, you might want to use some form of vertical repetition: // ----- // #include <boost/preprocessor/iteration/local.hpp> #include <boost/preprocessor/seq/elem.hpp> #define ARGS \ (char)(int)(unsigned)(long) \ /**/ #define BOOST_PP_LOCAL_MACRO(n) \ void foo( BOOST_PP_SEQ_ELEM(n, ARGS) ); \ /**/ #define BOOST_PP_LOCAL_LIMITS \ (0, BOOST_PP_SEQ_SIZE(ARGS) - 1) \ /**/ #include BOOST_PP_LOCAL_ITERATE() #undef ARGS // ----- // Regards, Paul Mensonides

Eric Robert wrote:
Hi,
I think the preprocessor library could help me here but I'm having problems understanding it. Maybe someone will be so kind to explain it to me a bit. Here is what I want to produce:
void foo(char); void foo(int); void foo(unsigned int); ....
You got the idea. Something that repeats a list of things i.e. here, types. How can I do that?
Thanks! Eric
The best way to do it depends on the scope (i.e. size) of what you want to repeat. Doing something like the above is pretty easy in a variety of different ways, but I'm guessing that you want to do something more complicated. Regards, Paul Mensonides
participants (3)
-
Eric Robert
-
Paul Mensonides
-
Tanton Gibbs