Without D1-style operator overloads, the `in` operator for classes doesn't make sense
Don
prosthetictelevisions at teletubby.medical.com
Mon Jan 6 10:55:15 UTC 2020
In DMD 2.088.0, the D1 operator overloads were deprecated, in
favour of the D2 syntax which has been available for years.
For example, opAdd_r is replaced with opBinaryRight(string
op)(...) if (op == "+")
But this is not purely a syntactic change. Some functionality is
lost: the D2 syntax is a template; and therefore, it is not a
virtual function.
It was argued that using virtual functions for operators is an
obscure feature which hardly anybody would use. So it is not a
significant loss. And I agree with that, *for the operators which
D inherited from C*.
Unfortunately, this argument is not valid for two operators which
are unique to D: opCat and opIn. The problem is most acute with
the `in` operator.
Suppose you make an object-oriented container class library.
Let's say you have a Set. This may have derived classes HashSet,
BloomFilterSet, etc.
One of the most basic operations is asking if an element is a
member of the set. For sure you would want to use the `in`
operator. But you can't, because it isn't virtual.
So, I think we've got ourselves into a situation which doesn't
make sense. It's pretty much always a mistake to define a
D2-style 'in' operator for a class. If you are using classes, you
would want it to be virtual; if you don't need it to be virtual,
you shouldn't be using classes.
So I feel that by introducing this deprecation, we've dropped
support for OOP container classes.
If this is part of a grand conspiracy to remove classes from D, I
won't stand in the way :) But apparently we've done this by
accident, which is rather alarming.
More information about the Digitalmars-d
mailing list