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

           Summary: array/slice assignment causes destruction + postblit
                    instead of opAssign
           Product: D
           Version: unspecified
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nob...@puremagic.com
        ReportedBy: monarchdo...@gmail.com


--- Comment #0 from monarchdo...@gmail.com 2012-11-01 10:10:38 PDT ---
Basically, given two static arrays of S, or when calling array opSliceAssign,
I'd expect the assignment to trigger element-wise assignment.

However, what happens is that the elements of the original array are destroyed,
and then postblit copies are copied over, element by element:

//----
import std.algorithm;
import std.stdio;

struct S
{
    int i;
    this(this){"post: ".writeln(i);}
    void opAssign(S){"opAssign".writeln();}
    ~this(){"dest: ".writeln(i);}
}

void main()
{
    S[2] a = [S(1), S(2)];
    S[2] b = [S(3), S(4)];
    "begin".writeln();
    a = b;
    "end".writeln();
}
//----
post: 1
post: 2
post: 3
post: 4
begin
post: 3
dest: 1
post: 4
dest: 2
end
dest: 4
dest: 3
dest: 4
dest: 3
//----

opSlice/opSlice assignement will produce the same effect:
//----
void main()
{
    S[] a = [S(1), S(2)];
    S[] b = [S(3), S(4)];
    "begin".writeln();
    a[] = b[];
    "end".writeln();
}
//----

destruction+postblit is not the same as opAssign, so if this is an
"optimization", it is wrong.

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

Reply via email to