[Issue 17771] foreach over const input range fails

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Tue Aug 22 12:37:02 PDT 2017


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

ag0aep6g at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ag0aep6g at gmail.com

--- Comment #11 from ag0aep6g at gmail.com ---
(In reply to Alex Goltman from comment #9)
> the error stating foreach doesn't work with a
> const actually made me question whether foreach over a range modifies the
> range I give it,

I don't really have a horse in this race, but if we consider a generic range,
then `foreach` does very much modify it. `foreach` doesn't call `save`, so
every `popFront` potentially modifies the original range.

It doesn't really matter that `foreach` copies the range, because copying is
not a range concept. If you have a generic range, and you run it through
`foreach`, you must be prepared to have an empty range afterwards.

--


More information about the Digitalmars-d-bugs mailing list