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++:为什么结构类需要一个虚拟方法才能成为多态? 2022-10-19
 - 用指数格式表示浮点数 1970-01-01
 - 对 STL 容器的安全并行只读访问 2022-10-25
 - 向量<unique_ptr<A>>使用初始化列表 2022-10-23
 - 迭代std :: bitset中真实位的有效方法? 2022-10-18
 - C++多态 1970-01-01
 - C语言数组 1970-01-01
 - C语言3个整数的数组 1970-01-01
 - 总计将在节日礼物上花多少钱 1970-01-01
 - 明确指定任何或所有枚举数的整数值 1970-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
				
				
				
				