Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 12:40 AM, Mathias LANG wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/18/21 6:35 AM, Johan wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash

Re: semi-final switch?

2021-06-18 Thread Steven Schveighoffer via Digitalmars-d-learn
On 6/17/21 5:54 PM, H. S. Teoh wrote: On Thu, Jun 17, 2021 at 05:41:28PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [.[..] Oh, and to throw a monkey wrench in here, the value is a string, not an integer. So I can't use std.conv.to to verify the enum is valid (plus, then I'm runn

Re: semi-final switch?

2021-06-18 Thread Johan via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash the program if the incoming value

Re: semi-final switch?

2021-06-17 Thread jfondren via Digitalmars-d-learn
On Friday, 18 June 2021 at 04:24:19 UTC, jfondren wrote: On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. ... Oh, and to throw a monkey wrench in here, the value is a string

Re: semi-final switch?

2021-06-17 Thread Mathias LANG via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the d

Re: semi-final switch?

2021-06-17 Thread jfondren via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. ... Oh, and to throw a monkey wrench in here, the value is a string, not an integer. So I can't use std.conv.to to verify th

Re: semi-final switch?

2021-06-17 Thread Dennis via Digitalmars-d-learn
On Thursday, 17 June 2021 at 21:41:28 UTC, Steven Schveighoffer wrote: Any ideas on better ways to handle this? I've had such a situation before too where I want to switch over enums I read from an ELF file which can't be assumed to be correct, but I also don't want to forget one. For a tight

Re: semi-final switch?

2021-06-17 Thread H. S. Teoh via Digitalmars-d-learn
On Thu, Jun 17, 2021 at 05:41:28PM -0400, Steven Schveighoffer via Digitalmars-d-learn wrote: [.[..] > Oh, and to throw a monkey wrench in here, the value is a string, not > an integer. So I can't use std.conv.to to verify the enum is valid > (plus, then I'm running a switch twice). > > Any ideas

semi-final switch?

2021-06-17 Thread Steven Schveighoffer via Digitalmars-d-learn
A final switch on an enum complains if you don't handle all the enum's cases. I like this feature. However, sometimes the data I'm switching on is coming from elsewhere (i.e. a user), and while I want to enforce that the data is valid (it's one of the enum values), I don't want to crash the pr