<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">The == operator is defined for tuples with (up to 6) elements that conform to the Equatable protocol</div><div class="">(and &lt; for tuples with Comparable elements):</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; class SomeClass: Equatable {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; static public func ==(_ lhs:SomeClass, _ rhs:SomeClass) -&gt; Bool {</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return lhs === rhs</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="">&nbsp; &nbsp; }</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; let c1 = SomeClass()</div><div class="">&nbsp; &nbsp; let c2 = SomeClass()</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; let t1 = ("abc", c1)</div><div class="">&nbsp; &nbsp; let t2 = ("abc", c2)</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; c1 == c2 &nbsp; &nbsp; &nbsp; &nbsp;// legal</div><div class="">&nbsp; &nbsp; t1 == t2 &nbsp; &nbsp; &nbsp; &nbsp;// legal</div><div class=""><br class=""></div><div class="">The existence of a == operator alone, without declaring protocol conformance, is not sufficient.</div><div class=""><br class=""></div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On 9. Jul 2017, at 17:11, David Baraff via swift-users &lt;<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Given 2-tuples of type (T1, T2), you should be able to invoke the == operator if you could on both types T1 and T2, right? &nbsp;i.e.<div class=""><br class=""></div><div class="">(“abc”, 3) == (“abc”, 4)<span class="Apple-tab-span" style="white-space:pre">        </span>// legal</div><div class=""><br class=""></div><div class="">but:</div><div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">class SomeClass {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; static public func ==(_ lhs:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9f35da" class="">SomeClass</span><span style="font-variant-ligatures: no-common-ligatures" class="">, _ rhs:</span><span style="font-variant-ligatures: no-common-ligatures; color: #9f35da" class="">SomeClass</span><span style="font-variant-ligatures: no-common-ligatures" class="">) -&gt; </span><span style="font-variant-ligatures: no-common-ligatures; color: #3495af" class="">Bool</span><span style="font-variant-ligatures: no-common-ligatures" class=""> {</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; &nbsp; &nbsp; return lhs === rhs</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">&nbsp; &nbsp; }</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">}</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">let c1 = </span><span style="font-variant-ligatures: no-common-ligatures; color: #9f35da" class="">SomeClass</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">let c2 = </span><span style="font-variant-ligatures: no-common-ligatures; color: #9f35da" class="">SomeClass</span><span style="font-variant-ligatures: no-common-ligatures" class="">()</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">let t1 = (</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">"abc"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0536ff" class="">c1</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">let t2 = (</span><span style="font-variant-ligatures: no-common-ligatures; color: #b4261a" class="">"abc"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, </span><span style="font-variant-ligatures: no-common-ligatures; color: #0536ff" class="">c2</span><span style="font-variant-ligatures: no-common-ligatures" class="">)</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(5, 54, 255);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">c1</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #9f35da" class="">==</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures: no-common-ligatures" class="">c2<span class="Apple-tab-span" style="white-space:pre">                </span>// legal</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0536ff" class="">t1</span><span style="font-variant-ligatures: no-common-ligatures" class=""> == </span><span style="font-variant-ligatures: no-common-ligatures; color: #0536ff" class="">t2<span class="Apple-tab-span" style="white-space:pre">                </span>// illegal</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #0536ff" class=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></div></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class="">Why is t1 == t2 not legal given that c1 == c2 IS legal?</div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div><div style="margin: 0px; line-height: normal; min-height: 13px;" class=""><br class=""></div></div>_______________________________________________<br class="">swift-users mailing list<br class=""><a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-users<br class=""></div></blockquote></div><br class=""></body></html>