<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="">Hi Zhao<div class=""><br class=""></div><div class="">Thanks for your response.</div><div class=""><br class=""></div><div class="">I understand your point, but when using third party classes I don’t know if the hash values are comparable, but for example I may want to have a set of ‘data' (NSData) and a subset of ‘mutable data' (NSMutableData), which point to the same objects. As a user of swift I would expect to be able to subtract Set<NSMutableData> from Set<NSData>.</div><div class=""><br class=""></div><div class="">Your last example perhaps works in Swift 3, so this may be fixed now, but in Swift 2 you get the error</div><div class=""><br class=""></div><div class="">Cannot invoke 'subtract' with an argument list of type '(Set<Bar>)’</div><div class=""><br class=""></div><div class="">Perhaps Swift 3 supports it with some additional safety around hashValue overriding or something.</div><div class=""><br class=""></div><div class="">Thanks<br class=""><div class="">
<br class="Apple-interchange-newline"><span style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; display: inline !important; float: none;" class="">Nick</span><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 1 Sep 2016, at 04:00, Zhao Xin <<a href="mailto:owenzx@gmail.com" class="">owenzx@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="gmail_default" style="font-family:georgia,serif">I don't see the point. For example if an element in Set<B> and another element in Set<A> are with a same hash value. Neither of the elements should be subtracted. As they are in different types. And hash values between different types are not guaranteed to be comparable. </div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">import</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Foundation</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(112, 61, 170);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Foo:</span><span style="font-variant-ligatures:no-common-ligatures" class="">Hashable</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span></div><p 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="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</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><p 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="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">static</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" 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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</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><p 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="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">required</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = value</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;" 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;color:rgb(187,44,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Bar:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">override</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> * </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</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;" 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;color:rgb(187,44,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> foo = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</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;color:rgb(187,44,162)" class="">let</span><span style="font-variant-ligatures:no-common-ligatures" class=""> bar = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</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(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">hashValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// 10</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">bar</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">hashValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// 100</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">((</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">bar</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">as</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures: no-common-ligatures;" class="">).</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">hashValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures" class="">// 100 instead of 10</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(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(49,89,93)" class="">==</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">bar</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures" class="">// true</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">foo</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">hashValue</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> == </span><span style="font-variant-ligatures:no-common-ligatures" class="">bar</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures" class="">hashValue</span><span style="font-variant-ligatures: no-common-ligatures;" class="">) </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(0,132,0)" class="">// false</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">As you can see in the above code, although `foo == bar` is true, `foo.hashValue == bar.hashValue` is not guaranteed to be true. As far as I know, Set<T> uses hash values instead of equations to compare the elements. So the results of a super class and its sub class are not guaranteed. Also, as `(bar as Foo).hashValue` is always the result of its own class, you can't get the results you want through casting.</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> fooSet:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</span><span style="font-variant-ligatures:no-common-ligatures" class=""><</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">7</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;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barSet:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</span><span style="font-variant-ligatures:no-common-ligatures" class=""><</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">7</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">6</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">5</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(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">fooSet</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">subtract</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">barSet</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;color:rgb(79,129,135)" class="">fooSet</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">forEach</span><span style="font-variant-ligatures:no-common-ligatures" class=""> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"</span><span style="font-variant-ligatures:no-common-ligatures" class="">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">type(of:$0)</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">), value:</span><span style="font-variant-ligatures:no-common-ligatures" class="">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">)"</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; color: rgb(0, 132, 0);" 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; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> Foo, value:10</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> Foo, value:9</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> Foo, value:8 // Here is a mystery, Foo(7) is </span>unreasonably missing.</div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo;color:rgb(79,129,135)" class="">
</p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">*/</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">However, if you can guarantee the hash values are comparable, you still can get the results you want.</div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(112, 61, 170);" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">class</span><span style="font-variant-ligatures: no-common-ligatures;" class=""> Foo:</span><span style="font-variant-ligatures:no-common-ligatures" class="">Hashable</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</span></div><p 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="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> hashValue: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</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><p 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="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">public</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">static</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">func</span><span style="font-variant-ligatures:no-common-ligatures" class=""> ==(lhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">, rhs: </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">) -> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" 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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">return</span><span style="font-variant-ligatures:no-common-ligatures" class=""> lhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> == rhs.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</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><p 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="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">required</span><span style="font-variant-ligatures:no-common-ligatures" class=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">init</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">_</span><span style="font-variant-ligatures:no-common-ligatures" class=""> value:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Int</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">self</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures" class=""> = value</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;" 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;color:rgb(187,44,162)" class="">class</span><span style="font-variant-ligatures:no-common-ligatures" class=""> Bar:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</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=""> </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> name = </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"bar"</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;" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><br 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;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> fooSet:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</span><span style="font-variant-ligatures:no-common-ligatures" class=""><</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">10</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">9</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Foo</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">7</span><span style="font-variant-ligatures:no-common-ligatures" class="">)]</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">
</span></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo;" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(187,44,162)" class="">var</span><span style="font-variant-ligatures:no-common-ligatures" class=""> barSet:</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(112,61,170)" class="">Set</span><span style="font-variant-ligatures:no-common-ligatures" class=""><</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">> = [</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">8</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">7</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">6</span><span style="font-variant-ligatures:no-common-ligatures" class="">), </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">Bar</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(39,42,216)" class="">5</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=""><br class=""></span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(79, 129, 135);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">fooSet</span><span style="font-variant-ligatures: no-common-ligatures;" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">subtract</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">barSet</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;color:rgb(79,129,135)" class="">fooSet</span><span style="font-variant-ligatures:no-common-ligatures" class="">.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">forEach</span><span style="font-variant-ligatures:no-common-ligatures" class=""> { </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(61,29,129)" class="">print</span><span style="font-variant-ligatures:no-common-ligatures" class="">(</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">"</span><span style="font-variant-ligatures:no-common-ligatures" class="">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">type(of:$0)</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">), value:</span><span style="font-variant-ligatures:no-common-ligatures" class="">\</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">(</span><span style="font-variant-ligatures:no-common-ligatures" class="">$0.</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(79,129,135)" class="">value</span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(209,47,27)" class="">)"</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; color: rgb(0, 132, 0);" 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; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> Foo, value:10</span></div><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> Foo, value:9</span></div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">
</span></p><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: menlo; color: rgb(0, 132, 0);" class=""><span style="font-variant-ligatures:no-common-ligatures" class="">*/</span></div></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif"><br class=""></div><div class="gmail_default" style="font-family:georgia,serif">Zhaoxin</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Thu, Sep 1, 2016 at 8:31 AM, Nick Brook via swift-users <span dir="ltr" class=""><<a href="mailto:swift-users@swift.org" target="_blank" class="">swift-users@swift.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class="">I have a set, Set<A> and a subset of that, Set<B>, where B: A. I want to subtract Set<B> from Set<A>, but the subtract function signature specifies that the set elements must be the same type (S.Generator.Element == Element). I guess this is because Element is not required to be a class, simply hashable, therefore inheritance is not guaranteed? Is there any way this could be implemented in Set, in an extension, or what would be the most efficient way to perform that operation?<div class=""><br class=""></div><div class="">Thanks<span class="HOEnZb"><font color="#888888" class=""><br class=""><div class="">
<br class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-ligatures: normal; font-variant-position: normal; font-variant-caps: normal; font-variant-numeric: normal; font-variant-alternates: normal; font-variant-east-asian: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; float: none; display: inline !important;" class="">Nick</span></div></font></span></div></div><br class="">______________________________<wbr class="">_________________<br class="">
swift-users mailing list<br class="">
<a href="mailto:swift-users@swift.org" class="">swift-users@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-users" rel="noreferrer" target="_blank" class="">https://lists.swift.org/<wbr class="">mailman/listinfo/swift-users</a><br class="">
<br class=""></blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></body></html>