-
Notifications
You must be signed in to change notification settings - Fork 18
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 enum utilities and add enum with holes support #115
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR doesn't work when used with other types than int
Eg, 5.byte in SomeEnum
Also, since hasHoles
is used in contains
, put hasHoles
first (it's causing issues in some cases currently)
stew/objects.nim
Outdated
if v > int.high.uint64: | ||
return false | ||
when e.hasHoles(): | ||
v.int64 in enumRangeOrd(e).mapIt(it.int64) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using mapIt
here would be a bit inefficient as it would allocate a sequence just to perform the check. It would be better to directly produce an int64
array in enumRangeOrd
.
Add one macro and one procedure:
Creates an array with all the ordinal value of an enum (sorted by default from what I saw)
With the macro described above, it checks if an integer is in the enum, in order to use someInt in / notin RandomEnum
In addition to that, I use those two macro/proc to implement the hole management in the macro hasHoles and the proc checkEnumAssign