Function max

Finds the largest element in the argument list or a range.

CommonType!Args max(Args...) (
  Args args
)
if (Args.length >= 2 && isOrderingComparable!(Args[0]) && allSameType!(Map!(Unqual, Args)));

ref inout(Unqual!(Args[0])) max(Args...) (
  inout ref Args args
)
if (Args.length >= 2 && isOrderingComparable!(Args[0]) && allSameType!(Map!(Unqual, Args)));

Range max(Range) (
  Range range
)
if (isForwardRange!Range && isOrderingComparable!(ElementType!Range));

If a range is passed, max returns a range of the same type, whose front element is the largest in the range. If more than one element fulfills this condition, the front of the returned range points to the first one found. If range is empty, the original range is returned.

If Args are floating point numbers, NaN is not considered for comparison. NaN is returned only if all arguments are NaNs.

Parameters

NameDescription
Args Types of the arguments. All arguments should have the same type.
Range Forward range type.
args Argument list.
range Forward range.

Returns

The largest element.

Example

assert(max(1, 2) == 2);
assert(max(3, 2) == 3);
assert(max(1, 3, 2) == 3);

int[4] range = [1, 5, 5, 2];
auto maxElement = max(range[]);
assert(maxElement.front == 5);
assert(maxElement.length == 3);