-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 enumutils.items for sparse enums, typetraits.SomeSparseEnum #17080
Conversation
Probably should use |
good point; come to think of it, sparse enum is IMO a better terminology; since we don't yet have API's with |
28f85b2
to
7c8ab28
Compare
2578963
to
88b315c
Compare
PTAL @hlaaftana |
refs #17080 (comment) please vote by adding +1 or -1 reaction to this msg (not the PR itself) as follows:
the rationale for changing terminology is provided here #17080 (comment) and (as i mentioned) isn't a breaking change since no API uses this term yet (until this PR, that is) |
The terminology "enums with holes" is entirely justified: It's precise and does convey the idea that they are defective: You cannot use these enums as array indexes, the code generation for |
88b315c
to
1851237
Compare
PTAL
I've changed it back to enum with holes for the sake of moving on but I would've preferred sparse enum, it's more standard and in the context of enum's conveys the same thing. |
…lang#17080) * add enumutils.items for enum with holes * changelog * ref in lib.rst * use `type SomeSparseEnum* = (not Ordinal) and enum` instead of concept * address comment: rename back to enum with holes
…lang#17080) * add enumutils.items for enum with holes * changelog * ref in lib.rst * use `type SomeSparseEnum* = (not Ordinal) and enum` instead of concept * address comment: rename back to enum with holes
import std/enumutils
type Color = enum Red = 0, Green = 2, Blue = 3
for c in Color.items:
echo c compile output of this code:
isn't |
Enumutils.items should use |
Ping @timotheecour |
that's just a symptom; the root cause is elsewhere, IMO: when true:
type Color = enum Red = 0, Green = 2, Blue = 3
let s = {Red, Green, Blue}
for si in s: echo si also gives this warning, even though it doesn't use std/enumutils (note that enumutils itself creates a set via enumWithHolesFullRange) warning goes away with this diff: diff --git a/lib/system/iterators.nim b/lib/system/iterators.nim
index f23f7aa11..4b82f9235 100644
--- a/lib/system/iterators.nim
+++ b/lib/system/iterators.nim
@@ -51,7 +51,7 @@ iterator items*[T](a: set[T]): T {.inline.} =
## able to hold).
var i = low(T).int
while i <= high(T).int:
- if T(i) in a: yield T(i)
+ if cast[T](i) in a: yield cast[T](i)
inc(i) but TBD whether this is a good diff |
(inspired by
enmRange
in #17066, thanks @beef331 !)future work
genEnumCaseStmt
needs tests and runnableExamplesproc nativeString*(a: enum): string {.compileTime.}
magic proc which would by pass enum string definitions: