Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2007-10-31 11:42:33


on Tue Oct 30 2007, Yu Di <diyu60607-AT-yahoo.com> wrote:

> Hi, I am trying to use the preprocessor lib to generate something like
>
> Cons<a, Cons<b, Cons<c, Cons<d, Nil> > > >
>
> from
>
> (a) (b) (c) (d)

The easy way to do things like this is to take advantage of the fact
that the PP can generate invalid fragments of syntax, so something
like:

// not tested -- I may have the argument order wrong among other things
#define cons_open(z, e, _) Cons<e,
#define cons_close(z, e, _) >
#define GENERATE(x) \
     BOOST_PP_SEQ_FOR_EACH(cons_open, x, ~) Nil BOOST_PP_SEQ_FOR_EACH(cons_close,x,~)

HTH,

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

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