【发布时间】:2021-11-18 14:37:25
【问题描述】:
map<pair<int,int>, int> 可以编译,但 unordered_map<pair<int,int>> 存在哈希函数问题。背后到底发生了什么?
【问题讨论】:
-
C++ 有一个内置的
operator<用于配对(字典顺序,假设配对的类型支持通过operator<进行比较),但它没有内置的配对哈希和元组。所以你可以在maps 中使用它们,但不能在unordered_maps 中使用它们。不确定为什么没有用于对和元组的内置散列 - 很难找到平衡速度和散列质量的“正确”默认值? -
这与 Rcpp 无关,所以请删除标签(我现在不能这样做,因为有待批准的编辑)。
-
重复:Why can't I compile an unordered_map with a pair as key?、Why did the C++ standards committee not include std::hash for pair and tuple?、Why does std::map accept a std::pair as key, but std::unordered_map does not?、Why can't I compile an unordered_map with a pair as key?、
pair<int,int>pair as key of unordered_map issue
标签: c++ hash unordered-map