opApply/opApplyReverse return value types

Bill Baxter wbaxter at gmail.com
Tue Oct 17 14:21:34 PDT 2006

Max Samuha wrote:
> The question might seem idle but why opApply/opApplyReverse return int
> instead of bool, anyway?

Actually, why do they have to return anything?  It seems like it should 
be possible to make this work:

void opApply(void delegate(inout ArgT) dg)
    for (int i=0; i<length; i++)
       if (dg(array[i]))

I haven't totally grokked the code, but I see the magic is happening in 
statement.c, ForeachStatement::semantic somewhere.  That function is 
constructing the delegate that wraps the loop body.  I don't see why the 
delegate wrapper can't just store the value it returns to me so I don't 
have to keep track of it.  It seems weirdly low-level for me to have to 
be the shephard of some value who's meaning is totally opaque to me.


More information about the Digitalmars-d-learn mailing list