|
Boost Users : |
From: Josh Brown (jbrown_at_[hidden])
Date: 2007-10-03 11:22:14
Tobias Schwinger wrote:
> Michael Fawcett wrote:
>
>> On 10/2/07, Josh Brown <jbrown_at_[hidden]> wrote:
>>
>>> The root of my problem seems to stem from the fact that BOOST_PP_IF
>>> expands both the true and false expressions before it does the if test
>>> and just outputs the already expanded expression. Is this correct; and
>>> if so, is there a way around it?
>>>
>
> Make the IF lazy.
>
>
>>> Or are there any obvious other
>>> solutions to my problem that the boost experts can suggest :)
>>>
>> You'll want to look into BOOST_PP_TUPLE_EAT -
>> http://www.boost.org/libs/preprocessor/doc/ref/tuple_eat.html
>>
>>
>
> Exactly.
>
> #define GET_OPTIONAL_ELEMENT(r, data, elem) \
> BOOST_PP_IF( \
> BOOST_PP_EQUAL(BOOST_PP_SEQ_SIZE(elem), 3), \
> BOOST_PP_SEQ_ELEM, BOOST_PP_TUPLE_EAT(2) \
> )(2,elem)
>
>
Ahh, thank you Tobias and Micheal for this suggestion.
Last night I came up with the idea of pushing on an extra element to
every sequence, that way when the SEQ_ELEM was expanded it would not
error because there was always enough elements in the sequence, but
since the bogus added element was never output it didn't hurt anything
to have it there. However, your solution is an appropriate solution and
not an ugly hack like mine :)
Thanks again
Josh
this is much cleaner than the solution I came up with last night!
> Regards,
> Tobias
>
> _______________________________________________
> 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