Copying reference types by value

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Thu Apr 18 06:22:41 PDT 2013


On 04/17/2013 10:29 PM, Ali Çehreli wrote:
> Yes but as I said I am not sure how useful or needed this whole thing is.
> 
> The language handles copy, move, and assignment for structs. takeOver() seems to
> be a primitive operation for classes.

Could you expand a bit on that?  Just that I'm not sure I understand your
meaning completely, and I'm curious. :-)

> That's what I meant by "a wrapper function." But I think move is a more
> fundamental operation that elides a copy. If we had only copyFrom(), then the
> following would indeed need to copy:
> 
>     // foo() returns a class object
>     a.copyFrom(foo());
> 
> On the other hand, takeOver() would have the ability to move the members of the
> returned rvalue object without needing to copy.

OK, clear.  In fact seems possible that copying vs. takeover might be useful to
define separately and use whichever is optimal for the given use-case.

> Agreed.

I'd assumed this problem would be some fairly straightforward aspect of the
language that I just wasn't familiar with, so I'm quite struck by the fact that
it actually seems a non-trivial problem.



More information about the Digitalmars-d-learn mailing list