ptr_vector is copy constructible and copy assignable. How can it deep copy the underlying objects when it doesn't know their concrete types?
views:
77answers:
1
+4
A:
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.
James McNellis
2010-08-07 02:51:03
Ah -- so I need to support the clonable concept even if my object is copy-constructable? The docs seem to mention only clonable when the object is not.
Billy ONeal
2010-08-07 19:35:33
@Billy: That's my understanding of it. I've not used `ptr_vector` extensively, but that is how other pointer containers I've used handle cloning.
James McNellis
2010-08-07 20:02:05