<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Feb 18, 2016, at 16:09 , Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><br style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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=""><span style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">on Thu Feb 18 2016, Jacob Bandes-Storch &lt;</span><a href="mailto:swift-evolution@swift.org" style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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="">swift-evolution@swift.org</a><span style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">&gt; wrote:</span><br style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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=""><br style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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=""><blockquote type="cite" style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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="">Would it make sense for the standard library Set to provide variants (or<br class="">parallel versions of the same data structure) that take custom hashValue/==<br class="">implementations at init time (functions taking in Elements), rather than<br class="">relying on Hashable/Comparable protocols?<br class=""><br class="">Use case: I want a set of objects that are compared for equality using ===<br class="">rather than ==. This doesn't seem possible today, using Set, without<br class="">creating some sort of wrapper object.<br class=""><br class="">This particular case would be analogous to using NSHashTable with<br class="">NSPointerFunctionsObjectPointerPersonality. (Maybe all I'm asking for is a<br class="">Swiftier API for NSHashTable — including ArrayLiteralConvertible, using<br class="">generics instead of UnsafePointer&lt;Void&gt;, etc.)<br class=""><br class="">Similarly, C++'s unordered_map<br class="">&lt;<a href="http://en.cppreference.com/w/cpp/container/unordered_map" class="">http://en.cppreference.com/w/cpp/container/unordered_map</a>&gt; and friends have<br class="">template parameters specifying the hash function and equality comparator,<br class="">which use std::hash and == by default.<br class=""></blockquote><br style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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=""><span style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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; float: none; display: inline !important;" class="">It might make sense. &nbsp;How bad is the wrapper solution for user code?</span><br style="font-family: Monaco; font-size: 11px; font-style: normal; font-variant-caps: 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></blockquote></div><br class=""><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div class="">struct CustomHashableFoo: Hashable {</div><div class="">&nbsp; var value: Foo</div><div class="">&nbsp; func hash() -&gt; Int {</div><div class="">&nbsp; &nbsp; // custom hash function here</div><div class="">&nbsp; }</div><div class="">}</div><div class="">func ==(a: CustomHashableWrapped, b: CustomHashableWrapped) {</div><div class="">&nbsp; // custom == here</div><div class="">}</div></blockquote><br class=""><div class="">Really not that bad, although you do have to get 'value' in and out of the box. It's also not reusable code—you have to rewrite the box for every type.</div><div class=""><br class=""></div><div class="">I'd say you usually <i class="">don't</i>&nbsp;want to allow custom hash/== closures because (a) then you have to store them somewhere, and (b) the compiler won't usually be able to inline them away. You also end up with a Set&lt;Foo&gt; that doesn't behave like a normal Set&lt;Foo&gt;—maybe you can insert equal-but-not-identical elements—which is bad if anyone's relying on normal Set-like guarantees.</div><div class=""><br class=""></div><div class="">-1 from me until we can put functions in generics, if ever.</div><div class=""><br class=""></div><div class="">Jordan</div></body></html>