[英]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.