semi-final switch?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 17 21:54:07 UTC 2021


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 on better ways to handle this?
[...]

Why not just:

	try {
		MyEnum value = input.to!MyEnum;
	} catch (Exception e) {
		stderr.writeln("Invalid input");
	}

?


T

-- 
People demand freedom of speech to make up for the freedom of thought which they avoid. -- Soren Aabye Kierkegaard (1813-1855)


More information about the Digitalmars-d-learn mailing list