开发者

How does boost::ptr_vector deep copy the underlying objects?

开发者 https://www.devze.com 2023-01-10 09:38 出处:网络
ptr_vecto开发者_StackOverflow中文版r is copy constructible and copy assignable. How can it deep copy the underlying objects when it doesn\'t know their concrete types?The boost::ptr_vector container h

ptr_vecto开发者_StackOverflow中文版r is copy constructible and copy assignable. How can it deep copy the underlying objects when it doesn't know their concrete types?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消