[Issue 7897] New: Problem with alias template parameter

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Apr 13 06:35:13 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7897

           Summary: Problem with alias template parameter
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: turkeyman at gmail.com


--- Comment #0 from Manu <turkeyman at gmail.com> 2012-04-13 06:35:59 PDT ---
I've boiled this down as much as I can. My use case isn't clearly reflected
here (significantly more complex).



import std.traits;

struct ExternFunction
{
    string name;
    void* pFunction;
}


// loose function
extern(C) void function() globalFunction;

// functions contained in a struct
struct Debug
{
    extern(C) void function( const char* format, ... ) outputDebug;
}
__gshared Debug d;


void main()
{
    const(ExternFunction)* pImports = null;

    // register loose function is okay
    HookupEngineFunction!( globalFunction )( pImports );

    // register function in struct (doesn't work, won't take alias for some
reason?)
    HookupEngineFunction!( d.outputDebug )( pImports );

    // register whole struct (fails via internal call to the function above,
but with a different complaint)
    HookupEngineModule!( d )( pImports );
}

private:

// hook up a struct full of callback pointers
void HookupEngineModule( alias s )( const(ExternFunction)* pImports )
{
    // iterate struct members
    foreach( m; __traits( allMembers, typeof( s ) ) )
    {
        // !!! getMember doesn't work here...
        HookupEngineFunction!( __traits( getMember, s, m ) )( pImports );
    }
}


void HookupEngineFunction( alias funcptr )( const(ExternFunction)* pImports )
{
    alias typeof( funcptr ) Type;

    static if( isFunctionPointer!Type )
    {
        const(ExternFunction)* pExtern = pImports; // FindImport(...);

        funcptr = cast(Type)pExtern.pFunction;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list