“CopyConstructible”需要C ++ stl容器元素 [英] "CopyConstructible" requirement for C++ stl container element
问题描述
关于对C ++ stl容器元素的要求,标准说:元素类型应该是CopyConstructible,并且有一个表用于CopyConstructible需求。还有各种书(Josuttis等),生成的副本应该是等同于源。
Regarding to the requirement for C++ stl container element, the standard says: the element type should be CopyConstructible, and there is a table for CopyConstructible requirements. Also by various books (Josuttis, etc.), the generated copy should be "equivalent to" the source.
我想我需要一些清楚。什么是等同于?另外,我有点困惑的CopyConstructible和深/浅拷贝之间的关系。通常,复制构造函数是浅复制或深复制。那么哪一个适用于CopyConstructible,哪一个不适用?
I think I need some clarity here. What is exactly "equivalent to"? Also I am a bit confused with the relation between the "CopyConstructible" and the "deep/shallow copy". In general, a copy constructor is either shallow copy or deep copy. So which one applies to the "CopyConstructible", and which does not?
感谢任何意见!
推荐答案
深或浅拷贝都工作。例如, shared_ptr
总是做一个浅拷贝(有一些额外的引用计数的东西),你可以在容器中使用它们很好。这取决于复制操作的语义。
Deep or shallow copy both work. For instance, shared_ptr
always does a shallow copy (with some extra reference counting stuff), and you can use them in containers just fine. It depends on the semantics of copy-operation.
等效意味着您的程序不应该依赖于它是与原件还是与副本一起工作。
Equivalent means your program should not depend on whether it works with the original or with the copy.
这篇关于“CopyConstructible”需要C ++ stl容器元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!