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
|
|
@ -15,6 +15,17 @@
|
|||
import std/private/since
|
||||
export system.`$` # for backward compatibility
|
||||
|
||||
type SomeEnumWithHoles* = (not Ordinal) and enum ## Enum with holes.
|
||||
|
||||
runnableExamples:
|
||||
type A = enum a0 = 2, a1 = 4, a2
|
||||
type B = enum b0 = 2, b1, b2
|
||||
assert A is SomeEnumWithHoles
|
||||
assert B isnot SomeEnumWithHoles
|
||||
assert int isnot SomeEnumWithHoles
|
||||
type C[T] = enum h0 = 2, h1 = 4
|
||||
assert C[float] is SomeEnumWithHoles
|
||||
|
||||
proc name*(t: typedesc): string {.magic: "TypeTrait".} =
|
||||
## Returns the name of the given type.
|
||||
##
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue