boost :: ptr_vector如何深度复制基础对象? [英] How does boost::ptr_vector deep copy the underlying objects?
问题描述
ptr_vector
是可复制构造的和可复制分配的.当不知道基础对象的具体类型时,如何深层复制基础对象?
ptr_vector
is copy constructible and copy assignable. How can it deep copy the underlying objects when it doesn't know their concrete types?
推荐答案
boost :: ptr_vector
容器具有可选的模板参数 CloneAllocator
,用于定义克隆策略.默认分配器是 heap_clone_allocator
,它仅调用复制构造函数来克隆对象.
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.
您可以在 Boost Pointer Containers中找到更多信息.库文档,说明了可克隆和克隆分配器的概念.
You can find more information in the Boost Pointer Containers Library documentation, which explains the Clonable and Clone Allocator concepts.
这篇关于boost :: ptr_vector如何深度复制基础对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!