Boost logo

Boost Users :

Subject: Re: [Boost-users] [preprocessor] removing parentheses
From: Edward Diener (eldiener_at_[hidden])
Date: 2010-08-04 17:38:28


On 8/4/2010 5:09 PM, Daniel Bradburn wrote:
> I'm not sure without seeing exactly what you are trying to do, but perhaps
>
> http://www.boost.org/doc/libs/1_43_0/libs/preprocessor/doc/ref/tuple_rem.html
>
> or
>
> http://www.boost.org/doc/libs/1_43_0/libs/preprocessor/doc/ref/tuple_rem_ctor.html
>
> Could help you.

Except that:

1) I do not know ( or normally care ) how many commas are in the
parenthesized value ( ie. size of the tuple )

2) The value can be passed without any parentheses and therefore not be
a tuple. For this second problem I can force the end-user always to put
parentheses around the passed value, even if it does not need it to form
a single macro value. But 1) would still remain a problem. Of course I
could solve 1) by forcing the end-user to also pass the number of commas
in the parenthesized value as a separate template parameter, but I think
that is too much of a burden for the end-user.

I just want the end-user to pass the value as a single macro parameter,
and to use the value without the outer parentheses if the value contains
commas. But perhaps this is just impossible to do with C++'s macro
facilities. The preprocessing library is so great I was hoping it could
even solve this problem. In reality I may not need to strip off the
parentheses from the value ( which in my particular case forms part of a
C++ declaration ), since redundant parentheses almost ( possibly ) never
causes a syntax error in C++.

It does seems as if the preprocessor library should have the
functionality I require since it is able to extract a value from a
sequence via BOOST_PP_SEQ_ELEM, and a sequence can be in the simple form
of '(value)'. However my tests show that if I pass a non-sequence, such
as just 'value' to BOOST_PP_SEQ_ELEM, the compiler gives a warning and
the result is bogus.

>
> > To: boost-users_at_[hidden]
> > From: eldiener_at_[hidden]
> > Date: Wed, 4 Aug 2010 16:05:57 -0400
> > Subject: [Boost-users] [preprocessor] removing parentheses
> >
> > I have a single macro parameter which allows its passed value to contain
> > commas. Therefore the user of the macro needs parentheses around the
> > parameter if it contains one or more commas ( to does not have to ).
> > When processing this parameter in a macro I would like to remove the
> > outer parentheses if they are there before passing the value on for
> > further processing. Is there a way to do this using some preprocessor
> > library macro ?
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users


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