Can you spot the difference between foo1 and foo2?

import std.algorithm: map;
import std.range: iota;

void foo1(in int[] a, in int[] b) pure {
    int[] r;
    foreach (immutable i; 0 .. a.length)
        r ~= (i % 2) ? a[i] : b[i];
}

void foo2(in int[] a, in int[] b) pure {
    int[] r;
    foreach (x; iota(a.length)
                .map!(i => (i % 2) ? a[i] : b[i]))
        r ~= x;
}

void main() {}



Sometimes variants of this problem hit me. I don't even know if this simple problem has a name. Is it impossible to solve?

Bye,
bearophile

Reply via email to