Reducing code duplication while defining a commutative operation
问题 I have a a set of overloads of a commutative binary function named overlap , which accepts two distinct types: class A a; class B b; bool overlap(A, B); bool overlap(B, A); My function overlap returns true if and only if one shape overlaps the other - this is one common example used when discussing multimethods. Because overlap(a, b) is equivalent to overlap(b, a) , I only need to implement one "side" of the relation. One repetitive solution is to write something like this: bool overlap(A a,