Boost logo

Boost :

Subject: Re: [boost] [c++11]
From: Niall Douglas (ndouglas_at_[hidden])
Date: 2013-06-18 12:41:12

> > 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.
> >
> [snip]
> I can already here you ranting about how variadic templates allows you to
> use
> an arbitrary number of parameters while the preprocessor solution can not.

"Ranting"? That's a little harsh don't you think? I am plenty aware that
variadic templates have similar limits in parameter depth as recursive

Actually that wasn't the problem I found. And yes, I am more than well aware
of Boost's existing facilities in Phoenix et al. and thanks to everyone for
pointing them out in depth.

> > That evil variadic template machinery gets rid of that problem. And
> > its only replacement is std::function<> - you *cannot* implement that
> > functionality (pure compile time std::function<>) without variadic
> > templates because you can't properly unpack them without.

I'll quickly explain the problem I found just for the list's reference: I
struggled to implement nested args-to-tuple => tuple-to-args expansion without
variadic templates i.e. if I bind up a callable and a set of args into a
compile time container, and then pass that itself as part of a set of unknown
args, I kept running into instantiation limits in C++03 era compilers.

I'll entirely grant you, before anyone comments, that it could be entirely my
own shoddy metaprogramming skills. And yes, I know you can tell some compilers
to increase their hard limits.

Either way, with C++03 era compilers it just became easier to use a
function<>, push the problem into the runtime and be done with it, especially
as the preprocessor generated template specialisations are lengthy and
substantially extend compile times, as other posts have mentioned.

That was the basis of my "quite bold statement" which you don't think holds:
an earlier failure of mine in C++03 which was fairly straightforward to
implement in C++11, and something I probably would have moved ahead with in
Boost.AFIO if it weren't that I'm pretty sure we'll need to drop the variadic
templates requirement. I accept, given the list's response, that the cause is
likely my incompetence as a programmer and others on this list can perform
magic I cannot. I therefore retract my earlier assertion.


Opinions expressed here are my own and do not necessarily represent those of 
BlackBerry Inc.

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