【发布时间】:2013-08-19 23:43:36
【问题描述】:
std::multimap 和 std::unordered_multimap 多久洗一次条目?我问是因为我的代码传递引用以区分具有相同哈希的条目,并且我想知道何时在它们上运行引用重定向功能。
-
如果我这样做会发生什么:
std::multimap atable; //Type specification stuff left out //Code that pus in two entries with the same key, call that key foo int bar = atable[foo]; 如果是 unordered_multimap,结果会有所不同吗?
回到传递引用以区分具有相同哈希的条目。有没有更安全的方法来做到这一点?
如果我删除其中一个条目,条目是否会移动(这是阅读 std::vector 文档所建议的)?
【问题讨论】:
-
对于
std::unordered_map,真的没有必要乱序,因为它没有排序。 -
考虑到
std::map::operator[]返回引用,我发现它们也不太可能被移动。
标签: c++ c++11 stl unordered-map multimap