[Issue 9437] unwanted behavior from phobos range

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Feb 1 06:31:02 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9437



--- Comment #3 from monarchdodra at gmail.com 2013-02-01 06:31:01 PST ---
(In reply to comment #2)
> Ok, but silently doing this that is really bad and a is really a thing in D
> where could create many bug

But silently doing what? If the range provides random access, then which
behavior would you expect?

//----
int arr[] = [1, 2, 3]

foreach ( a ; arr)
    writeln(arr.front); //So this print 1, 2, 3?

assert(arr.length == 3); //But this should pass?
//----

The expected behavior of foreach is *only* to iterate on each element of the
range, but it is also expected to *not* modify the range.

It is modifying the range that would provide surprising results.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list