Re: switch with enum

2015-11-30 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/25/15 12:17 AM, tcak wrote: On Wednesday, 25 November 2015 at 03:59:01 UTC, Steven Schveighoffer wrote: On 11/24/15 10:51 PM, tcak wrote: I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum

Re: switch with enum

2015-11-25 Thread Adam D. Ruppe via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 21:26:09 UTC, Meta wrote: Since when? A long time, at least with the -w switch turned on when compiling.

Re: switch with enum

2015-11-25 Thread Anon via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 21:26:09 UTC, Meta wrote: On Wednesday, 25 November 2015 at 20:47:35 UTC, anonymous wrote: Use `final switch`. Ordinary `switch`es need an explicit default case. `final switch`es have to cover all possibilities individually. Implicit default cases are not allow

Re: switch with enum

2015-11-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 20:47:35 UTC, anonymous wrote: Use `final switch`. Ordinary `switch`es need an explicit default case. `final switch`es have to cover all possibilities individually. Implicit default cases are not allowed. Ordinary `switch`es need an explicit default case Si

Re: switch with enum

2015-11-25 Thread anonymous via Digitalmars-d-learn
On 25.11.2015 21:06, Meta wrote: ...Which doesn't work because it won't compile without a default case. Is this a recent change? I don't remember D doing this before. Use `final switch`. Ordinary `switch`es need an explicit default case. `final switch`es have to cover all possibilities individ

Re: switch with enum

2015-11-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 20:00:01 UTC, Meta wrote: One way you could do it: import std.conv: to; try { switch (userValue.to!Status) { ... } } catch (ConvException c) { //Default case } ...Which doesn't work because it won't compile without a default case. Is

Re: switch with enum

2015-11-25 Thread Meta via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 03:51:48 UTC, tcak wrote: I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum Status: ubyte{ Busy = 1, Active = 2 } and received a ubyte value from user. ubyt

Re: switch with enum

2015-11-24 Thread tcak via Digitalmars-d-learn
On Wednesday, 25 November 2015 at 03:59:01 UTC, Steven Schveighoffer wrote: On 11/24/15 10:51 PM, tcak wrote: I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum Status: ubyte{ Busy = 1, Acti

Re: switch with enum

2015-11-24 Thread Steven Schveighoffer via Digitalmars-d-learn
On 11/24/15 10:51 PM, tcak wrote: I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum Status: ubyte{ Busy = 1, Active = 2 } and received a ubyte value from user. ubyte userValue; I want to s

switch with enum

2015-11-24 Thread tcak via Digitalmars-d-learn
I have seen a code a while ago, but even by looking at documentation, I couldn't have found anything about it. Let's say I have defined an enum; enum Status: ubyte{ Busy = 1, Active = 2 } and received a ubyte value from user. ubyte userValue; I want to switch over userValue, but that shoul