[Issue 5893] Allow simple aliases for operator overloading

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 21 18:19:22 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5893


Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich at gmail.com


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-01-21 18:19:18 PST ---
Hows this for a workaround:

import std.traits;

class C
{
    void concatAssign(C other) { }
    void concatAssign(int other) { }

    auto ref opOpAssign(string s, T)(T t) if (s == "~")
    {
        static if (is(ReturnType!concatAssign == void))
            concatAssign(t);
        else
            return concatAssign(t);
    }
}

void main()
{
    auto c = new C;
    c.opOpAssign!"~"(c); // works
    c.opOpAssign!"~"(1); // works
    c ~= 1;              // works
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list