www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature request: Bringing mixed-in operators and constructors to the

reply "Tommi" <tommitissari hotmail.com> writes:
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)
Nov 10 2013
parent reply "Tommi" <tommitissari hotmail.com> writes:
Filed an enhancement request:
https://d.puremagic.com/issues/show_bug.cgi?id=11500
Nov 11 2013
parent reply "deadalnix" <deadalnix gmail.com> writes:
On Monday, 11 November 2013 at 21:58:44 UTC, Tommi wrote:
 Filed an enhancement request:
 https://d.puremagic.com/issues/show_bug.cgi?id=11500
Everything should work the same way.
Nov 11 2013
parent reply "Tommi" <tommitissari hotmail.com> writes:
On Tuesday, 12 November 2013 at 01:17:20 UTC, deadalnix wrote:
 On Monday, 11 November 2013 at 21:58:44 UTC, Tommi wrote:
 Filed an enhancement request:
 https://d.puremagic.com/issues/show_bug.cgi?id=11500
Everything should work the same way.
Do you mean that what I'm reporting is a compiler-bug rather than a feature request?
Nov 19 2013
parent reply Timon Gehr <timon.gehr gmx.ch> writes:
On 11/19/2013 11:13 AM, Tommi wrote:
 On Tuesday, 12 November 2013 at 01:17:20 UTC, deadalnix wrote:
 On Monday, 11 November 2013 at 21:58:44 UTC, Tommi wrote:
 Filed an enhancement request:
 https://d.puremagic.com/issues/show_bug.cgi?id=11500
Everything should work the same way.
Do you mean that what I'm reporting is a compiler-bug rather than a feature request?
I'd argue yes, but similar issues have surprisingly attracted some controversy in the past. (The constructor aliasing is an enhancement though as it extends the language grammar.)
Nov 19 2013
parent "Tommi" <tommitissari hotmail.com> writes:
On Tuesday, 19 November 2013 at 22:51:10 UTC, Timon Gehr wrote:
 On 11/19/2013 11:13 AM, Tommi wrote:
 On Tuesday, 12 November 2013 at 01:17:20 UTC, deadalnix wrote:
 On Monday, 11 November 2013 at 21:58:44 UTC, Tommi wrote:
 Filed an enhancement request:
 https://d.puremagic.com/issues/show_bug.cgi?id=11500
Everything should work the same way.
Do you mean that what I'm reporting is a compiler-bug rather than a feature request?
I'd argue yes, but similar issues have surprisingly attracted some controversy in the past. (The constructor aliasing is an enhancement though as it extends the language grammar.)
Hmmm... decisions decisions. I changed it from enhancement to bug (normal priority) anyway.
Nov 19 2013