我遇到“C++ 标准没有提供此类型的哈希值。”
我使用了 unordered_map 的嵌套映射,如下所示:std::map
需要自定义哈希函数。但为什么呢?
我尝试了不同的组合。
地图到地图作品
unordered_map 映射作品
映射到 unordered_map 没有
unordered_map 到 unordered_map 没有
该模式似乎 unordered_map 不能是内部嵌套结构。
我知道映射可能是红黑树,而 unordered_map 是实际的哈希映射。
看来内部函数不能使用默认的哈希函数。
看参数。
template<
class Key,
class T,
class Compare = std::less<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class map;
std::map
根本不使用哈希,这就是为什么你的“地图中的地图”示例有效。
另一方面,
template<
class Key,
class T,
class Hash = std::hash<Key>,
class KeyEqual = std::equal_to<Key>,
class Allocator = std::allocator<std::pair<const Key, T>>
> class unordered_map;
正在使用
hash
。