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
This commit is contained in:
parent
74a8f23801
commit
c274e67198
6 changed files with 58 additions and 6 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue