View source code
Display the source code in std/algorithm/comparison.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
Improve this page
Quickly fork, edit online, and submit a pull request for this page.
Requires a signed-in GitHub account. This works well for small changes.
If you'd like to make larger changes you may want to consider using
local clone.
Function std.algorithm.comparison.min
Iterates the passed arguments and returns the minimum value.
MinType!T min(T...)
(
T args
)
if (T .length >= 2);
Parameters
Name | Description |
---|---|
args | The values to select the minimum from. At least two arguments
must be passed, and they must be comparable with < . |
Returns
The minimum of the passed-in values.
See Also
Example
int a = 5;
short b = 6;
double c = 2;
auto d = min(a, b);
static assert(is(typeof(d) == int));
writeln(d); // 5
auto e = min(a, b, c);
static assert(is(typeof(e) == double));
writeln(e); // 2
// With arguments of mixed signedness, the return type is the one that can
// store the lowest values.
a = -10;
uint f = 10;
static assert(is(typeof(min(a, f)) == int));
writeln(min(a, f)); // -10
// User-defined types that support comparison with < are supported.
import std .datetime;
writeln(min(Date(2012, 12, 21), Date(1982, 1, 4))); // Date(1982, 1, 4)
writeln(min(Date(1982, 1, 4), Date(2012, 12, 21))); // Date(1982, 1, 4)
writeln(min(Date(1982, 1, 4), Date .min)); // Date.min
writeln(min(Date .min, Date(1982, 1, 4))); // Date.min
writeln(min(Date(1982, 1, 4), Date .max)); // Date(1982, 1, 4)
writeln(min(Date .max, Date(1982, 1, 4))); // Date(1982, 1, 4)
writeln(min(Date .min, Date .max)); // Date.min
writeln(min(Date .max, Date .min)); // Date.min
Authors
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.