Can a member function return a delegate to itself?

Gregor Richards Richards at codu.org
Wed May 23 10:28:56 PDT 2007


BCS wrote:
> as mentioned, the reason this isn't directly doable is that the type is 
> undefinable. However this is strictly a limitation of the D Syntax and 
> their is no problem with actually doing it if you can tell DMD how. I 
> have does this using typing tricks before:
> 
> 
> struct S
> {
>     S delegate(int,int) dg;
> }
> 
> struct O
> {
>     int k;
>     S go(int i, int j)
>     {
>         O* o = new O
>         o.k = k+i+j;
>         S ret;
>         ret.dg = &o.go;
>         return ret;
>     }
> }

I just want to say that this method is brilliant. It's easy to read and 
understand on a high and low level, and does everything you need it to 
do with no questions asked. Bravo.

  - Gregor Richards



More information about the Digitalmars-d mailing list