![](/img/trans.png)
[英]What is the difference between std::unordered_map and boost::unordered_map?
[英]What is the difference between these two ways of unordered_map declaration?
以下两种声明方式有什么区别?
unordered_map<int, int> mp;
auto umap = unordered_map<int, int>{};
和优化有关系吗?
对于unordered_map
它不会有什么不同,因为 c++17。
如果类型是例如聚合类型,则会有所不同。
因此,如果您有std::array
,则会有不同的结果:
std::array<int, 4> a1;
auto a2 = std::array<int, 4>{};
a1
将包含不确定的值。
另一方面,它们是相等的:
std::array<int, 4> a1{};
auto a2 = std::array<int, 4>{};
所以使用auto var = some_type{};
(也称为“几乎总是自动模式”)将确保您不会忘记初始化变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.