Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost preprocessor question
From: Pete Bartlett (pete_at_[hidden])
Date: 2009-01-05 16:54:05


>What about:
>
>CLASS(Foo, FROM(Bar),
> CONSTRUCT(BOOST_PP_EMPTY_SEQ)
> CONSTRUCT((int, a, A)(bool, b, B))
> int A;
> bool B;
>)

>Might that not be a way to avoid the Foo repetition?

It would have to look like

CLASS( Foo, FROM(Bar)
, CONSTRUCT( BOOST_PP_EMPTY_SEQ )
  CONSTRUCT( (int, a, A)(bool, b, B) )
, int A ; bool B ;
)

where you have

#define CONSTRUCT(sequence) sequence

and the CLASS macro does all the work. The macro implementation would be
slightly more complicated because of the nested FOR_EACHs (degrading
maintainability) and debuggability will be impaired, but perhaps still
better than introducing an external code generator to your build setup.

Nb it seems like the 'a' and 'b' are superfluous - the constructor
parameters could be written something like BOOST_PP_CAT(membervarname , _ ).


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