Implicit enum conversions are a stupid PITA

Regan Heath regan at netmail.co.nz
Wed Mar 24 07:07:00 PDT 2010


bearophile wrote:
> Regan Heath:
>> I find being able to define bit flag values with an enum and
>> combine them using | and |= or negate with &= ~flag etc very
>> useful.
> 
> The cause of the problem here is that you are trying to use enums for
> a different purpose, as composable flags. In C# enums and flags are
> not the same thing, you can use the [Flags] attribute: 
> http://www.codeguru.com/vb/sample_chapter/article.php/c12963 The
> ridiculous thing of D development is that no one ever takes a look at
> C#, it often already contains a solution to problems we are just
> starting to find in D (or often that we just refuse to see in D). As
> they say: "Those who cannot learn from C# are doomed to re-invent it,
> often badly."

Thanks, I haven't used the flags attribute in C# before.  It is like the 
"numeric base type" suggestion I made, in that it causes an alternate 
set of behaviour for 'enum'.  I was hoping there was some way to get 
what we want without extra syntax.

> (In D you can solve this problem creating a flags struct, using a
> strategy similar to the one used by std.bitmanip.bitfields, but it
> feels hackish).

I've not used that (it's been a while since I used D for anything 
practical) but it seems like it's not quite what we want, we really want 
a set of compile time constants.

R



More information about the Digitalmars-d mailing list