opAddAssign still works

Steven Schveighoffer schveiguy at yahoo.com
Mon May 10 14:48:29 PDT 2010


I just made a startling discovery: the old operator overload routines  
still work in 2.045

Is this intended?


struct S
{
     int x;
     S opAddAssign(ref const S other)
     {
         x += other.x;
         return this;
     }
}

void foo(S s)
{
     s += s;
}

generates no error.

And in fact, neither does this:


struct S
{
     int x;
     S opAddAssign(ref const S other)
     {
         x += other.x;
         return this;
     }

     S opOpAssign(string op)(ref const S other) if (op == "+=")
     {
         static assert(0, "fail!");
     }
}

void foo(S s)
{
     s += s;
}

But if I only have the template version, it does use the template.

-Steve


More information about the Digitalmars-d-learn mailing list