map of tuples and unordered_map of tuples

发布时间 2023-07-26 17:46:17作者: xuyv

由于c++ map和unordered_map的底层实现不同,因此对tuples 作为key的支持情况也不同。

map是二叉树实现的,因此tuple as key比较容易实现,c++也是支持的。

unordered_map是hash实现的,hash一个tuple就不太容易了,c++貌似不支持,同样值的hash会造成不同的值。

 

如果想在unordered_map里面使用tuple as key,需要自行指定hash函数。

如下:

https://blog.csdn.net/pineappleKID/article/details/108341064

 

参考:

How to create an unordered_map of tuples in C++? - GeeksforGeeks

 

Map of Tuples in C++ with Examples - GeeksforGeeks