Boost logo

Boost Users :

Subject: Re: [Boost-users] [preprocessor] BOOST_PP_VARIADIC_SIZE() and g++ in 1.52
From: Kim Barrett (kab.conundrums_at_[hidden])
Date: 2012-12-13 15:11:36


On Dec 11, 2012, at 10:19 AM, Nat Linden wrote:
> In fact, when I change the definition of the intercept() macro below to:
>
> #define intercept(FIRST, ARGS...) \
> targetfunc(transform(FIRST) \
> , boost::lexical_cast<std::string>(BOOST_PP_VARIADIC_SIZE(ARGS)))
>
> I see that BOOST_PP_VARIADIC_SIZE() expands to 1 for
> intercept("first") as well as for intercept("first", "second").
>
> Is it possible to achieve what I want with my present suite of
> compilers? Is there some workaround we could use until (at some point
> in the indefinite future) we've upgraded all our compilers so that
> even the oldest of them supports variadic functions?

Perhaps something like the following will do what you need?

#define intercept(ARGS...) \
   BOOST_PP_IIF( \
       BOOST_PP_EQUAL(1, BOOST_PP_VARIADIC_SIZE(ARGS)), \
       intercept_1, \
       intercept_many)(ARGS)

where the definitions of intercept_1 and intercept_many should be
obvious.


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