如何从复合对象或派生对象的祖先中获取类型?
例如,如何从以下参数中获取
string
?
proc MyProc(theArg: HashSet[string, int]) =
var innerKey: typeof(theArg)[0] # trying to get string from theArg
var innerVal: typeof(theArg)[1] # trying to get int from theArg
...
上面的例子很愚蠢,因为我已经输入了
string
和 int
。
真实的情况更接近这样:
type
SomeEnum = enum Up, Down, Left, Right, Sideways`
MyKeyType = string
MyValType = SomeEnum
BigTable = HashSet[MyKeyType, MyValType]
proc MyProc(table: BigTable): =
var innerKey: ...? # find the key type of BigTable
var innerVal: ...? # find the val type of BigTable
var someThing: ...? # find the ancestor or root+1 ancestor of MyValType, ie SomeEnum (not RootObj)
...