Internal delegate and Stack Overflow

tsalm tsalm at free.fr
Sat Nov 29 01:45:13 PST 2008


Le Sat, 29 Nov 2008 01:49:20 +0100, BCS <ao at pathlink.com> a écrit:

> struct C(R, A...)
> {
>   A args;
>   R function(A) dg;
>   static R delegate() opCall(R function(A) dg, A a)
>   {
>      C!(R, A) ret;
>      ret.dg=dg;
>      foreach(int i,_;A)
>         ret.args[i] = a[i];
>      return &ret.fn;
>   }
>   R fn() { return dg(args); }
> }
>   // test it
>  import std.stdio;
>  int delegate() dg(int i)
> {
>   return C!(int,int)(function int(int j){return j;}, i);   // <--- used  
> here
> }
>  void main()
> {
>   auto d = dg(5);
>   writef("%s\n", d());
> }

Interesting code. Thanks!


More information about the Digitalmars-d-learn mailing list