Reflection magic: function signatures

Christopher Wright dhasenan at gmail.com
Sat Jun 30 17:20:47 PDT 2007


Jarrett Billingsley wrote:
> "Christopher Wright" <dhasenan at gmail.com> wrote in message 
> news:f65pa1$1rt3$1 at digitalmars.com...
>> As far as I can tell, I can't suss out a function signature at compile 
>> time with the current reflection systems. Flectioned seems to require a 
>> pointer to the function, and that won't exist until the function has been 
>> compiled.
> 
> But.. but you did this:
> 
>> ---
>> T function (U) CreateFunction(T, U...)() {
>>     T func(U u) { return T.init; } // probably just does first element; 
>> need mixin
>>     return &func;
>> }
>> ---
> 
> The function signature is just the return type + parameter type tuple, no?
> 
> import std.traits;
> 
> T function(U) CreateFunction(FuncType, T = ReturnType!(FuncType), U = 
> ParameterTypeTuple!(FuncType))()
> {
>     // static so we can return it
>     static T func(U u) { return T.init; }
>     return &func;
> }
> 
> 

My god, you're a genius!


More information about the Digitalmars-d-learn mailing list