ptr_vector
is copy constructible and copy assignable. How can it deep copy the underlying objects when it doesn't know their concrete types?
Copy an Object With Object.assign() was the most popular way to deep copy an object. Object. assign() will copy everything into the new object, including any functions. Mutating the copied object also doesn't affect the original object.
The default copy constructor makes a member-wise copy, and whether a deep or shallow copy is made of a member depends entirely on the behavior of members. struct Person { string firstName, lastName; } - the default copy constructor makes a deep copy.
Deep copy is a process in which the copying process occurs recursively. It means first constructing a new collection object and then recursively populating it with copies of the child objects found in the original. In case of deep copy, a copy of object is copied in other object.
The boost::ptr_vector
container has an optional template parameter, CloneAllocator
, that defines the cloning policy. The default allocator is the heap_clone_allocator
, which simply invokes the copy constructor to clone an object.
The Clone Allocator is used as a way to add a layer of indirection around the cloning. For example, it allows you to provide a custom allocator that correctly handles cloning of a noncopyable type.
You can find more information in the Boost Pointer Containers Library documentation, which explains the Clonable and Clone Allocator concepts.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With