-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add type().length for enums #11469

Comments

Why |
Min / Max would work just fine I guess. |
@Amxx could you please explain a bit more how you would use this feature and why the current set of features is not sufficient? |
If it's |
Actually I just checked and the enum values are indeed |
We did discuss during the meeting, that potentially a more generic solution following #11284 is to have something akin to Rust's "try_convert". That would return a boolean in case of failure, unlike the compiler generated error we have on out-of-bounds int to enum casting today. |
I don't like justifying with my particular usecase, because I always have the feeling the my usecase is just one of many cases, and not necessarily the best one. Also, this doesn't allow to do anything that was impossible before. It just helps (just like That being said, here is an idea of a library. It defines a structure that is holding arbitrary values, but has a few "reserved values" at the beginning of the rang. In my case the arbitrary values are timestamp, so no realistic risk of clash
As you can see, I have a mechanism to check if the value is reserved or not, by comparing it to the length. To get the length, my trick is to add a |
@axic any results on finding a more generic solution? We could just add |
We decided in the call that we will implement this a min/max. |
Apart from #11469 (comment), no. At the time we handle conversion changes, that will be a larger breaking release, and it would be possible to drop |
Abstract
Add a mechanism to get the number of entries in an Enum using the enum's name
Motivation
There is already a mechanism to get
type().min
andtype().max
for integers types. In some cases it might be necessary to check if auint
does match an enum without reverting (casting will revert of not within limits)Specification
type(MyEnum).length
should returns auin8
Alternative
An alternative would be to have
type(MyEnum).min
andtype(MyEnum).max
supported..min
would always return 0.max
would return the lengthBackwards Compatibility
N/A
The text was updated successfully, but these errors were encountered: