I'd like to be able to have a static string converted to a hash value at compile time rather than generating code to evaluate it.
Like this:
But have the compiler generate this code for instance:
If the GetHash() function is sufficiently simple and the string is sufficiently short MSVC will do this for me, but if the string is longer than 10 chars it will generate a function call instead. Is there any way to force the compiler evaluate more than 10 chars? Or any magic construct that will force the compiler evaluate it completely?
From what I gather there's a solution in C++0x with variadic templates and user-defined literals, but while waiting for compilers to implement this I was hoping for a standard c++ way of doing things. Any suggestions?
Like this:
Code:
const int hash = GetHash("MyFancyString");
But have the compiler generate this code for instance:
Code:
const int hash = 0x28AC8B1F;
If the GetHash() function is sufficiently simple and the string is sufficiently short MSVC will do this for me, but if the string is longer than 10 chars it will generate a function call instead. Is there any way to force the compiler evaluate more than 10 chars? Or any magic construct that will force the compiler evaluate it completely?
From what I gather there's a solution in C++0x with variadic templates and user-defined literals, but while waiting for compilers to implement this I was hoping for a standard c++ way of doing things. Any suggestions?