Iterating over a "packed" enum

i have the type enum { E0, E1, ... } where each Ei would have the corresponding integer value i

i now want to iterate over all values of this enum type – but what’s the best way to know the “cardinality” of this set???

i can obviously create a special E_last value, but was looking for a solution where i didn’t need to add a sentinel value…

suggestions???

You can use std.meta.fields to get all fields as a []const Type.EnumField.

1 Like