To elaborate... what's the point of making everything cheap to copy?

Copying of an object is _not_ an operation like swap() or "move", which are essential to many algorithms.

Indeed, an object might not want to be copyable at all, or it might need to perform some expensive operation (as in Jon's example) in order for the copy to behave like a copy is supposed to.


The only thing that the arbitrary requirement "copies are supposed to be cheap" would do is that it would slow down everything else, forcing checks on operations that shouldn't need to be checked. And it's completely unnecessary unless you're working with reference types, in which case copying is already cheap anyways.


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.

Reply via email to