D1 operator overloading in D2

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Mar 30 08:25:01 PDT 2015


On 3/30/15 1:42 AM, ketmar wrote:
> it's still working. moreover, it is used in Phobos! and yet it's not
> documented anywhere. what i want to know is whether they will be removed
> for good, or brought back and properly documented? the current situation
> is awful: compiler has special treatment for some aggregate members, but
> nothing in documentation tells you that.
>

They technically can be removed for good, because an operator template 
can now be an alias (this was pretty recent, maybe 1 year ago?). There 
is still one thing that doesn't work right I think -- covariance.

But doing so would break all code that uses it. I think at the very 
least, Phobos should replace all D1-style operators with D2 style. 
Dogfooding and all. Originally when the "yay, look at these new 
template-style operators" was posted, it was imagined that one could do:

mixin(generateD2Operators);

in your aggregate, and the links from the new style operators to the old 
style would give you an upgrade path without having to rewrite all your 
operators. This really wasn't possible until the alias update. But maybe 
it's time to add this to std.typecons.

I think at the very least we should provide a link to the D1 
documentation and say that "D1 operators overloads are still supported, 
but their support is not guaranteed to continue, please use D2 operators 
wherever possible."

Clearly, there is some work that should be done. I agree that if you 
come across old code, and you are unaware of the old style operators, 
you will be super-confused as to how the operators are even working. 
That can be very annoying.

I'll put in a doc PR to reference the D1 documentation.

-Steve


More information about the Digitalmars-d-learn mailing list