[Issue 1112] New: Allow enums in WithStatements

Ary Manzana ary at esperanto.org.ar
Sat Apr 7 22:24:23 PDT 2007


d-bugmail at puremagic.com escribió:
> http://d.puremagic.com/issues/show_bug.cgi?id=1112
> 
>            Summary: Allow enums in WithStatements
>            Product: D
>            Version: unspecified
>           Platform: All
>         OS/Version: All
>             Status: NEW
>           Severity: enhancement
>           Priority: P2
>          Component: DMD
>         AssignedTo: bugzilla at digitalmars.com
>         ReportedBy: deewiant at gmail.com
> 
> 
> Been asked for a few times, submitting it here for posterity.
> 
> enum Enum {
>         A = 0, B, C
> }
> 
> void main() {
>         with (Enum) {
>                 assert (A == 0);
>                 assert (B == A+1);
>                 assert (C == B+1);
>         }
> }
> 
> It would be handy if the above worked. A common use case is switching on an
> enum:
> 
> enum Enum {
>         A = 0, B, C
> }
> 
> void main() {
>         Enum e;
>         with (Enum) switch (e) {
>                 case A:
>                 case B:
>                 case C:
>                 default: break;
>         }
>         // the above looks much better than:
>         switch (e) {
>                 case Enum.A:
>                 case Enum.B:
>                 case Enum.C:
>                 default: break;
>         }
> }
> 
> 

In fact, it would be nice to be able to ommit the name of the enum if 
one is switching an enum value.

Enum e;
switch(e) {
     case A:
     case B:
     case C:
     default: break;
}

That looks much nicer... That's how it is done in Java, BTW. (further, 
if you switch an enum in Java, it's an error to precede the enum member 
with the enum name... That's just paraonid!... but it always looks cleaner).


More information about the Digitalmars-d-bugs mailing list