zip vs. lockstep -- problems accessing elements by ref

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Sat Jun 29 02:57:05 PDT 2013


On 06/29/2013 11:42 AM, Joseph Rushton Wakeling wrote:
> I should add that bearophile has been fantastic in suggesting alternative design
> patterns that don't require either lockstep _or_ zip, but I still think this
> lockstep/zip discrepancy needs resolving.

According to the docs: zip "offers mutation and swapping if all ranges offer
it".  But I still get an arrayful of nan's even if I do:

    auto arr3 = new double[10];
    auto index = iota(10).array();
    foreach(i, ref x; zip(index, arr3))
    {
        x = i;
    }
    writeln(arr3);

... even though the array index ought to be mutable here.  Tweaking to

    foreach(ref i, ref x; zip(index, arr3))
    {
       x = i;
    }

... doesn't work either.


More information about the Digitalmars-d-learn mailing list