Add countof(SomeEnum) as a compile-time constant #8906
Unanswered
Entiat
asked this question in
Language Ideas
Replies: 2 comments 15 replies
-
A compile-time constant wouldn't work well if the |
Beta Was this translation helpful? Give feedback.
15 replies
-
This is another case (similar to #8505, |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
(I have zero doubt this has come up before, multiple times, I've searched but no luck - my apologies if the reason this was never implemented is "common knowledge" and I've just missed it)
There is currently no way to determine the count of an enumerated type as a compile-time constant. This means this count cannot be used in many useful scenarios, including default method parameter values, array sizes at compile time, and as attribute parameters.
Workarounds in wide use are klunky and error-prone.
Example of use:
Examples of a couple error-prone workarounds in current common usage:
Or:
Beta Was this translation helpful? Give feedback.
All reactions