如何比较模板中的两个 typedesc 是否相等
How to compare two typedesc in a template for equality
我希望能够比较模板中的两个 typedesc 以查看它们是否引用相同的类型(或至少具有相同的类型名称)但我不确定如何比较。 ==
运算符不允许这样做。
type
Foo = object
Bar = object
template test(a, b: expr): bool =
a == b
echo test(Foo, Foo)
echo test(Foo, Bar)
它给了我这个:
Error: type mismatch: got (typedesc[Foo], typedesc[Foo])
如何做到这一点?
is
运算符帮助:http://nim-lang.org/docs/manual.html#generics-is-operator
type
Foo = object
Bar = object
template test(a, b: expr): bool =
#a is b # also true if a is subtype of b
a is b and b is a # only true if actually equal types
echo test(Foo, Foo)
echo test(Foo, Bar)
我希望能够比较模板中的两个 typedesc 以查看它们是否引用相同的类型(或至少具有相同的类型名称)但我不确定如何比较。 ==
运算符不允许这样做。
type
Foo = object
Bar = object
template test(a, b: expr): bool =
a == b
echo test(Foo, Foo)
echo test(Foo, Bar)
它给了我这个:
Error: type mismatch: got (typedesc[Foo], typedesc[Foo])
如何做到这一点?
is
运算符帮助:http://nim-lang.org/docs/manual.html#generics-is-operator
type
Foo = object
Bar = object
template test(a, b: expr): bool =
#a is b # also true if a is subtype of b
a is b and b is a # only true if actually equal types
echo test(Foo, Foo)
echo test(Foo, Bar)