[Issue 4705] Redesign of std.algorithm.max()/min() + mins()/maxs()

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Mar 24 15:11:04 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=4705



--- Comment #7 from bearophile_hugs at eml.cc 2011-03-24 15:07:40 PDT ---
The examples hopefully show how much useful are the new max/min.
This is part of the "pivoting" part of a LU decomposition algorithm:

T imax = mat[j][j];
int nrow = j;
foreach (i; j .. N) {
    if (mat[i][j] > imax) {
        imax = mat[i][j];
        nrow = i;
    }
}


With the improved max() it becomes:

int nrow = max!((int i){ return mat[i][j]; })(iota(j, N));


That is similar to this Python code:

nrow = max(xrange(j, N), key=lambda i: mat[i][j])

Python designers have recognized this is a common pattern in code.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list