Timon Gehr , dans le message (digitalmars.D:144541), a écrit :
> On 09/15/2011 11:44 AM, Christophe wrote:
>> bearophile , dans le message (digitalmars.D:144513), a écrit :
>>> I'd like to receive some comments from Andrei about one of the most nagging 
>>> problems I have with std.algorithm, it's not a big issue, but I bump my 
>>> nose against it few times every week:
>>>
>>> http://d.puremagic.com/issues/show_bug.cgi?id=4705
>>>
>>> If you have questions or doubts, feel free to ask here or in Bugzilla.
>>>
>>> Bye,
>>> bearophile
>>
>> min and max for ranges are good things to add.
>>
>> If min and max use a callable, it should be a less predicate, and
>> max(item1, item2) should use a predicate too. A max!callable(range) that
>> replaces max(map!collable(range)) is unuseful and confusing, since max
>> should return one of the element passed in its arguments.
>>
>> mins and maxs are too specialized to be in phobos IMO.
>>
> 
> Where do you draw the line? min and max for ranges are just reduce!min 
> and reduce!max.

Well, max(item1, item2) is just item1>item2?item1:item2 ...
A line has to be drawn somewhere, depending of what people expect from 
a standard library. Then I'm just giving my opinion, depending on what I 
think people expect in a std library (which is biaised by what I expect 
from a std library...).

What you say is true, and is an acceptable argument in favor of not 
including max for ranges. However:
-min and max having been implemented in phobos for more that 2 arguments
-the effect of min and max on ranges is obvious, so anyone implementing 
this function will implement it the same way, why not do it in phobos ?

> What is "unuseful and confusing" about:
> 
> max!"a.length"(range); ?

What is confusing is that I don't know if this function returns a 
length, or one of the elements of the range.

max compares elements two at a time and returns one of them. It seems 
(to me) more natural to give it a predicate to compare elements two at a 
time. This is what is used in c++ std lib. "less" predicates are very 
common in a std lib, so they should not surprise the user much.

max!"a.length<b.length"(range);

If that is too much of a surprise, then max should not take a callable.

-- 
Christophe

Reply via email to