Am I right in thinking that final switch can be used to check that all the elements in an enum are handled in cases? Thinking that this is a worthwhile safety check, I’d like to convert an existing list into an enum for use in a final switch. I have an existing list which I use elsewhere,
   enum terminators = [ '%', ':', '?' ];

I pass that to some routine. I am wondering how to safely create either an enum with values or have the enum with values declared first and then create the list from it. That is, maybe start the other way around
 enum terminators_t = { percent = '%', colon = ':', qmark = '?' };
and then automatically generate the list from that. The idea is to avoid duplication in the array list and enum value list, so that if I ever add one, I will not be able to update the other to match.

Any suggestions? I need some good compile-time stuff. It doesn’t matter which direction we go in, from one to the other, but my money is on the all-values enum generating the array list.

Reply via email to