Procs
func symbolName[T: enum](a: T): string
-
Returns the symbol name of an enum.
This uses symbolRank.
Example:
type B = enum b0 = (10, "kb0") b1 = "kb1" b2 let b = B.low assert b.symbolName == "b0" assert $b == "kb0" static: assert B.high.symbolName == "b2" type C = enum # HoleyEnum c0 = -3 c1 = 4 c2 = 20 assert c1.symbolName == "c1"
Source Edit
Templates
template symbolRank[T: enum](a: T): int
-
Returns the index in which a is listed in T.
The cost for a HoleyEnum is implementation defined, currently optimized for small enums, otherwise is O(T.enumLen).
Example:
type A = enum # HoleyEnum a0 = -3 a1 = 10 a2 a3 = (20, "f3Alt") B = enum # OrdinalEnum b0 b1 b2 C = enum # OrdinalEnum c0 = 10 c1 c2 assert a2.symbolRank == 2 assert b2.symbolRank == 2 assert c2.symbolRank == 2 assert c2.ord == 12 assert a2.ord == 11 var invalid = 7.A doAssertRaises(IndexDefect): discard invalid.symbolRank
Source Edit