Re: Can I check if a value is convertible to a valid value of an enum?

2015-09-25 Thread Meta via Digitalmars-d-learn
On Friday, 25 September 2015 at 03:20:24 UTC, Nicholas Wilson wrote: find + EnumMembers should do the trick if ( (EnumMembers!SomeType).canFind(value)) { // ... } Should be if (only(EnumMembers!SomeType).canFind(value)) { //... }

Re: Can I check if a value is convertible to a valid value of an enum?

2015-09-24 Thread thedeemon via Digitalmars-d-learn
On Friday, 25 September 2015 at 03:12:20 UTC, French Football wrote: ...without having to loop over the enum? writeln( test( valid_value ) ); //prints true Since `value` is known only at run time, some checks need to be performed at run time anyway. One way of doing it without iterating

Can I check if a value is convertible to a valid value of an enum?

2015-09-24 Thread French Football via Digitalmars-d-learn
...without having to loop over the enum? enum SomeType : string { CHEESE = "cheese", POTATO = "potato" } string valid_value = "cheese"; string invalid_value = "pizza"; bool test( string value ){ if( value.isConvertableToSomeType ){ // this be the magic I seek //do something

Re: Can I check if a value is convertible to a valid value of an enum?

2015-09-24 Thread Nicholas Wilson via Digitalmars-d-learn
On Friday, 25 September 2015 at 03:12:20 UTC, French Football wrote: ...without having to loop over the enum? enum SomeType : string { CHEESE = "cheese", POTATO = "potato" } string valid_value = "cheese"; string invalid_value = "pizza"; bool test( string value ){ if(