Setting up a final switch from a list
Cecil Ward
cecil at cecilward.com
Wed Aug 2 18:19:55 UTC 2023
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.
More information about the Digitalmars-d-learn
mailing list