Boost logo

Boost :

Subject: Re: [boost] [Variant] C++11 variadic template implementation
From: Larry Evans (cppljevans_at_[hidden])
Date: 2012-05-01 07:30:08


On 04/15/12 14:06, Larry Evans wrote:
> On 04/15/12 08:02, paul Fultz wrote:
>>
>>
>>
>>
>> ----- Original Message -----
>>> From: Mathias Gaunard <mathias.gaunard_at_[hidden]>
> [snip]
>>> Did you find a magic way to make a switch statement from a template
>>> parameter pack?
>>
>> Well you can expand the parameter pack to create a static array of
>> function pointers. This is how it is done in this implementation:
>>
>> http://thenewcpp.wordpress.com/2012/02/15/variadic-templates-part-3-or-how-i-wrote-a-variant-class/
>>
> [snip]
>
> IIUC, something similar was proposed earlier; however, a preprocessor
> generated switch statement was deemed faster:
>
> http://article.gmane.org/gmane.comp.lib.boost.devel/169739
>
> However, maybe compiler's have improved since then.
>
Looking closer, I see that the gmane.comp.lib.boost.devel/169739
code did not use parameter pack expansion because it didn't use
variadic templates; however, it did use a vector of function pointers.

Also, apparently the switch library has an alternative implementation
which does something similar here:

http://svn.boost.org/svn/boost/sandbox/switch/libs/switch/alternate/switch/sorted_array.hpp

There's also, apparently, a test driver to compare the speed of
alternative implementations here:

http://svn.boost.org/svn/boost/sandbox/switch/libs/switch/alternate/switch/test_speed.cpp

-regards,
Larry


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