Bug 5099 – Add enum size property

Status
RESOLVED
Resolution
DUPLICATE
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Windows
Creation time
2010-10-22T02:04:00Z
Last change time
2014-03-19T03:56:09Z
Assigned to
nobody
Creator
ah08010-d

Comments

Comment #0 by ah08010-d — 2010-10-22T02:04:03Z
Presently, enums support these properties: .init = lexically-first member value .min = smallest value .max = largest value .sizeof = size of underlying storage type I propose adding another property, .length The value would be the array-declaration-friendly number of elements in the enum. Thus, enum E { A, B, C }; int[ E.length ] counters; // int[3] There is always the possibility that enum values would be declared as duplicates of each other: enum F { A = 0, B, C = 0 }; In that case, .length would _still_ return 3, because it's defined at the number, not the number(unique) or anything. (And because not all enumerated types will supported ==).
Comment #1 by bearophile_hugs — 2010-10-22T03:38:48Z
See bug 4997
Comment #2 by lt.infiltrator — 2014-03-19T03:56:09Z
*** This issue has been marked as a duplicate of issue 4997 ***