max

Iterates the passed arguments and returns the maximum value.

  1. auto max(T args)
  2. T max(T a, U b)
    T
    max
    (
    T
    U
    )
    (
    T a
    ,
    U b
    )
    if (
    is(T == U) &&
    is(typeof(a < b))
    )

Return Value

Type: T

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