I'd like to be able to compare two typedesc in a template to see if they're referencing the same type (or at least have the same type name) but am not sure how. The ==
operator doesn't allow this.
type
Foo = object
Bar = object
template test(a, b: expr): bool =
a == b
echo test(Foo, Foo)
echo test(Foo, Bar)
It gives me this:
Error: type mismatch: got (typedesc[Foo], typedesc[Foo])
How can this be done?
The is
operator helps: 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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With