[Issue 13940] New: std.algorithm.argMin
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Mon Jan 5 12:25:55 PST 2015
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 at puremagic.com
Reporter: peter.alexander.au at 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
--
More information about the Digitalmars-d-bugs
mailing list