argmax_

version(none)
@safe pure
argmax_
(
alias fun
Range
)
(
in Range r
)
if (
isInputRange!Range &&
is(typeof(fun(r.front) > fun(r.front)) == bool)
)

Return Value

Type: auto

Element in r that maximizes fun. LaTeX: \underset{x}{\arg\max}

Examples

assert(argmax!(x => x*x)([1, 2, 3]) == 3);
assert(argmax!(x => x*x)([3, 2, 1]) == 3);

Meta