bearophile wrote:
In my dlibs there's a lazyOr() that takes any number of arguments and returns 
the first one that's true (where true is defined by a standard function 
boolean() that returns false for 0, null, objects/structs that have a length 
and where such length is zero).

A reduced (and untested) version that works with two arguments only, that is (I 
think) the Elvis operator:

Tx lazyOr(Tx, Ty)(Tx x, lazy Ty y) {
    static assert(CastableTypes!(Tuple!(Tx, Ty)), "lazyOr: all items must be 
castable to the same type.");
    if (boolean(x))
        return x;
    return y();
}

I guess this would work better:

CommonType!(Tx, Ty) lazyOr(Tx, Ty)(Tx x, lazy Ty y) { ... }


Andrei

Reply via email to