I am trying to initialize an enum using the hash codes of the type label:
enum ValueType {
CLOSED = hashCode("CLOSED"),
OPEN = hashCode("OPEN"),
SEKIHAIRITSU = hashCode("SEKIHAIRITSU"),
ZWEITMANDAT = hashCode("ZWEITMANDAT")
};
ValueType valuetype;
The hashCode
function is an implementation of Java's function:
constexpr long hashCode(const char *string) {
long h = 0;
int off = 0;
for (int i = 0; i < strlen(string); i++) {
h = 31 * h + string[off++];
}
return h;
}
I get an error on Sekihairitsu
and Zweitmandat
:
expression must have a constant value -- value exceeds range of "long"
The weird thing is, it isn't outside of long. When I run the hashCode
function by myself, it returns -1606024481
for Sekihairitsu and -710079088
for Zweitmandat. Neither of those are outside the range of long, or even int.
Anybody know what the problem is? I have already tried enum ValueType : long
.