简体   繁体   中英

map (vs) unordered_map with pair as key

This produces compiler error

unordered_map<pair<int,int>,int> umap;

I understand that a hash function must be provided for it to work.

But

map<pair<int,int>,int> omap;

works perfectly without any hash function.

Why is that so?

std::map does not use a hash function. Rather, its "keys are sorted by using the comparison function..." where "search, removal, and insertion operations have logarithmic complexity.". Lookup is done by traversing a search tree rather than via hashing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM