Thread overview
[Issue 2444] New: structs should allow calling the normal blitting function when overriding opAssign
Nov 06, 2008
d-bugmail
Jan 11, 2009
d-bugmail
Dec 02, 2012
Andrej Mitrovic
November 06, 2008
http://d.puremagic.com/issues/show_bug.cgi?id=2444

           Summary: structs should allow calling the normal blitting
                    function when overriding opAssign
           Product: D
           Version: 2.019
          Platform: PC
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: schveiguy@yahoo.com


In D1, if I overload opAssign in a struct, I cannot create an overload that takes the struct as an argument.  This is marked as illegal.

However, in a recent version of D2 (not sure which one), this became legal. However it has a bad side effect.  If I want to overload opAssign for an argument other than the struct, for example an int, then it masks the overload that just does the blitting.  I have to re-implement the blitting version.

I understand that an author may want to control opAssign to the point of disallowing simple blitting copy.  But if desired, it is a PITA to do the blitting manually.  It would be nice to be able to alias the original function, or flag the struct somehow so that the compiler will use the blitting function when assigning one struct to another.


-- 

January 11, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=2444


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |smjg@iname.com
           Severity|normal                      |enhancement




-- 

December 02, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=2444


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

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


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-12-01 16:21:12 PST ---
I think you can implement this now as:

struct Foo
{
    void opAssign(const Foo rhs)
    {
        this.tupleof = rhs.tupleof;
    }
}

Maybe it should be added to the docs.

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