D1 operator overloads have been deprecated.

Jonathan M Davis newsgroup.d at jmdavisprog.com
Mon Oct 7 03:23:27 UTC 2019


On Sunday, October 6, 2019 6:28:57 AM MDT uranuz via Digitalmars-d wrote:
> Every time I do something I want to know: what for? Especially,
> if it touches some basic aspects. But still I haven't got any
> answer...

It was the plan to remove the D1 operator overloading functions when the D2,
templated operators were added to the language. The D1 operators have only
been around this long, because no one got around to deprecating them. Having
multiple ways to overload operators complicates the language and provides
almost no benefit. The only thing that you can't do with the templated
operators that you can do with the D1 operators is have them be virtual,
which doesn't matter for the vast majority of D code, since most D code uses
structs rather than classes. And for the code that does use classes and
actually needs the operators to be virtual, it's trivial to just put the
overloaded operator in the base class and then have protected, virtual
functions that the derived classes override. It's what you'd do with the NVI
(non-virtual inheritance) pattern anyway.

So, code that uses classes and needs virtual, overloaded operators is going
to be in the minority, and there's a clear and easy way to use virtual
functions with the templated operators. As such, the extra complication of
having the D1 operators in the language is not considered to be worth it.

- Jonathan M Davis





More information about the Digitalmars-d mailing list