How to do a checked cast from base-type to enum-type

dnspies dspies at ualberta.ca
Sat Apr 5 19:21:33 PDT 2014


Is there a way to do a checked cast from a base type to an 
enum-type (so that an exception is thrown if it fails)?

ie something like

enum x : dchar { A : 'a', B : 'b', C : 'c' };

x get_x() {
  dchar r = get_char();
  return cast(x)r; //Throw exception if this cast fails
}


More information about the Digitalmars-d-learn mailing list