Function min
Finds the smallest element in the argument list or a range.
CommonType!Args min(Args...)
(
Args args
)
if (Args .length >= 2 && isOrderingComparable!(Args[0]) && allSameType!(Map!(Unqual, Args)));
ref inout(Unqual!(Args[0])) min(Args...)
(
inout ref Args args
)
if (Args .length >= 2 && isOrderingComparable!(Args[0]) && allSameType!(Map!(Unqual, Args)));
Range min(Range)
(
Range range
)
if (isForwardRange!Range && isOrderingComparable!(ElementType!Range));
If a range is passed, min returns a range of the same type, whose front element is the smallest 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
Name | Description |
---|---|
Args | Types of the arguments. All arguments should have the same type. |
Range | Forward range type. |
args | Argument list. |
range | Forward range. |
Returns
The smallest element.
Example
assert(min(1, 2) == 1);
assert(min(3, 2) == 2);
assert(min(3, 1, 2) == 1);
int[4] range = [3, 1, 1, 2];
auto minElement = min(range[]);
assert(minElement .front == 1);
assert(minElement .length == 3);