enum

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Wed Apr 9 11:05:19 PDT 2014


On 4/9/14, 10:17 AM, Meta wrote:
> 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.

That was for C++, and a function vs. a cast didn't improve the 
experience much. -- Andrei



More information about the Digitalmars-d mailing list