www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 24650] New: foreach should support inout for callback delegate

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

          Issue ID: 24650
           Summary: foreach should support inout for callback delegate
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: apz28 hotmail.com

struct S
{
    int opApply(int delegate(inout(int)) dg)
    {
        dg(1);
        return 0;
    }

    int opApply(int delegate(size_t, inout(int)) dg)
    {
        dg(0, 1);
        return 0;
    }
}

void main()
{
    import std.stdio;

    S s;
    foreach(n; s) // error on this line
        writeln(n);    
}


onlineapp.d(21): Error: variable `onlineapp.main.__foreachbody2.n` - `inout`
variables can only be declared inside `inout` functions

--
Jul 05