D1 operator overloads have been deprecated.

Daniel N no at public.email
Mon Jul 15 08:43:59 UTC 2019


On Monday, 15 July 2019 at 08:07:37 UTC, Alexandru Ermicioi wrote:
> On Monday, 15 July 2019 at 08:00:26 UTC, Alexandru Ermicioi 
> wrote:
>> On Sunday, 14 July 2019 at 05:27:28 UTC, Bert wrote:
>>> In the new way we have to have an alias redirector and the 
>>> function rather than just the function. All we end up getting 
>>> is freeing a member id name and a whole lot of broken code.
>>

Just forward to the legacy D1 name.
*) Only have to change base class
*) Backwards and forwards compatible

import std.stdio;

abstract class X
{
     abstract X opNeg(); // D1
     alias opUnary(string op : "-") = opNeg; // D2
}

class C : X
{
     int x;
     this(int x) { this.x = x; }
     override C opNeg() { return new C(-x); }

}

void main()
{
     X a = new C(1), b = new C(2);
     writeln((cast(C)(-b)).x);
}


More information about the Digitalmars-d mailing list