[Issue 16255] std.algorithm.iteration.each on opApply doesn't support ref

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Sun Oct 9 14:25:24 PDT 2016


https://issues.dlang.org/show_bug.cgi?id=16255

--- Comment #1 from Jon Degenhardt <jrdemail2000-dlang at yahoo.com> ---
An example that appears related:

void main()
{
    import std.algorithm : each;

    int[] dynamicArray = [1, 2, 3, 4, 5];
    int[5] staticArray = [1, 2, 3, 4, 5];

    dynamicArray.each!((ref x) => x++);
    assert(dynamicArray == [2, 3, 4, 5, 6]); // modified

    staticArray.each!((ref x) => x++);
    assert(staticArray == [1, 2, 3, 4, 5]);  // not modified

    staticArray[].each!((ref x) => x++);
    assert(staticArray == [2, 3, 4, 5, 6]);  // modified
}

Using a ref parameter works in the range cases, but not the static array case
(opApply).

--


More information about the Digitalmars-d-bugs mailing list