quot;CopyConstructiblequot; requirement for C++ stl container element(“可复制构造C++ stl 容器元素的要求)
问题描述
关于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.
这篇关于“可复制构造"C++ stl 容器元素的要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:“可复制构造"C++ stl 容器元素的要求
- C语言求模 1970-01-01
- 使用来自float.h和limits的数据,找到该系统的一些 1970-01-01
- 运算符优先级 1970-01-01
- C++指向数组的指针 1970-01-01
- 使用最流行的转义序列 1970-01-01
- C++浮点常数 1970-01-01
- 使用整数值初始化char类型的变量 1970-01-01
- “纯虚函数调用"在哪里?崩溃从何而来? 2022-10-18
- C语言可使用的所有转义序列 1970-01-01
- 打印扩展的ASCII字符 1970-01-01