Boost logo

Boost :

Subject: Re: [boost] [preprocessor] Variadics suggestion
From: Paul Mensonides (pmenso57_at_[hidden])
Date: 2012-09-25 03:57:21


On Mon, 24 Sep 2012 15:09:03 -0700, paul Fultz wrote:

>> #define SEQ    (a,b,c)(1,2,3,4)
>> BOOST_PP_VARIADIC_SEQ_TO_SEQ( SEQ )    // expands to
>> ((a,b,c))((1,2,3,4))
>
> In your implementations couldn't you use just two overload macros
> instead of 256? Like this:
>
>     #    define BOOST_PP_VARIADIC_SEQ_TO_SEQ(seq) BOOST_PP_CAT(
>     BOOST_PP_VARIADIC_SEQ_TO_SEQ_1_ seq, BOOST_PP_NIL )() #
>     #    define BOOST_PP_VARIADIC_SEQ_TO_SEQ_1_(...) (( __VA_ARGS__
>     )) BOOST_PP_VARIADIC_SEQ_TO_SEQ_2_ #    define
>     BOOST_PP_VARIADIC_SEQ_TO_SEQ_2_(...) (( __VA_ARGS__ ))
>     BOOST_PP_VARIADIC_SEQ_TO_SEQ_1_
>
>     #    define BOOST_PP_VARIADIC_SEQ_TO_SEQ_1_BOOST_PP_NIL() #   
>     define BOOST_PP_VARIADIC_SEQ_TO_SEQ_2_BOOST_PP_NIL()
>
> Also on a side note, when vardiacs are enabled it would be nice to add
> an `IS_PAREN` macro like this:

Following the other similar macros that are already there, IS_NULLARY,
IS_UNARY, and IS_BINARY, this would be named IS_N_ARY or IS_VARIADIC.

However, what many people fail to realize is just how enormously difficult
(and in some cases impossible) it is to modernize Boost.Preprocessor when
support for VC++ (in particular) is required. It is usually easy to get a
trivial case working. It is amazingly difficult to get non-trivial cases
working because the nature of VC++'s macro replacement algorithm leads to
combinatorial difficulties. E.g. It isn't that difficult to write macros
A and B, test them individually to confirm that they work, but then some
other macro C (possibly even written by a user) uses both and everything
breaks. The point is that there is no black box testing. It is a
*horrible* preprocessor. Edward has had some exposure to this when we
worked on the limited variadic support that we did add.

Besides the above, adding significant work to Boost.Preprocessor is
iterating a dead horse. It is *way* outdated in terms of modern
preprocessor metaprogramming technique. It needs a complete rewrite (i.e.
it needs to be Chaos or similar to it) to support variadics properly. To
modernize it, one has to abandon VC++'s preprocessor or somehow get MS to
fix it (which is also beating a dead horse). There have been claims (on
this list) that you can modernize it with current VC++, but, sorry, you
can't. Not without throwing out a predictable, self-terminating recursion
model. You could maybe get about a third of the way from
Boost.Preprocessor to Chaos.

Regards,
Paul Mensonides


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