https://issues.dlang.org/show_bug.cgi?id=15413
Jonathan M Davis <issues.dl...@jmdavisprog.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |issues.dl...@jmdavisprog.co | |m Severity|normal |enhancement --- Comment #3 from Jonathan M Davis <issues.dl...@jmdavisprog.com> --- foreach specifically copies the range that it's given. If it didn't, then iterating over a dynamic array would consume it. It does unfortunately mean that whether a range is consumed or not depends on whether it's a reference type, pseudo-reference type, or value type, but that's a general problem with copying ranges. Either way, changing how foreach worked would break a lot of code. So, in order for this to work, ranges which are non-copyable would have to be treated differently from other ranges when using foreach. However, considering that almost all range-based code copies ranges, I find it hard to believe that having a non-copyable range makes much sense. And if you specifically are looking for foreach to work, you should just be able to use opApply instead of making the object a range. --