digitalmars.D.bugs - [Issue 3941] New: quirks of overloading function templates impede the new operator overloading
- d-bugmail puremagic.com Mar 12 2010
http://d.puremagic.com/issues/show_bug.cgi?id=3941 Summary: quirks of overloading function templates impede the new operator overloading Product: D Version: 2.041 Platform: All OS/Version: All Status: NEW Keywords: rejects-valid Severity: normal Priority: P2 Component: DMD AssignedTo: nobody puremagic.com ReportedBy: mrmocool gmx.de --- Comment #0 from Trass3r <mrmocool gmx.de> 2010-03-12 13:43:48 PST --- struct Vector2(T) { T x; T y; /// element-wise operations, +, -, Vector2 opBinary(string op)(ref Vector2 v) { mixin("return Vector2!(T)( cast(T)(x " ~ op ~ " v.x), cast(T)(y " ~ op ~ " v.y) );"); } /// operation with scalar Vector2 opBinary(string op)(int i) { mixin("return Vector2!(T) ( cast(T)(x " ~ op ~ " i), cast(T)(y " ~ op ~ " i) );"); } } void main() { auto v = Vector2!(float)(0f,0f) + Vector2!(float)(1f,1f); } yields: template instance opBinary!("+") matches more than one template declaration This can be worked around with: opBinary(string op, U:Vector2)(U v) opBinary(string op, U:int)(U v) Solutions could be: (1) Something like template fn(string op) { fn(args1) {...} fn(args2) {...} } could work if a + b was rewritten as x.opBinary!("+").opBinary(b); (2) the best solution would of course be to detect such function template overloads directly! -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Mar 12 2010








d-bugmail puremagic.com