www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 10875] New: Introduce functionLinkageType to mirror functionLinkage with an enum

reply d-bugmail puremagic.com writes:
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: nobody puremagic.com
        ReportedBy: andrej.mitrovich gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich gmail.com> 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: -------
Aug 23 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10875



--- Comment #1 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-23
04:54:39 PDT ---
(In reply to comment #0)
 But since it's too late to change the return type, I propose we introduce an
 enum version:
Actually a reasonable alternative is to simply introduce the LinkageType enum which will have a string as its base type, so it can be used with the functionLinkage function: enum LinkageType : string { D = "D", C = "C", Windows = "Windows", Pascal = "Pascal", Cpp = "C++" } ----- import std.traits; extern(C) void func() { } void main() { enum linkage = functionLinkage!func; static if (linkage == LinkageType.C) { } else static if (linkage == LinkageType.D) { } } ----- -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10875


bearophile_hugs eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc


--- Comment #2 from bearophile_hugs eml.cc 2013-08-23 06:25:57 PDT ---
(In reply to comment #1)

 Actually a reasonable alternative is to simply introduce the LinkageType enum
 which will have a string as its base type, 
This is a nice idea to fix the original design mistake of using strings. Do you know of other functions/templates in Phobos that could enjoy this the same improvement? -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10875



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-08-23
09:22:04 PDT ---
(In reply to comment #2)
 (In reply to comment #1)
 
 Actually a reasonable alternative is to simply introduce the LinkageType enum
 which will have a string as its base type, 
This is a nice idea to fix the original design mistake of using strings. Do you know of other functions/templates in Phobos that could enjoy this the same improvement?
Nothing of the top of my head, but I think there are a few more. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 23 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=10875


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |pull
         AssignedTo|nobody puremagic.com        |andrej.mitrovich gmail.com


--- Comment #4 from Andrej Mitrovic <andrej.mitrovich gmail.com> 2013-09-18
18:27:04 PDT ---
https://github.com/D-Programming-Language/phobos/pull/1587

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