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

          Issue ID: 19984
           Summary: Support shared in foreach lambdas
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P1
         Component: dmd
          Assignee: nob...@puremagic.com
          Reporter: turkey...@gmail.com

We want to arrive at a place where this code works:

struct S {
    int result;
    void inc(int i) shared { result.atomic!"+="(i); }
}
int sum(){
    S s;
    foreach(i; iota(1000).parallel){
        static assert(is(typeof(s) == shared(S)));
        s.inc(i);
    }
    static assert(is(typeof(s) == S));
    return s.result;
}



In this example, the opApply delegate would be `int delegate(ref int) shared`.

--

Reply via email to