问题描述
使用具有两个字段和一对字段的结构在内存分配和效率方面有什么区别?
What is the difference regarding memory allocation and efficiency between using a struct with two fields and a pair?
推荐答案
std::pair 提供预先编写的构造函数和比较运算符.这也允许它们存储在 std::map 之类的容器中,而无需编写,例如,复制构造函数或通过 operator < 的严格弱排序(例如 std 所要求的::地图).如果你不写它们,你就不会犯错(还记得严格弱排序是如何工作的吗?)所以使用 std::pair 更可靠.
std::pair provides pre-written constructors and comparison operators. This also allows them to be stored in containers like std::map without you needing to write, for example, the copy constructor or strict weak ordering via operator < (such as required by std::map). If you don't write them you can't make a mistake (remember how strict weak ordering works?) so it's more reliable just to use std::pair.
这篇关于使用具有两个字段和一对字段的结构有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)