[Issue 15413] Foreach over range with @disable this(this) doesn't work

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 25 04:41:36 UTC 2019


https://issues.dlang.org/show_bug.cgi?id=15413

Jonathan M Davis <issues.dlang at jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |issues.dlang at jmdavisProg.co
                   |                            |m
           Severity|normal                      |enhancement

--- Comment #3 from Jonathan M Davis <issues.dlang at 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.

--


More information about the Digitalmars-d-bugs mailing list