--- Comment #4 from Dmitry Olshansky <> 2011-09-20 
07:37:10 PDT ---
> Please note this line:
> >         a = A(dummy); // a(dummy) was a typo, thought it changes nothing
> This is "assignment", not initializing.
> The assignment of an object that has postblit (like A) is implemented *swap 
> and
> destroy*. 

Note this line was in constructor. No way to initialize member of a struct?
That's something I'd call unacceptable.

I should point out that move == swap & destroy, iff left side of assigment
_was_ initialized. A constructor may be called on chunk of uninitialized memory
e.g. in Phobos std.typecons.emplace.

> For this purpose, D compiler implements opAssign implicitly, like
> follows:
> struct A {
>   ...
>   ref A opAssign(A rhs) {  // rhs is copyed from original value

why do we copying the original value in the first place? 
It should be moved with e.g. memmov

>     std.algorithm.swap(this, rhs);  // bitwise swapping
>     return rhs;
>     // rhs is equals to original 'this', and it is destroyed here.
>   }
> }

> Therefore, the assignment of an object of A always increment A.dtor.

Thanks, that clarifies it in part, but still how about initialization in

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to