October 06, 2019
On Sunday, 6 October 2019 at 12:28:57 UTC, uranuz wrote:
> On Sunday, 6 October 2019 at 10:39:04 UTC, Gregor Mückl wrote:
>> You only need this workaround if you habe a class hierarchy where overloaded operators are
>> overridden in subclasses. This is a very narrow set of cases. Otherwise, implementing only the D2 way is sufficient. How often do you actually need to override operator behaviour in subclasses? I'm genuinely curious about use cases.
>
> Personally, I have several places in my code where I need to add `in` into basic interface and implement it in derived classes. It is not some "weird", "narrow" set of cases, I believe.
> For instance, I have different implementations of `in` in all of these classes.

What is your use case for an in operator that changes in derived classes?
October 06, 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



October 07, 2019
On Monday, 7 October 2019 at 03:23:27 UTC, Jonathan M Davis wrote:
...
> 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.

Thanks. Understood. The problemme is just that this solution feels like some ugly hack (in Russian language we call it "костыль"). But seems that there is nothing to do with this already. No matter...
1 2 3
Next ›   Last »