max

Iterates the passed arguments and returns the maximum value.

  1. auto max(T args)
    max
    (
    T...
    )
    ()
    if (
    T.length >= 2 &&
    !is(CommonType!T == void)
    )
  2. T max(T a, U b)

Parameters

args T

The values to select the maximum from. At least two arguments must be passed, and they must be comparable with <.

Return Value

Type: auto

The maximum of the passed-in values. The type of the returned value is the type among the passed arguments that is able to store the largest value. If at least one of the arguments is NaN, the result is an unspecified value. See std.algorithm.searching.maxElement for examples on how to cope with NaNs.

Examples

int a = 5;
short b = 6;
double c = 2;
auto d = max(a, b);
assert(is(typeof(d) == int));
assert(d == 6);
auto e = min(a, b, c);
assert(is(typeof(e) == double));
assert(e == 2);

See Also

Meta