|
Boost : |
Subject: Re: [boost] [switch] Is there any interest in library switch extention?
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2008-10-01 12:43:20
On Wed, Oct 1, 2008 at 6:33 PM, Kasra Nassiri(Math & ComSci)
<kasra_n500_at_[hidden]> wrote:
>>I hardly see how this could work for a O(1) lookup (the point of the
>>switch statement).
>
> I have found a compile time solution! However, we need C++0x :(
> A hash functions with output type of <int> so we could embed the statement in a normal switch statement on C++0x.
>
so const_hash_function is a constexpr?
Still, if the case values are not contiguous, most compilers will
require at best logN lookups (they could do better with perfect
hashing, but is there any compiler that actually does it?), so the
improvement is not that great.
Also, on current hardware, an O(1) lookup done with and indirect jump
is not necessarily better than O(n) lookup done with conditional
branches (in fact it might be much worse), for small values of n, at
least.
-- gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk