Cannot use function as foreach aggregate.
BCS
BCS at pathlink.com
Fri Apr 6 09:15:15 PDT 2007
Jarrett Billingsley wrote:
> "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.
>
>
OK, I've tested this one on 0.177
(Yes, I need to update this system :-b)
R delegate(Args) ToDelegate(R, Args...)(R function(Args) func)
{
struct S
{
void callMe(Args args)
{
return (cast(R function(Args))cast(void*)this)(args);
}
}
return &((cast(S*)cast(void*)func).callMe);
}
More information about the Digitalmars-d
mailing list