D1 operator overloads have been deprecated.
Bert
Bert at gmail.com
Sun Jul 14 05:26:56 UTC 2019
On Friday, 12 July 2019 at 15:07:11 UTC, Timon Gehr wrote:
> On 12.07.19 15:42, Bert wrote:
>>
>> um, the OP said "works with virtual functions/inheritance".
>> When are people going to learn that aliases are not virtual
>> and have nothing to do with preserving inheritance structure?
>>
>>
>> import std.stdio;
>>
>> class X
>> {
>> }
>> class C : X{
>> int x;
>> this(int x){ this.x=x; }
>> C opAddImpl(C rhs){
>> return new C(x+rhs.x);
>> }
>> alias opBinary(string op:"+")=opAddImpl;
>> }
>> void main(){
>> X a=new C(1),b=new C(2);
>> writeln((a+b).x);
>> }
>>
>> fails.
>
> Please do enlighten us how you would make that work with D1
> operators.
I said nothing about getting it to work. It works
import std.stdio;
abstract class X
{
//abstract X opNeg(); // D1
abstract X opNegImpl(); // D2
alias opUnary(string op : "-") = opNegImpl; // D2
}
class C : X
{
int x;
this(int x) { this.x = x; }
//override C opNeg(){ return new C(-this.x); } D1
override C opNegImpl() { return new C(-x); }
}
void main()
{
X a = new C(1), b = new C(2);
writeln((cast(C)(-b)).x);
}
There is nothing wrong with D1 operators! Unless there is a
deeper problem besides just freeing names, what is being done is
a whole lot of old D code will be broke simply to free opXXX
id's... This type of thing is called *making a small problem much
bigger*.
Maybe the better way would be to convert the D1 op names to
opD1XXX
then at least a simple search and replace can solve 99% of the
problems... of course, there is no real problem because someone
will come along and complain that the id name space is polluted
with opD1XXX's and must be removed... at some point someone has
to stand up and say "It's not an issue but breaking hundreds of
thousands of lines of library code is!".
If you think opD1XXX is too common, then
_op_D1_OLD_OPERATOR_NAME__XXX...
It's irrelevant, but deprecating something just for the hell of
it is wrong and that is what *seems* to be done here(I'm going
off what J.D. said about there being two ways to do the same way,
the old D1 way with fixed opXXX and the new way with opXXX
templates, which, are in fact essentially identical semantically
with a slight syntactical difference... sorta like {} VS BEGIN
and END.)
More information about the Digitalmars-d
mailing list