[Issue 23116] foreach with opApply infer ref when opApply delegate is templated
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Mon May 16 17:55:10 UTC 2022
    
    
  
https://issues.dlang.org/show_bug.cgi?id=23116
--- Comment #4 from Luís Ferreira <contact at lsferreira.net> ---
Doing fallback of the overload manually can be a workaround for this:
```
int opApply(Dg : int delegate(ref ubyte))(scope Dg dg)
{
    enum attrs = functionAttributes!Dg;
    alias nonRefDg = SetFunctionAttributes!(int delegate(ubyte),
functionLinkage!Dg, attrs);
    foreach(ubyte i; &this.opApply!(nonRefDg)) // use the correct overload
        if(auto ret = dg(i)) return ret;
    return 0;
}
int opApply(Dg : int delegate(ubyte))(scope Dg dg)
{
    // ...
}
```
--
    
    
More information about the Digitalmars-d-bugs
mailing list