add typetraits.OrdinalEnum, enumutils.symbolName (#17281)

This commit is contained in:
Timothee Cour 2021-03-10 08:08:24 -08:00 • committed by GitHub
commit eb07a5a75b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 9 deletions

View file

@ -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.