Assigning A to B without B destroying all the allocations...

Started by
9 comments, last by King Mir 11 years, 2 months ago

Why would you want the container copying to exchange ownership? Similarly, using shared pointers doesn't make sense, because changes to the copy will affect the original. For a container, copying should generally deep-copy every element.
Copy on write semantics can also be useful, as an optimization. Or just don't allow copying.

It's true that the default copy operatations wouldn't work if your class holds unique pointers, but you can still write copy operations that do the right thing yourself. Alternatively, you could write your own smart pointer that has the right copy semantics, and an efficient move. I suspect in this case the way to go is to just modify the contained object to have move semantics.

This topic is closed to new replies.

Advertisement