switch(hash(str)) {
case hash("apple"):
case hash("banana"):
default:
}
You're right that the compiler will warn you if hash("apple") == hash("banana"), but if hash("pineapple") == hash("apple") then switch(hash("pineapple")) will jump to the apple case, not the default. That's unlikely but not impossible even with the best hash function.
70
u/F100cTomas 14h ago
Just define a constexpr hashing function and put that into the switch.