On Sunday, December 09, 2012 21:02:14 Mehrdad wrote:
> So basically, algorithms should _expect_ copying of arbitrary
> objects to be expensive, and there's no need for them to be
> otherwise. C++'s swap() illustrates the lack of the need for
> copying beautifully -- often times the only objects I copy
> "generically" in C++ are iterators. I never find the need to copy
> other objects... and I believe D has no such need, either.

It's been a debate for some time whether Phobos should be able to rely on 
copying being cheap. Algorithms end up copying all the time, and it greatly 
simplifies things if you don't have to worry about copying being expensive. 
Being able to rely on copying being O(1) is something that Andrei has tried to 
push for, but I don't see how we really can given simple things like the need 
to dup arrays - though I can see arguing that it's up to the caller to make 
copying cheap if they want certain algorithms to be more efficient.

The whole reason that the move* primitives were introduced was to try and 
combat expensive copying, but they complicate things a fair bit and rarely get 
used, even if they should be.

D's move semantics also help, but ultimately, some things are just plain going 
to be expensive to copy, and I don't see how you can get around that without 
disallowing certain idioms, which would then cause a different set of problems.

- Jonathan M Davis

Reply via email to