two questions on enums

bearophile bearophileHUGS at lycos.com
Thu Apr 3 15:04:17 PDT 2014


Eric:

> 1).  Is there a way to "import" an enum so that you don't need
> to qualify each instance with the type name?  Something like
> java does with its "static import".

In some cases you can use the handy with() statement for that 
purpose.

One example usages:

final switch (foo) with (MyEnum) {
     ...
}


> 2).  It seems that you can't use an enum of struct or class type
> in a switch statement.

Using an enumeration of class instances isn't a good idea, they 
are designed mostly for integral built-in types, including chars, 
etc.

Regarding your enhancement, look here (I suggest an unapply as in 
Scala), you can even vote it:
https://d.puremagic.com/issues/show_bug.cgi?id=596

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list