maxElement

fnauto maxElement(alias map = (a => a), Range)(Range r) if (isInputRange!Range && !isInfinite!Range)

Iterates the passed range and returns the maximal element. A custom mapping function can be passed to map. In other languages this is sometimes called argmax.

Complexity: O(n) Exactly n - 1 comparisons are needed.

Parameters

mapcustom accessor for the comparison key
rrange from which the maximum element will be selected
seedcustom seed to use as initial element Precondition: If a seed is not given, r must not be empty.

Returns

The maximal element of the passed-in range.

Note

If at least one of the arguments is NaN, the result is an unspecified value.

See minElement for examples on how to cope with NaNs.

See Also

fnauto maxElement(alias map = (a => a), Range, RangeElementType = ElementType!Range)(Range r, RangeElementType seed) if (isInputRange!Range && !isInfinite!Range && !is(CommonType!(ElementType!Range, RangeElementType) == void))

ditto