[Issue 16279] foreach and opApply cannot be nogc

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Oct 26 13:11:21 UTC 2021


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

moonlightsentinel at disroot.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |moonlightsentinel at disroot.o
                   |                            |rg
         Resolution|---                         |WORKSFORME

--- Comment #1 from moonlightsentinel at disroot.org ---
Overloading w.r.t. @nogc works since 2.080.1.

Test case:


struct Foo
{
    int[3] arr = [1, 2, 3];

    int opApply(scope int delegate(ref int) @nogc loopBody) @nogc
    {
        foreach(a; arr)
            loopBody(a);
        return 0;
    }

    int opApply(scope int delegate(ref int) loopBody)
    {
        foreach(a; arr)
            loopBody(a);
        return 0;
    }
}

void main() @nogc
{
    Foo foo;
    int sum = 0;
    foreach(f; foo)
    {
        sum += f;
    }
}

--


More information about the Digitalmars-d-bugs mailing list