I have some enum types which I am using to access values from lookup tables. I thought for instances where the values would be the same for each enum that I might be able to do this:
type
aEnum = enum A1, A2, A3
bEnum = enum B1, B2, B3
eitherEnum = aEnum | bEnum
let lookup: array[eitherEnum, int] = [1, 2, 3]
But it fails and returns Error: ordinal type expected. Is there anyway other than defining the lookup table for each enum separately?The easiest way to do this would be to make a procedure that does the look up as such:
type
aEnum = enum A1, A2, A3
bEnum = enum B1, B2, B3
let lookupArr = [1, 2, 3]
proc lookup*(enm: aEnum or bEnum): int = lookupArr[ord enm]
for i in 0..2:
assert lookup(aEnum(i)) == lookup(bEnum(i))