On Wednesday, May 16, 2012 03:29:23 Nick Sabalausky wrote:
> "Jonathan M Davis" <[email protected]> wrote in message
> news:[email protected]...
> 
> > No. That's expected. Your range is a value type, so it got copied when you
> > used it with foreach.
> 
> But foreach isn't a function, it's a flow-control statement.

If it _wasn't_ copied, using foreach would consume your range. It doesn't, and 
it would really suck if it did. But

foreach(e; range) {}

pretty has to be translated to something similar to

for(auto r = range; !r.empty(); r.popFront())
{
    auto e = r.front;
}

And actually, looking at TDPL (p. 381), that's pretty much _exactly_ what it 
gets translated to (save for the exact variable names used).

- Jonathan M Davis

Reply via email to