std/enumutils (original) (raw)

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 a0 = -3 a1 = 10 a2 a3 = (20, "f3Alt") B = enum b0 b1 b2 C = enum 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