March 12, 2010 [Issue 3941] New: quirks of overloading function templates impede the new operator overloading | ||||
---|---|---|---|---|
| ||||
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: ------- |
January 22, 2012 [Issue 3941] quirks of overloading function templates complicate the new operator overloading | ||||
---|---|---|---|---|
| ||||
Posted in reply to Trass3r | http://d.puremagic.com/issues/show_bug.cgi?id=3941 Andrej Mitrovic <andrej.mitrovich@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED CC| |andrej.mitrovich@gmail.com Resolution| |FIXED --- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-21 17:56:57 PST --- Can't reproduce in 2.057, I guess it's fixed. Reopen if necessary. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation