<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div>To me it seems like a future direction of the property behavior proposal.</div><div>There could be a behavior like "pointerEquatable" which is used as a transparent wrapper:</div><div><br></div><div> bahavior <span style="background-color: rgba(255, 255, 255, 0);">pointerEquatable<Value: AnyObject> : Hashable {</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var value: Value</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> var hashValue: Int {</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> // hash value from pointer</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> // omitting get/set</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> func == <T>(p1: pointerEquatable<T>, p2: pointerEquatable<T>) -> Bool {</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> return p1.value === p2.value</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> }</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> // possible usage</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"> let set: Set<pointerEquatable<MyClass>> = [MyClass(), MyClass()]</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">This solution could then be used for any type not only Sets.</span></div><div><span style="background-color: rgba(255, 255, 255, 0);"><br></span></div><div><span style="background-color: rgba(255, 255, 255, 0);">Best regards</span></div><div><span style="background-color: rgba(255, 255, 255, 0);">- Maximilian</span></div><div><br>Am 18.02.2016 um 23:58 schrieb Jacob Bandes-Storch via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>>:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div>Would it make sense for the standard library Set to provide variants (or parallel versions of the same data structure) that take custom hashValue/== implementations at init time (functions taking in Elements), rather than relying on Hashable/Comparable protocols?</div><div><br></div><div>Use case: I want a set of objects that are compared for equality using === rather than ==. This doesn't seem possible today, using Set, without creating some sort of wrapper object.</div><div><br></div><div>This particular case would be analogous to using NSHashTable with NSPointerFunctionsObjectPointerPersonality. (Maybe all I'm asking for is a Swiftier API for NSHashTable — including ArrayLiteralConvertible, using generics instead of UnsafePointer<Void>, etc.)</div><div><br></div><div>Similarly, C++'s <a href="http://en.cppreference.com/w/cpp/container/unordered_map">unordered_map</a> and friends have template parameters specifying the hash function and equality comparator, which use std::hash and == by default.</div><div><br></div><div>(Apologies if this has been discussed already; I haven't seen it.)<br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
</div></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>