--- Comment #5 from Kenji Hara <> 2011-09-20 08:07:19 PDT ---
(In reply to comment #4)
> > 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.

In B's constructor, the member a is already intialized by A.init. So `a =
A(dummy);` is always assignment.

And, yes, I think using emplace is right way to *initialize* member a.

emplace(&a, dummy);  // a is treated as an uninitialized memory

But, unfortunately, emplace has a bug. This does not work as our expected.

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

Ah... my explanation had a bit misleading. When opAssign receives rvalue, rhs
is just moved. Otherwise, rhs is coped. In this case, A(dummy) is treated as
rvalue, so it is moved.

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

Reply via email to