www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10541] New: Failure writing to elements of std.range.zip

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10541

           Summary: Failure writing to elements of std.range.zip
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: joseph.wakeling webdrake.net


--- Comment #0 from Joseph Rushton Wakeling <joseph.wakeling webdrake.net>
2013-07-04 03:09:15 PDT ---
According to the documentation, std.range.zip "offers mutation and swapping if
all ranges offer it".  However, as the attached code sample shows, attempting
to write to elements of a zip in a foreach loop consistently fail, even when
accessed by ref and when all ranges in the zip are mutable.

The sample code shows (i) foreach'ing over a lockstep of a non-mutable range
and an array, writing to the array; (ii) foreach'ing over a zip of a
non-mutable range and an array; (iii) foreach'ing over a zip of two arrays,
writing to the second, with only the elements of the second accessed via ref;
(iv) foreach'ing over a zip of two arrays, accessing the elements of both via
ref.

The foreach over the lockstep results in an array with correctly-written
values, but the arrays that should be written to via foreach over zip remain
full of nan's.

This problem is also a block to the proposal in #8155 to deprecate lockstep in
favour of zip, since it makes it impossible to do a blanket replace
's/lockstep/zip/' and have the resulting code work.

At a minimum, zip should be corrected to ensure that its elements are mutable
in line with the statement made in the docs (i.e., the 3rd and 4th cases in the
sample code should result in arrays filled with correct values).  Ideally,
elements of a zip that come from a mutable range should themselves be mutable
even if the other ranges in the zip aren't (i.e. the 2nd case in the sample
code should also work).

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 04 2013
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10541



--- Comment #1 from Joseph Rushton Wakeling <joseph.wakeling webdrake.net>
2013-07-04 03:09:54 PDT ---
Created an attachment (id=1229)
Sample code to illustrate the problem.

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