V Thu, 11 Sep 2014 14:49:02 +0000
bearophile via Digitalmars-d-learn <digitalmars-d-learn@puremagic.com>
napsáno:

> Daniel Kozak:
> 
> You can just use min:
> 
> import std.stdio, std.algorithm;
> 
> struct Thing {
>      uint x;
>      alias x this;
> }
> 
> alias minimum = reduce!min;
> 
> void main() {
>       immutable ar1 = [10, 20, 30, 40, 50];
>       ar1.minimum.writeln;
> 
>       immutable ar2 = [Thing(10), Thing(20), Thing(40)];
>       ar2.minimum.writeln;
> }
> 
> Bye,
> bearophile

Yep, this look the most idiomatic :).

Why there is no phobos function for minimum of array(range)?

Reply via email to