Boost logo

Boost :

Subject: Re: [boost] [c++11]
From: Thomas Heller (thom.heller_at_[hidden])
Date: 2013-06-18 06:21:02

On Tue, Jun 18, 2013 at 11:37 AM, Jonathan Wakely

> On 18 June 2013 08:33, Thomas Heller wrote:
> > On Mon, Jun 17, 2013 at 11:54 PM, Niall Douglas <ndouglas_at_[hidden]
> >wrote:
> >> Now, nothing in proposed Boost.AFIO uses variadic templates in a way not
> >> replaceable with preprocessor programming. However it very /nearly/
> did: I
> >> had this neato bit of evil variadic instantiation which let you convert
> an
> >> unknown set of trailing args into a std::tuple<> for storage, then
> /unpack/
> >> said std::tuple<> back into an unknown set of trailing args, all with
> >> perfect forwarding. Effectively it was a compile-time std::function<>
> >> implementation.
> >>
> >
> > That is *very* easily achievable with the preprocessor. The outstanding
> > feature here, IMHO, is the perfect forwarding, which is of course not
> > possible with C++03. In any case, I couldn't think of how you'd unpack
> the
> > tuple to call the function without the preprocessor. Could you please
> show
> > me a code snippet how this could be done?
> Very, very easily, see the apply() example in [intseq.general] in the
> C++14 draft, taken from
> Doing that with the preprocessor instead would be ... I don't have a
> polite way to say it.

Well, it has been done. Except for passing a variadic amount of parameters
(which would need to be emulated with the PP), everything else is perfectly
doable within C++03 (ok, perfect forwarding is kinda missing ... Boost.Move
might help here).

Examples of where this has been done is boost.fusion. With the help of cons
lists and iterators over tuples, you wouldn't even need the preprocessor to
emulate a variadic amount of parameters. Heck, there is even a
boost::fusion::invoke as well as a boost::fusion::fused class template. The
user of such code never ever gets in contact with the preprocessor based
My point is that saying this is impossible without variadic templates is
plainly wrong. Of course, and I said this in my previous message as well,
variadics ease the way to write such code. A preprocessor (with the help of
partial preprocessing) based solution might be more efficient though,
because no template recursions are needed.

To put in a nutshell, variadic templates are a great addition to the
language, and together with perfect forwarding, you get a very nice and
elegant solution to the problem we are discussing here. However, every
author has to decide for his/her own sake what to use here. It is all a
matter of what compilers are supposed to be supported. I for one do not
want to maintain a variadic template based and a preprocessor based
solution. As the preprocessor based solution is supported on much, much
more compilers, the decision for me is clear to fall back to such a legacy
solution. Especially because i have to regularly deal with such compilers.

However, IMHO, boost should move to a 2.0 version to advocate plain C++-11
without looking back to legacy compilers. As soon as the compiler landscape
evolves to support more an more C++11 features, everyone is able to benefit
from such a solution. The Boost 1.X line however should remain C++03

> _______________________________________________
> Unsubscribe & other changes:

Boost list run by bdawes at, gregod at, cpdaniel at, john at