Compared to normal iteration schemes, yes. It may be
comparable to opApply in terms of performance though. If
you're curious, look at the Fiber context switching code
(starting at switchIn and switchOut).
It's much slower than opApply. This loop takes 70s on my machine:
foreach(el; visitor(Iterable(1000_000_000)))
sum += 1;
And this one takes 2.7s:
auto iter(int n)
{
struct I
{
int n;
int opApply(int delegate(ref int) dg)
{
for(int i = 0; i < n; i++)
if(int r = dg(i))
return r;
return 0;
}
}
return I(n);
}
foreach(el; iter(1000_000_000))
sum += 1;