How to implement the following simple comparison function

I would like to implement the following simple function, but I cannot find an alternative for AnyType (interface?) that defines comparison operators. In the following code a __ne__ is needed for ai != bi. It's as if I'm missing a manual. If someone knows how to do this, or knows how to make me cope that is cannot be done...
fn equal_vector[T: AnyType](a: DynamicVector[T], b: DynamicVector[T]) -> Bool:
# assumed a and b are sorted
if a.__len__() != b.__len__():
return False
for i in range (a.__len__()):
let ai: T = a.__getitem__(i)
let bi: T = b.__getitem__(i)
if ai != bi: ## compilation error HERE
return False
return True
fn equal_vector[T: AnyType](a: DynamicVector[T], b: DynamicVector[T]) -> Bool:
# assumed a and b are sorted
if a.__len__() != b.__len__():
return False
for i in range (a.__len__()):
let ai: T = a.__getitem__(i)
let bi: T = b.__getitem__(i)
if ai != bi: ## compilation error HERE
return False
return True
2 Replies
gabrieldemarmiesse
I think that since traits are not there yet, you have to do if not ai.__eq__(bi) or something like that
Henk-Jan Lebbink
Henk-Jan LebbinkOP13mo ago
Thanx for idea. I guess we would need to wait for traits, bacause AnyType do not define __eq__. Fix: don't use Vector. I've replaced it with A Tensor that does implement equality op.
Want results from more Discord servers?
Add your server