<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 Dec 31, 2015, at 8:44 AM, Susan Cheng <<a href="mailto:susan.doggie@gmail.com" class="">susan.doggie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">What's problem of overloading? We only have four methods to do so.<br class=""></div></blockquote><div><br class=""></div>The set of potential algorithms using comparison predicates is not closed, and they will be implemented not only by the standard library but also by third parties. One component gets us the functionality for all those algorithms.</div><div><br class=""><blockquote type="cite" class=""><div class=""><br class="">Dave Abrahams <<a href="mailto:dabrahams@apple.com" class="">dabrahams@apple.com</a>> 於 2016年1月1日星期五 寫道:<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=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 31, 2015, at 4:14 AM, Tino Heth <<a href="javascript:_e(%7B%7D,'cvml','2th@gmx.de');" target="_blank" class="">2th@gmx.de</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><font face="Menlo" class="">func byComparing<T, U: Comparable>(getComparisonKey: (T)->U) -> (T, T) -> Bool {</font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><font face="Menlo" class=""> return { getComparisonKey($0) < getComparisonKey($1) }</font></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><font face="Menlo" class="">}</font></div></div></blockquote></div>I've written something similar to bring file URLs into the order of their creation dates.<div class="">It is a small extension for collection types, and its only downside will disappear as soon as properties are accessible via method calls (afair there is a proposal in the making).</div><div class=""><br class=""></div><div class="">It was quite a lot fiddling with generics, and I don't have the tiny piece of code on my own computer, but it works in a way that you can do</div><div class="">let sorted = array.sortUsingAccessor(ElementType.methodThatReturnsComparable)</div><div class="">Beside the problems with properties, I really liked that approach.</div></div></div></blockquote><div class=""><br class=""></div>This seems to be essentially the same design as Susan’s, and has the same problem: it requires a new overload for every algorithm that takes a comparison predicate.<br class=""></div><br class=""><div class="">
-Dave
</div>
<br class=""></div></blockquote>
</div></blockquote></div><br class=""><div class="">
-Dave
</div>
<br class=""></body></html>