Getting enum from value

Temtaime via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Aug 5 09:48:33 PDT 2017


On Saturday, 5 August 2017 at 15:42:53 UTC, Rene Zwanenburg wrote:
> On Saturday, 5 August 2017 at 15:33:57 UTC, Matthew Remmel 
> wrote:
>> Any ideas?
>
> You can use to! in std.conv:
>
>
> import std.stdio;
> import std.conv;
>
> enum Foo
> {
> 	A = "A",
> 	B = "B"
> }
>
> void main()
> {
> 	writeln("A".to!Foo);	
> }

Are you fools ?
Did you ever read the post ?

I think this is a minimal solution:

enum Foo
{
	A = "AV",
	B = "BV",
	C = "CV",
}

Foo K = [ EnumMembers!Foo ].find!(a => a == `BV`)[0];


More information about the Digitalmars-d-learn mailing list