|
Boost : |
Subject: Re: [boost] [preprocessor] Variadics suggestion
From: Kitten, Nicholas (nkitten_at_[hidden])
Date: 2012-09-25 15:33:57
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()
That would be the succinct solution I was looking for - it didn't
occur to me that recursion wouldn't be an issue here because of the
order of macro substitution. Thanks a ton!
On Tue, Sep 25, 2012 at 3:45 AM, Paul Mensonides <pmenso57_at_[hidden]> wrote:
> Get a good preprocessor (such as Wave or a different compiler) and use
> Chaos. Bad preprocessors are precisely the reason that Boost.Preprocessor
> is not much more functional than it is.
Yup, and support for bad preprocessors would be the reason I'm using
Boost.Preprocessor instead of Chaos (or a dedicated code generator)
>> #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))
>
> This is probably doable.
>> Next, I would suggest having a documented IS_EMPTY(...) function for
>> detecting an empty variadic list.
>
> No. Your implementation causes undefined behavior which happens to work
> on VC++.
>> Finally, I would suggest using the preceding IS_EMPTY(...) function to
>> allow VARIADIC_SIZE(...) to return 0
>
> Again, no. Emptiness is a valid argument.
1 out of 3... I'll take it :)
> 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.
I understand why you feel that way, but it doesn't change the sad
reality that VC's broken preprocessor (and code using it) is
everywhere. I might even say the same about any working C
preprocessor when compared to D's syntactically and type-safe template
mixins, but unfortunately I don't get to choose the tools my company
uses. So until that bright future where FORTRAN is completely dead,
Google and Apple have deposed MS, and we've all long forgotten about
the tragic mess which was the VC++ preprocessor, I'll just say thanks
again for patiently educating the ignorant like me, and for iterating
on a dead horse ;)
Best,
-Nick Kitten
Software Engineer
Center for Video Understanding Excellence
ObjectVideo, Inc.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk