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++ #define 1970-01-01
- end() 能否成为 stl 容器的昂贵操作 2022-10-23
- 明确指定任何或所有枚举数的整数值 1970-01-01
- 分别使用%o和%x以八进制或十六进制格式显示整 1970-01-01
- 使用scanf()读取字符串 1970-01-01
- C语言访问数组元素 1970-01-01
- 初始化变量和赋值运算符 1970-01-01
- C++按值调用 1970-01-01
- C++定义类对象 1970-01-01
- C++输入/输出运算符重载 1970-01-01