Reflection magic: function signatures

Jarrett Billingsley kb3ctd2 at yahoo.com
Sat Jun 30 09:40:42 PDT 2007


"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;
}




More information about the Digitalmars-d-learn mailing list