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: nob...@puremagic.com
        ReportedBy: mrmoc...@gmx.de


--- Comment #0 from Trass3r <mrmoc...@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: -------

Reply via email to