D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 5099 - Add enum size property
Summary: Add enum size property
Status: RESOLVED DUPLICATE of issue 4997
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 enhancement
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-10-22 02:04 UTC by Austin Hastings
Modified: 2014-03-19 03:56 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Austin Hastings 2010-10-22 02:04:03 UTC
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 bearophile_hugs 2010-10-22 03:38:48 UTC
See bug 4997
Comment 2 Infiltrator 2014-03-19 03:56:09 UTC

*** This issue has been marked as a duplicate of issue 4997 ***