using enums for flags

foobar foo at bar.com
Thu Jan 26 07:11:34 PST 2012


On Thursday, 26 January 2012 at 01:44:23 UTC, Marco Leise wrote:
> Delphi: 
> http://delphi.about.com/od/beginners/a/delphi_set_type.htm | 
> Scroll to: "Sets with Enumerations"
> Sets use the smallest integer type that can hold enough bits 
> for the number of elements in an enum. So up to 8 enum flags 
> use a byte for example. TDaySet in the example code would also 
> be 1 byte in size. As the syntax suggests they don't implicitly 
> convert forth or back to integers.

vote += MAX_INT for the above suggestion which btw is also the 
solution in Java 5.0 which provides an EnumSet type. At the 
moment eums are completely broken in D and IMO they are even 
worse that the unsafe C counterparts. C# is a lousy example here 
since its design is only very slightly better than the original C 
semantics.

I suggest looking into the Java implementation of Enum and 
EnumSet types which provides both type safety and convenience.



More information about the Digitalmars-d mailing list