Design of reflective enums

Michiel nomail at please.com
Mon Feb 19 07:33:48 PST 2007


renoX wrote:

> Hello,
> Kevin Bealer has started an implementation (two implementations in fact!) of reflective enums, and I wanted to discuss the use case and the design of this feature to make it as useful as possible.
> Reflective enums have two useful properties that don't have normal enums:
> - their label is printable
> - it's possible to do a foreach on all the possible values.

What about this one:

- it's possible to do a slice and get a new enum with a subset of the
original enum values (and labels)

You could do something like this:

enum Weekday {MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY,
SUNDAY}

foreach (day; Weekday[MONDAY..FRIDAY]) { ... }

-- 
Michiel



More information about the Digitalmars-d mailing list