-
-
Notifications
You must be signed in to change notification settings - Fork 380
Open
Description
I know if return 0 is bug prone as return 1 and havnt looked for an example of it breaking labeled break, but......
foreach (x; &myLoop) that & is nesting a delegate of delegates; which suggests when this code was written is was someone searching for something that "just werked" (probably copy and pasted from an opApply code example ) rather than the simplest/idiomatic pattern of what the feature can do.
code im currently playing with:
#!opend test app
import std;
auto toiter(R)(ref R r) if (isInputRange!R){
return (int delegate(ref ElementType!R) dg){
int ret;
while( ! r.empty){
ret=dg(r.front);
r.popFront;
if(ret){return ret;}
}
return ret;
};
}
auto toiter(T)(ref T t) if ( ! isInputRange!T){
return (int delegate(ref T) dg){
return dg(t);
};
}
unittest{
auto foo=iota(9).toiter;
foo=10.toiter;
auto bar=iota(9).toiter;
excape:foreach(i;foo){
foreach(j;bar){
writeln(i,',',j);
if(j==10){ break excape;}
}}
"---".writeln;
foo=iota(9).toiter;
bar=10.toiter;
excape2:foreach(i;foo){
foreach(j;bar){
writeln(i,',',j);
if(j==10 && i==2){ break excape2;}
}}
}Metadata
Metadata
Assignees
Labels
No labels