Implicit enum conversions are a stupid PITA
bearophile
bearophileHUGS at lycos.com
Wed Mar 24 06:28:19 PDT 2010
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."
(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).
Bye,
bearophile
More information about the Digitalmars-d
mailing list