www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - new operator overloading buggy?

reply Trass3r <un known.com> writes:
Guess it's better to post this here. Are these some bugs or is there another
problem?

the following code strangely yields:
dsfml\system\vector2.d(47): Error: variable
dsfml.system.vector2.Vector2!(float).Vector2.op only parameters or foreach
declarations can be ref

/// element-wise operations, +, -, 
ref Vector2 opBinary(string op)(ref Vector2 v)
{
        mixin("return Vector2!(T)( cast(T)(x " ~ op ~ " v.x), cast(T)(y " ~ op
~ " v.y) );");
}

Removing ref from the return type makes it compile.


Furthermore the assignment operator seems to be rewritten as opBinary instead
of opAssign as the docs state:

Vector2f        _pos = Vector2f(0.f, 0.f);
yields:
Error: template instance opBinary!("=") matches more than one template
declaration


This also shows another problem. It can't distinguish between these two:
Vector2 opBinary(string op)(ref Vector2 v)
if (op != "*")
{
        mixin("return Vector2!(T)( cast(T)(x " ~ op ~ " v.x), cast(T)(y " ~ op
~ " v.y) );");
}

Vector2 opBinary(string op)(int i)
{
        mixin("return Vector2!(T) ( cast(T)(x " ~ op ~ " i), cast(T)(y " ~ op ~
" i) );");
}

even though vec1 + vec2 resp. vec + 5 is unambiguous.
Mar 08 2010
parent reply Walter Bright <newshound1 digitalmars.com> writes:
Trass3r wrote:
 Guess it's better to post this here. Are these some bugs or is there another
problem?
Can you please do these as complete code snippets? The reason I ask is because over and over, when I have to guess at the "obvious" rest of the code, the rest of the code turns out to be where the problem was.
Mar 13 2010
parent reply Trass3r <un known.com> writes:
 Can you please do these as complete code snippets?

 The reason I ask is because over and over, when I have to guess at the  
 "obvious" rest of the code, the rest of the code turns out to be where  
 the problem was.
I understand. Thanks for your answer. 2nd issue is now: http://d.puremagic.com/issues/show_bug.cgi?id=3935 3rd issue has become: http://d.puremagic.com/issues/show_bug.cgi?id=3941 need to have a look at the first one when I get some time. I spent much too much time in the dmd frontend yesterday ^^
Mar 13 2010
parent Walter Bright <newshound1 digitalmars.com> writes:
Trass3r wrote:
 2nd issue is now: http://d.puremagic.com/issues/show_bug.cgi?id=3935
 
 3rd issue has become: http://d.puremagic.com/issues/show_bug.cgi?id=3941
Perfect. Thanks!
Mar 13 2010