opApply and that int

BCS ao at pathlink.com
Fri Jan 4 09:34:43 PST 2008


Reply to Bill,


> Ok, Jason poked me into realizing that I completely forgot that the
> user's opApply has to know to return when the loop body does a break
> or something.  So with what I just proposed it would still have to
> check for a non-zero return code, *BUT* it wouldn't have to return it
> to the caller.  So opApplys could become:
> 

how about this:

void opApply( /**/ bool /**/  delegate(ref T) loop_body) {
  for(/*x in elements*/)
  {
    if (loop_body(x)) return;
  }
}


> Unfortunately if you call yield in a
> non-opApply callback situation it could just do bogus stuff and
> probably
> couldn't even warn you that what you were doing was bogus.

yield(loop_body(x));  // can check stuff about loop_body

but that still has the issue of:

MyObject mo;
mo.opApply((ref T x){something(x);});  // call to opApply directly


> --bb
> 




More information about the Digitalmars-d-learn mailing list