enum

Meta jared771 at gmail.com
Wed Apr 9 10:17:54 PDT 2014


On Wednesday, 9 April 2014 at 16:47:18 UTC, Andrei Alexandrescu 
wrote:
> Very true. In hhvm, we tried an enum class to avoid bugs with 
> using wrong indices in a couple of specific arrays. There were 
> so many darned casts around, we had to revert the change.


There are many ways to get around this, such as user-defined 
function or template, or a built-in .valueOf property.

template ValueOf(alias E)
if (is(typeof(E) == enum))
{
	import std.traits: OriginalType;
	
	enum OriginalType!(typeof(E)) ValueOf = E;
}

You can call this in a function for use with UFCS.



More information about the Digitalmars-d mailing list