by Bootvis · 8y ago · 0 comments
class Equal {
public:
template <typename T>
bool operator==(const T& eq) { return true; };
All kinds of equality are possible. class a {};
multi sub infix:<==> (a $a, $b) {
True
}
if a == 1 && a == 2 && a == 3 {
say "true!"
}
If you wanted to make an actual iterator out of `a`, you could do: multi sub infix:<==> (a $a, $b) {
++(state $) == $b
}
In that case, `a` would equal 1, 2, and 3 in that order. 5 is right out. my \a = any(1, 2, 3);
if ( a == 1 && a == 2 && a == 3 ) {
say "OMG quantum superposition!!!";
}
For those wondering what's going on: https://docs.perl6.org/type/Junction.html :-) class A {
public static bool operator ==(A a, int b) => true;
public static bool operator !=(A a, int b) => false;
}
var a = new A();
if (a == 1 && a == 2 && a == 3) Console.WriteLine("This works");