Cannot use function as foreach aggregate.

Jarrett Billingsley kb3ctd2 at yahoo.com
Thu Apr 5 20:23:58 PDT 2007


"BCS" <BCS at pathlink.com> wrote in message 
news:ev45id$94v$1 at digitalmars.com...
> Jarrett Billingsley wrote:
>
> Of course this all only works for statically known functions. If that 
> isn't the case then the original solution is needed.
>
> OTOH this might work
>
> template ToDelegate(alias func)
> {
>  ReturnType!(func) delegate(ParameterTypeTuple!(func)) ToDelegate()
>  {
>   struct S
>   {
>    ReturnType!(func) callMe(ParameterTypeTuple!(func) args)
>    {
>     return(cast(typeof(func))cast(void*)this)(args);
>    }
>   }
>   return &((cast(S*)cast(void*)&func).callMe);
>  }
> }
>
> I'd have to play with it but the same thing could be done for a dynamic 
> pointer just with a few things moved around.
>
>
> Ohh, I'd so fire anyone who tried to get me to pay them for writing that.

Error: can't convert from void* to a function pointer.  Oh well. 





More information about the Digitalmars-d mailing list