Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设有一张地图:typedef map<int, string> MyMap;
typedef map<int, string> MyMap;
我想通过字符串遍历它,例如:
3 -> a 1 -> b 7 -> b 2 -> c
一种方法是按其值对该地图进行排序。但我担心这会对 find() 效率产生影响(是真的吗?)
另一种选择是使用boost::bimap. 但是,您可能会注意到,MyMap 中的值不是唯一的,因此 bimap 在这里不适用。
boost::bimap
有什么好的方法吗?
我找到了在 boost.bimap 中使用多个值的解决方案:multiset_of
multiset_of
数据定义更改为:
#include <boost/bimap/multiset_of.hpp> typedef boost::bimap<int, boost::bimaps::multiset_of<std::string> > MyMap;
现在我可以通过键或值来遍历我的数据。