Jump to page: 1 2
Thread overview
[Issue 16255] std.algorithm.iteration.each on opApply doesn't support ref
Oct 09, 2016
Jon Degenhardt
Oct 09, 2016
Jon Degenhardt
Dec 23, 2016
greenify
Feb 05, 2017
b2.temp@gmx.com
Mar 21, 2020
Basile-z
Jun 10, 2022
Ali Cehreli
Dec 17, 2022
Iain Buclaw
October 09, 2016
https://issues.dlang.org/show_bug.cgi?id=16255

Jon Degenhardt <jrdemail2000-dlang@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jrdemail2000-dlang@yahoo.co
                   |                            |m

--
October 09, 2016
https://issues.dlang.org/show_bug.cgi?id=16255

--- Comment #1 from Jon Degenhardt <jrdemail2000-dlang@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).

--
December 23, 2016
https://issues.dlang.org/show_bug.cgi?id=16255

greenify <greeenify@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greeenify@gmail.com

--- Comment #2 from greenify <greeenify@gmail.com> ---
> Except it doesn't work. When each accepts the iterable, it accepts it by value. It should accept it by reference (if it's a class, it could take the class reference by value). Otherwise, the point of using ref throughout each is kind of useless.

A simple solution with `auto ref` for Iterables:

https://github.com/dlang/phobos/pull/4991

--
December 24, 2016
https://issues.dlang.org/show_bug.cgi?id=16255

--- Comment #3 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/f903de7bc6a507e787323d633679872c5c8e618c Fix issue 16255 - std.algorithm.iteration.each on opApply doesn't support ref

https://github.com/dlang/phobos/commit/515b6a4ea2d9485a01efbf212357b623980bfa82 Merge pull request #4991 from wilzbach/fix-issue-16255-each-opApply

Fix issue 16255 - std.algorithm.iteration.each on opApply doesn't support

--
December 24, 2016
https://issues.dlang.org/show_bug.cgi?id=16255

github-bugzilla@puremagic.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--
January 07, 2017
https://issues.dlang.org/show_bug.cgi?id=16255

--- Comment #4 from github-bugzilla@puremagic.com ---
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/f903de7bc6a507e787323d633679872c5c8e618c Fix issue 16255 - std.algorithm.iteration.each on opApply doesn't support ref

https://github.com/dlang/phobos/commit/515b6a4ea2d9485a01efbf212357b623980bfa82 Merge pull request #4991 from wilzbach/fix-issue-16255-each-opApply

--
January 16, 2017
https://issues.dlang.org/show_bug.cgi?id=16255

--- Comment #5 from github-bugzilla@puremagic.com ---
Commits pushed to newCTFE at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/f903de7bc6a507e787323d633679872c5c8e618c Fix issue 16255 - std.algorithm.iteration.each on opApply doesn't support ref

https://github.com/dlang/phobos/commit/515b6a4ea2d9485a01efbf212357b623980bfa82 Merge pull request #4991 from wilzbach/fix-issue-16255-each-opApply

--
February 05, 2017
https://issues.dlang.org/show_bug.cgi?id=16255

b2.temp@gmx.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |b2.temp@gmx.com
         Resolution|FIXED                       |---

--- Comment #6 from b2.temp@gmx.com ---
Is this supposed to work now ?


void main()
{
    int[][] arr = void;
    arr.length = 10;

    version(all)
    {
        import std.algorithm.iteration : each;
        arr.each!((ref a){a.length = 10; a[] = -1;});
    }
    else
    {
        foreach(ref a; arr)
        {
            a.length = 10;
            a[] = -1;
        }
    }
}

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=16255

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--
June 10, 2022
https://issues.dlang.org/show_bug.cgi?id=16255

Ali Cehreli <acehreli@yahoo.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |acehreli@yahoo.com

--- Comment #7 from Ali Cehreli <acehreli@yahoo.com> ---


(In reply to Basile-z from comment #6)
> Is this supposed to work now ?
> 
> 
> void main()
> {
>     int[][] arr = void;

That is the problem. We can't use arr in any meaningful way because it already has garbage number of garbage elements.

>     arr.length = 10;

It reduces the length to 10 but all the elements are garbage.

--
« First   ‹ Prev
1 2