#Iterate over all values in an enum

1 messages · Page 1 of 1 (latest)

foggy pollen
#

Suppose I have an enum:
const my_enums = enum{
val1: bool,
val2: bool,
val3: bool,
};

Is there a way for me to loop over all the values in the enum to check what value they were set too (ie (my_enums) |my_enum| {}) besides manually calling each value like my_enum.val1 ... ?

primal hinge
#

not at pc so can't confirm but I believe std.meta.fields

wise abyss
#

@typeInfo(T).Enum.fields

foggy pollen
#

Thanks!

rich ivy
#

there's also std.enums.values(E) which actually returns []const E

foggy pollen
#

For anyone that comes to this thread later, the first two options are for comtime int values while the last one (std.enums.values) is can be runtime!