Boost logo

Boost :

Subject: Re: [boost] [offtopic] C++11 useful trick
From: Eric Niebler (eric_at_[hidden])
Date: 2012-07-29 02:55:49


On 7/28/2012 7:10 PM, Dave Abrahams wrote:
>
> on Wed Jul 04 2012, Eric Niebler <eric-AT-boostpro.com> wrote:
>
>> He's using a variant of the variadic tuple trick. He wants to find the
>> Nth element in a parameter pack. So he puts all the elements in a
>> tuple-like thingy (select_impl) which holds individual elements, each
>> in its own base class (select_base). But only the Nth base actually
>> holds onto its argument. (See the partial specialization of
>> select_base.) His solution instantiates O(N) instances of select_base,
>> but gets you the Nth element in O(1). Fiendishly clever.
>
> That explanation doesn't match what I'm seeing in his latest attachment

Right, I was commenting on this:
http://llvm.org/bugs/attachment.cgi?id=8825

> (http://llvm.org/bugs/attachment.cgi?id=8838&action=edit), which doesn't
> require storing anything. Which is pretty cool!

His latest implementation is very, very cool and I've already found
another use for his technique.

I'm slightly dismayed that we need to be so very clever to use variadic
templates efficiently. This stuff is not obvious AT ALL.

-- 
Eric Niebler
BoostPro Computing
http://www.boostpro.com

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