Truly compile-time string hashing in C++

Viewed 4888

Basically I need a truly compile-time string hashing in C++. I don't care about technique specifics, can be templates, macros, anything. All other hashing techniques I've seen so far can only generate hashtable (like 256 CRC32 hashes) in compile time, not a real hash.

In other words, I need to have this

printf("%d", SOMEHASH("string"));

to be compiled as (in pseudo-assembler)

push HASHVALUE
push "%d"
call printf

even in Debug builds, with no runtime operations on string. I am using GCC 4.2 and Visual Studio 2008 and I need the solution to be OK for those compilers (so no C++0x).

6 Answers
Related