
On Wed, Oct 1, 2008 at 6:33 PM, Kasra Nassiri(Math & ComSci) <kasra_n500@yahoo.com> 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