Summary: Add .length field to enums or provide helper function
                    to Phobos
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: trivial
          Priority: P2
         Component: DMD

--- Comment #0 from Andrej Mitrovic <> 2012-05-01 
13:44:17 PDT ---
My use-case:

enum Foo

enum Bar : Foo
    x = Foo.x,
    y = Foo.y,
    z = Foo.z

I really want to ensure that when I update Foo I will be forced to update Bar
(IOW get a compile-time error). If enums had a .length property then I could
easily add a static assert:

static assert(Foo.length == Bar.length);

As a workaround (if the proposal is rejected), we might add this template to

template EnumLength(E)
    if (is(E == enum))
    enum EnumLength = [__traits(allMembers, E)].length;

Used like so:
static assert(EnumLength!Foo == EnumLength!Bar);

I'd prefer having .length over instantiating templates, but either is fine for

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to