bearophile , dans le message (digitalmars.D:144550), a écrit :
> Christophe:
> 
>> sort does not use a Schwartzian transformation, although is preferable 
>> in many cases in term of efficiency: it uses a less predicate, because 
>> it has been decided that it is what the user expects, am I right? If you 
>> want to use a Schwartian transformation, you use schwartzSort.
> 
> I didn't agree with that design decision of Phobos, I think I said 
> this to Andrei too. schwartzSort is a very handy sort, I don't like it 
> buried by such long (and for me hard to write name, I am never able to 
> remember its spelling). In Python3 the built-in sort is a 
> schwartzSort.
> 
> Beside the name, I think D schwartzSort needs an improvement, because 
> currently you can't give it a function like q{ a.foo }, you have to 
> use a longer lambda like (Foo a){ return a.foo; }.


Hum, then schwartzSort could be simply called sort, since there is no 
way the two sort function could be mistaken*.

Actually the compiler could accept both sort function with a string 
template argument under the same name. sort!string(range) could check if 
unaryFun!string compiles, or if binaryFun!string compiles and returns a 
bool, and decide which sort algorithm to use. There is no possible 
confusion, unless someone has the crazy idea of using a schwartzian 
transformation that returns a bool.

*What is questionable is whether sort!unaryFun should allocate 
the transformed data of the whole range in any case, because it may not 
be optimal. Anyway, that does not apply to max!unaryFun.


-- 
Christophe

Reply via email to