digitalmars.D.bugs - [Issue 24540] New: Add order/index to enum member to return its
- d-bugmail puremagic.com (44/44) May 06 https://issues.dlang.org/show_bug.cgi?id=24540
https://issues.dlang.org/show_bug.cgi?id=24540 Issue ID: 24540 Summary: Add order/index to enum member to return its position Product: D Version: D2 Hardware: All OS: All Status: NEW Severity: enhancement Priority: P1 Component: dmd Assignee: nobody puremagic.com Reporter: apz28 hotmail.com Currently to get the order/index of an enum member to be done in loop which is slow. Provide such member will speedup the lookup enum Foo { one=100, // First order/index=0 two=399, // Next is 1 ... } auto checkingMember = Foo.two; size_t index; foreach (e; EnumMembers!Foo) { if (e == checkingMember) return index; index++; } One of the use case is provide a set of Foo using ubyte/ushort/uint/ulong struct Set(E) { void set(Foo e) { v |= 1 << e.order; } bool isSet(Foo e) { return (v & (1 << e.order)) != 0; } More...functions uint v; } --
May 06