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

           Summary: Introduce functionLinkageType to mirror
                    functionLinkage with an enum
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: [email protected]
        ReportedBy: [email protected]


--- Comment #0 from Andrej Mitrovic <[email protected]> 2013-08-23 
04:51:27 PDT ---
Currently std.traits.functionLinkage returns the linkage type, but it returns
it as a string. So if you have generic code, you might end up writing code like
so:

-----
import std.traits;

extern(C) void func()
{
}

void main()
{
    enum linkage = functionLinkage!func;

    static if (linkage == "c")
    {
    }
    else
    static if (linkage == "D")
    {
    }
}
-----

Unfortunately there's a bug here, there is no lowercase "c" linkage type, only
"C". It would be safer if functionLinkage returned an enum. 

But since it's too late to change the return type, I propose we introduce an
enum version:

-----
import std.traits;

extern(C) void func()
{
}

void main()
{
    // new trait which returns a LinkageType enum instance
    enum linkage = functionLinkageType!func;

    static if (linkage == LinkageType.c)
    {
    }
    else
    static if (linkage == LinkageType.d)
    {
    }
}
-----

This will also allow a user to generate code by using EnumMembers on the
LinkageType enum.

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

Reply via email to