Skip to content

Conversation

ghost
Copy link

@ghost ghost commented Feb 8, 2013

No description provided.

@ghost
Copy link
Author

ghost commented Feb 8, 2013

Unfortunately the diff view doesn't give it justice, not even with ?w=0.

alexrp added a commit that referenced this pull request Feb 10, 2013
Refactor lockstep and simplify opApply string mixin generator.
@alexrp alexrp merged commit cac8c67 into dlang:master Feb 10, 2013
@denis-sh
Copy link
Contributor

First of all, we don't need std.range.lockstep at all. What we really need is to document ability to expand tuple in foreach (implemented by Kenji of course) and add such example to std.range.zip.

@ghost
Copy link
Author

ghost commented Feb 14, 2013

First of all, we don't need std.range.lockstep at all.

We'll need at least a backwards-compatible template or function which forwards to zip, to avoid breaking code.

@denis-sh
Copy link
Contributor

You are right of course, I mean as a permanent documented member.

@monarchdodra
Copy link
Collaborator

We'll need at least a backwards-compatible template or function which forwards to zip, to avoid breaking code.

AFAIK, zip's front is return by value, so you we use zip in a foreach with ref parameters. You can with lockstep:

import std.range;
import std.stdio;

void main()
{
    int i = 0;
    int[] odds = new int [](4);
    int[] evens  = new int [](4);
    foreach(ref a, ref b; lockstep(odds, evens)) //Works
    //foreach(ref a, ref b; zip(odds, evens)) //Fails
    {
        a = ++i;
        b = ++i;
    }
    assert(odds == [1, 3, 5, 7]);
    assert(evens == [2, 4, 6, 8]);
}

So we can't currently outright make lockstep an alias of zip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants