I need to get the maximum value of an enum at compile time. In C++ I can do this:
enum class MyEnum {
a = 1,
b = 2,
c = 3,
LAST = c,
};
Then I can create an array to store some stuff for each enum value, like this:
int countOfEachType[(int)MyEnum::LAST];
But how do I do this in Zig? I tried this:
const MyEnum = enum(u32) {
a = 0,
b = 1,
c = 2,
LAST = c,
};
but it says “use of undeclared identifier ‘c’”
I tried this:
const MyEnum = enum(u32) {
a = 0,
b = 1,
c = 2,
LAST = .c,
};
but it says “type ‘u32’ has no members”
So then I gave up and tried this:
const MyEnum = enum(u32) {
a = 0,
b = 1,
c = 2,
LAST = 2,
};
But it says “enum tag value 2 already taken”
Or is there a more Zig-ish way to get the max enum value? Something like @maxEnumValue(MyEnum)
?