Andrei Alexandrescu <seewebsiteforem...@erdani.org> wrote:
And one consequence of that is that contrary to what has been said, this
would *not* allow foreach to be implemented as a library function.
I can appreciate the difficulty of getting the delegate's flow control
to be
handled as expected, but I think going ahead with this sugar without
addressing that in some way would be a mistake.
Control flow inside the delegate can be addressed through a slightly
more complicated lowering (the kind foreach already does). Probably
break and continue should not be accepted because generally you can't
expect all user-defined constructs to do iteration. Early returns should
be easy to handle.
void foo( string delegate( int ) );
string bar( ) {
foo( 3; ) {
return "a"; // Does this return "a" to foo, or from bar?
}
}
--
Simen