.
//////////////////////////
// strings as case labels
// this does not handle hash collisions
//////////////////////////
constexpr uint32_t djb2Hash(
const char* str, int index = 0)
{
return !str[index]
? 0x1505
: (djb2Hash(str, index + 1) * 0x21) ^ str[index];
}
// Create a literal type for short-hand case strings
constexpr unsigned int operator"" _C(
const char str[], size_t size)
{
return djb2Hash(str);
}
void Bloblawblah(const std::string& cond)
{
switch(djb2Hash(cond.c_str()))
{
case "Hello"_C: std::cout << "Goodbye"; break;
case "World"_C: std::cout << "Planet"; break;
default: std::cout << "BOGUS!";
}
std::cout << std::endl;
}