add typetraits.OrdinalEnum, enumutils.symbolName (#17281)
This commit is contained in:
parent
3dc1bd0d09
commit
eb07a5a75b
4 changed files with 57 additions and 9 deletions
|
|
@ -15,16 +15,20 @@
|
|||
import std/private/since
|
||||
export system.`$` # for backward compatibility
|
||||
|
||||
type SomeEnumWithHoles* = (not Ordinal) and enum ## Enum with holes.
|
||||
type HoleyEnum* = (not Ordinal) and enum ## Enum with holes.
|
||||
type OrdinalEnum* = Ordinal and enum ## Enum without 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
|
||||
assert A is enum
|
||||
assert A is HoleyEnum
|
||||
assert A isnot OrdinalEnum
|
||||
assert B isnot HoleyEnum
|
||||
assert B is OrdinalEnum
|
||||
assert int isnot HoleyEnum
|
||||
type C[T] = enum h0 = 2, h1 = 4
|
||||
assert C[float] is SomeEnumWithHoles
|
||||
assert C[float] is HoleyEnum
|
||||
|
||||
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