On Wednesday, 20 September 2017 at 19:25:58 UTC, Timon Gehr wrote:

Actually, it is useful enough to have a Wikipedia page:
https://en.wikipedia.org/wiki/Iverson_bracket

Example of a good use:

void floodFill(dchar[][] data,dchar c,int i,int j) {
    void dfs(int a, int b) {
        if (a<0 || a >= data.length) return;
        if (b<0 || b >= data[a].length) return;
        if (data[a][b] == c) return;
        data[a][b] = c;
        foreach(i; 0 .. 4){
            dfs(a + (i==0) - (i==1),
                b + (i==2) - (i==3));
        }
    }
    dfs(i, j);
}

I would rather use an explicit function for such use cases:

int delta(bool x) { return x == true ? 1 : 0; }

Reply via email to