Implicit enum conversions are a stupid PITA

Lutger lutger.blijdestijn at gmail.com
Mon Mar 29 11:56:08 PDT 2010


Lutger wrote:

...

> struct Flags(string members, T = uint)
> {
>     static assert( is(T : ulong), "Wrong underlying type of Flags: must be
> integral not " ~ T.stringof );
> 
>     mixin( genFlags(members) );

I screwed up of course, this must be:

mixin( genFlags(members, T.stringof) );


>     alias typeof(this) FlagsType;
> 
>     T value;
>     alias value this;
> 
>     this(T value)
>     {
>         this.value = value;
>     }
> 
>     void opAssign(T value)
>     {
>         this.value = value;
>     }
> 
>     pure bool opBinaryRight(string op, E)(E lhs)  const
>         if ( op == "in" )
>     {
>         return cast(bool)(lhs & this);
>     }
> }
...



More information about the Digitalmars-d mailing list