Boost logo

Boost :

From: Markus Schöpflin (markus.schoepflin_at_[hidden])
Date: 2005-07-15 03:33:38


Paul Mensonides wrote:

>>-----Original Message-----
>>From: boost-bounces_at_[hidden]
>>[mailto:boost-bounces_at_[hidden]] On Behalf Of Markus Schöpflin

>>Is there a way to get this:
>>
>> scope().attr("foo") = 1; scope().attr("bar") = 2;
>>
>>or this:
>>
>> scope().attr("foo") = foo; scope().attr("bar") = bar;
>>
>>IOW, how can I prevent macro expansion for X when invoked from
>>PY_DEFINE_CONSTANTS()?

> The only way to prevent expansion is with # and ##--and that's all about timing.

[snip solution]

> The trick here is to get the sequence inside the machinery in a way that allows
> the machinery to prevent it from expanding. That's the trailing 'INTERCEPT_ and
> the 'seq ## 0'. From there, it can be immediately processed with custom
> sequential iteration to make a new sequence with a argument/string pairs.

I see and I'm amazed, as usual when dealing with the preprocessor. :-)

> This is about the best way that you can do it, but I won't guarantee that it
> will work on buggy preprocessors. In fact, I know it won't work on VC. The
> timing is tricky, and it's intrusive on the interface, but that's about the only
> way that it can be done.

Fortunately I don't have to use MSVC, but you are right, the interface
doesn't really look nice. I think I'll have to make a little poll at the
office on what's better:

PY_DEFINE_CONSTANT(foo);
PY_DEFINE_CONSTANT(bar);

or

PY_DEFINE_CONSTANTS((foo)(bar) BOOST_PP_INTERCEPT_)

Maybe we'll just stick with the simple macro then.

Thanks for your help!

Markus


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk