[Issue 7552] New: Cannot get and combine a part of overloaded functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Mon Feb 20 04:47:56 PST 2012


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

           Summary: Cannot get and combine a part of overloaded functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody at puremagic.com
        ReportedBy: k.hara.pg at gmail.com


--- Comment #0 from Kenji Hara <k.hara.pg at gmail.com> 2012-02-20 04:47:55 PST ---
Extracting a function symbol from overloads by __traits(getOverloads), and
combining them by alias declaration should generate new overloads. See
following code.

----
template TypeTuple(T...){ alias T TypeTuple; }
template Id(      T){ alias T Id; }
template Id(alias A){ alias A Id; }

struct S
{
    static void foo(){}
    static void foo(int){}
}

struct T
{
    alias TypeTuple!(__traits(getOverloads, S, "foo")) FooInS;
    alias FooInS[0] foo;    // should be S.foo()
    static void foo(string){}
}

struct U
{
    alias TypeTuple!(__traits(getOverloads, S, "foo")) FooInS;
    alias FooInS[1] foo;    // should be S.foo(int)
    static void foo(string){}
}

void main()
{
    alias TypeTuple!(__traits(getOverloads, S, "foo")) FooInS;
    static assert(FooInS.length == 2);
                                      FooInS[0]();
    static assert(!__traits(compiles, FooInS[0](0)));
    static assert(!__traits(compiles, FooInS[1]()));
                                      FooInS[1](0);

                                      Id!(FooInS[0])();
    static assert(!__traits(compiles, Id!(FooInS[0])(0)));
    static assert(!__traits(compiles, Id!(FooInS[1])()));
                                      Id!(FooInS[1])(0);

    alias TypeTuple!(__traits(getOverloads, T, "foo")) FooInT;
    static assert(FooInT.length == 2);                  // fail
                                      FooInT[0]();
    static assert(!__traits(compiles, FooInT[0](0)));
    static assert(!__traits(compiles, FooInT[0]("")));
    static assert(!__traits(compiles, FooInT[1]()));
    static assert(!__traits(compiles, FooInT[1](0)));   // fail
                                      FooInT[1]("");    // fail

    alias TypeTuple!(__traits(getOverloads, U, "foo")) FooInU;
    static assert(FooInU.length == 2);
    static assert(!__traits(compiles, FooInU[0]()));
                                      FooInU[0](0);
    static assert(!__traits(compiles, FooInU[0]("")));
    static assert(!__traits(compiles, FooInU[1]()));
    static assert(!__traits(compiles, FooInU[1](0)));
                                      FooInU[1]("");
}
----

-- 
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