www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 11500] New: Bringing mixed-in operators and constructors to the overload set

reply d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11500

           Summary: Bringing mixed-in operators and constructors to the
                    overload set
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: tommitissari hotmail.com



We can bring mixed-in methods to the desired overload set, but 
not operators or constructors. Here's what I mean:

mixin template methodMix()
{
    void foo(int n) { }
}

mixin template operatorMix()
{
    void opBinary(string op)(int n) { }
}

mixin template ctorMix()
{
    this(int n) { }
}

struct MethodTest
{
    mixin methodMix mix;

    alias foo = mix.foo;

    void foo(string s) { }
}

struct OperatorTest
{
    mixin operatorMix mix;

    alias opBinary = mix.opBinary;

    void opBinary(string op)(string s) { } // [1]
}

struct CtorTest
{
    mixin ctorMix mix;

    // If only I could do the following to bring the
    // mixed-in constructor to the overload set:
    //alias this = mix.this;

    this(string s) { }
}

void main()
{
    MethodTest mt;
    mt.foo(3);

    OperatorTest ot;
    ot + 3;

    auto ct = CtorTest(3); // [2]
}
-----------------
1. Error: template test.OperatorTest.opBinary(string op)(string s) conflicts
with alias test.OperatorTest.opBinary
2. Error: constructor test.CtorTest.this (string s) is not callable using
argument types (int)

-- 
Configure issuemail: https://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 11 2013
parent d-bugmail puremagic.com writes:
https://d.puremagic.com/issues/show_bug.cgi?id=11500


Tommi <tommitissari hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|enhancement                 |normal


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