Implicit enum conversions are a stupid PITA
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sun Mar 28 16:16:35 PDT 2010
On 03/28/2010 06:03 PM, bearophile wrote:
>> The construct defines at compile-time a property for each given name.<
>
> A costant (enum) not a property, sorry.
>
> So this:
> alias Flags!q{ A, B, C } Foo;
>
> Becomes equivalent to:
>
> struct Foo {
> enum uint A = 1<< 0;
> enum uint B = 1<< 1;
> enum uint C = 1<< 2;
>
> private uint _data;
>
> // operators defined here, with full input tests:
> // = == | |= in& &= opBool
> ...
> }
>
>
> Foo f = Foo.A | Foo.B;
> Now f._data contains the or of the two flags...
>
> Bye,
> bearophile
Yah but let's say A|B is used very often so I want to call it AB. How do
I specify in the definition of Flags such a definition? I guess
alias Flags!q{ A, B, C, AB = A|B } Foo;
which makes parsing rather difficult.
Andrei
More information about the Digitalmars-d
mailing list