www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Feature: allow access to lvalue in static operator overloads.

In a previous post I was complaining that I could not access the lvalue in a
static operator overload. I think the reason I was thinking this is because In

parameters lvalue and rvalue, the lvalue must be of the same type as the
contating type. 




        public class Test
        {
            public string Name;

            public static Test operator +(Test lvalue, Test rvalue)
            {
                if (lvalue == null) { lvalue = new Test(); lvalue.Name = "foo";
}
                if (rvalue == null) { rvalue = new Test(); rvalue.Name = "bar";
}

                Console.Write(lvalue.Name);
                Console.Write(rvalue.Name);

                return rvalue;
            }

        }

static void Main(string[] args)
        {
            Test T = null;
            Test B = null;
            T += B;
        }
       

imeplementation of static operator overloads is not very usefull.

What I prepose is that if the programmer specifies the following code:

public class Test
{
    public static Test opAddAssign(Test lvalue, Test rvalue)
    {
       //...
    }

}

When the user writes:

Test a;
Test b;

a += b;

Should compile into:

Test.opCatAssign(a,b);

I have no problem with Non static operator overloads as the lvalue can be
accessed using the this keyword.
Jul 05 2007