Boost logo

Boost Users :

From: Tanton Gibbs (thgibbs_at_[hidden])
Date: 2003-05-06 14:19:46


Also, I was asked by a coworker if the following would be std C++:

BOOST_PP_LIST_FOR_EACH( DO_IT, BOOST_PP_EMPTY(), ARG_LIST )

I said that it would not because BOOST_PP_EMPTY would be expanded first to
nothing, which would be the same as
BOOST_PP_LIST_FOR_EACH( DO_IT, , ARG_LIST )
which Paul explicitly said below was non-conformant.

Is this correct?
----- Original Message -----
From: "Eric Robert" <synapzzz_at_[hidden]>
To: <Boost-Users_at_[hidden]>
Sent: Tuesday, May 06, 2003 2:19 PM
Subject: [Boost-Users] RE: PP Library...

> Ok,
> I see that there are 3 ways of doing this now. What is the
> recommendation for something small like 2 or 3 lines for each native
> types i.e. more or less 12 iterations?
>
>
> Eric
>
> "Paul Mensonides" <yg-boost-users_at_[hidden]> wrote
> > 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
>
>
>
>
>
> [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_at_[hidden]>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>
>


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net