www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 13940] New: std.algorithm.argMin

https://issues.dlang.org/show_bug.cgi?id=13940

          Issue ID: 13940
           Summary: std.algorithm.argMin
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: Phobos
          Assignee: nobody puremagic.com
          Reporter: peter.alexander.au gmail.com

I've often needed this function (and added it really early on to my utilities
library)

auto argMin(alias f, alias pred = "a < b", InputRange)(InputRange arg)
{
    assert(!arg.empty);
    return arg.minPos!((a, b) => binaryFun!pred(f(a), f(b))).front;
}

Ideally the implementation would cache the evaluation of f(x) so that it is
only evaluated once per element.

http://en.wikipedia.org/wiki/Arg_max

--
Jan 05 2015