even more delegate sugar

Don Clugston dac at nospam.com.au
Tue Aug 22 06:59:32 PDT 2006


Tom S wrote:
> Don Clugston wrote:
>> Oskar Linde wrote:
>>> Don Clugston wrote:
>>>> On reflection, an even more interesting example is variants of 
>>>> foreach, which I think would become completely redundant.
>>>
>>> break would pose a problem though.
>>
>> You're right.
>> Although foreach with opApply has the same problem.
> 
> Umm, nope...
> http://digitalmars.com/d/statement.html#foreach
> 
> Look at the opApply example. The delegate implementing foreach's body 
> returns != 0 in case of a break.

That's exactly what I meant. You can't use 'break' inside opApply, but 
of course it can be emulated, and the same solution could apply to 
Foreach function. It's just lacking in syntactic sugar (and probably in 
performance, too).

> It can be emulated thru e.g.
> return BREAK;
> or
> return CONTINUE;

> 
> 
> but if there was a way to define a function like:
> 
> outer.return myBreak() {
>     outer.return BREAK;
> }
> 
> ... then things could get even more bizarre ;)



More information about the Digitalmars-d mailing list