On Sunday, 22 July 2012 at 21:10:08 UTC, Andrei Alexandrescu wrote:
On 7/22/12 12:32 PM, David Nadlinger wrote:
On Sunday, 22 July 2012 at 03:06:28 UTC, Jens Mueller wrote:
Where is argmin defined? I couldn't find it.

On the slide before that… ;)

I think argmin is intuitive, popular, and useful enough to warrant a presence in std.algorithm. Would anyone want to do the honors?


Thanks,

Andrei

Are you asking for the _actual_ argmin as defined in the paper?

Because I think it would be much better if we provided an overload for the existing minPos/minRange to accept a unary pred:

----
Range minPos(alias pred, Range)(Range range)
  if (is(typeof(unaryFun!pred(range.front))))
{
  ...
}
----
Tuple!(ElementType!(Range), size_t)
minCount(alias pred, Range)(Range range)
  if (is(typeof(unaryFun!pred(range.front))))
{
  ...
}
----

Where pred if the unary weight function. This code would then work as such:

----
auto m = s.minPos!((x) => x.length).front;
----
auto m = s.minCount!((x) => x.length)[1];
----

Both versions require an extra .front/[1], but that's because that's just how the algorithms work.

I actually _just_ rewrote these two methods (they are in my pull requests). I'm on it if you you like the idea of being able to call these functions with a unary predicated (I do): It sure beats writing "(a, b) => pred(a) < pred(b)" when you could just write "a => pred(a)"

Reply via email to