diff options
author | Timothee Cour <timothee.cour2@gmail.com> | 2021-02-23 11:25:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-23 20:25:35 +0100 |
commit | c274e67198e446f07708c0a14751da3b2832cec9 (patch) | |
tree | 2fb9dcbe5b56f8f71a55af2856033e38565e76e2 /lib/system/iterators.nim | |
parent | 74a8f23801316cd9e5b7ea072bf0c8c0465b0626 (diff) | |
download | Nim-c274e67198e446f07708c0a14751da3b2832cec9.tar.gz |
add enumutils.items for sparse enums, typetraits.SomeSparseEnum (#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
Diffstat (limited to 'lib/system/iterators.nim')
-rw-r--r-- | lib/system/iterators.nim | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/system/iterators.nim b/lib/system/iterators.nim index 504695bf6..7f0076a44 100644 --- a/lib/system/iterators.nim +++ b/lib/system/iterators.nim @@ -82,8 +82,13 @@ iterator mitems*(a: var cstring): var char {.inline.} = yield a[i] inc(i) -iterator items*[T: enum](E: typedesc[T]): T = - ## Iterates over the values of the enum ``E``. +iterator items*[T: enum and Ordinal](E: typedesc[T]): T = + ## Iterates over the values of `E`. + ## See also `enumutils.items` for enums with holes. + runnableExamples: + type Goo = enum g0 = 2, g1, g2 + from std/sequtils import toSeq + assert Goo.toSeq == [g0, g1, g2] for v in low(E) .. high(E): yield v |