Recursive delegate inside template?
    drathier 
    forum.dlang.org at fi.fo
       
    Fri Jun 26 14:12:00 UTC 2020
    
    
  
I'm trying to get this to compile, without much luck:
```
bool foo()
{
     template fn(A)
     {
         A delegate(A) fn;
         fn = delegate A(A a)
         {
             return fn(a);
         };
     }
     return fn!(bool)(true);
}
```
What am I missing here? How can I define a recursive delegate 
inside another function like this? I even got a gold linker error 
from run.dlang.io at one point: "TLS relocation against invalid 
instruction".
Removing the template works fine:
```
bool foo()
{
     alias A = bool;
     A delegate(A) fn;
     fn = delegate A(A a) { return fn(a); };
     return fn(true);
}
```
but I need the function to be polymorphic, so I need the template.
    
    
More information about the Digitalmars-d-learn
mailing list