What's the status of old-style operator overloads in D2?

Steven Schveighoffer via Digitalmars-d digitalmars-d at puremagic.com
Tue Apr 22 07:38:52 PDT 2014


On Tue, 22 Apr 2014 10:21:40 -0400, Andrej Mitrovic  
<andrej.mitrovich at gmail.com> wrote:

> Old-style operator overloads (such as opCom, opAnd, etc) have largely  
> been superseded by new-style templated operator overloads (opUnary,  
> opBinary, etc).
>
> But the old-style operators are not listed on the deprecation page, they  
> don't seem to be planned to be deprecated/removed. I recall a few times  
> people mentioning they might get deprecated at some point.
>
> There's also a bugzilla issue from a year ago asking for warnings when  
> old-style operator overloads are used:
> https://issues.dlang.org/show_bug.cgi?id=10320
>
> E.g. I've wanted to replace old-style operators from Phobos with the  
> new-style ones  
> (https://github.com/D-Programming-Language/phobos/pull/2093), but this  
> brought up some issues w.r.t. the compilation performance when using  
> templates and potential object bloat as well.
>
> The reason I was replacing them is because I was under the impression  
> the old-style operators are going away, and it's best to keep such code  
> out of Phobos or users might end up writing that kind of code too.
>
> I think it's time we get an official stance on this before it's too late.

I filed an enhancement a while ago, that makes it completely feasible to  
have 0-impact forwarding from the new style operators to the existing  
operators. Supposedly it is included since Feb 2013, I haven't ever tested  
it.

See here: https://issues.dlang.org/show_bug.cgi?id=5893

Oh wait look, you were involved :)

I think a "useOldOperators" mixin template would be awesome to have for  
transitioning.

-Steve


More information about the Digitalmars-d mailing list