提问人:Bing Lan 提问时间:7/2/2018 最后编辑:seheBing Lan 更新时间:7/3/2018 访问量:329
使用 multiset_of 提升 bimap 查找
Boost bimap find with multiset_of
问:
我对 Boost::bimap 有疑问,无法从 boost 文档中找到答案。
using AToBBimap = boost::bimap< boost::bimaps::unordered_set_of<CString>, boost::bimaps::multiset_of<CString> >; //hashed bimap
using AToBBimapValueT = AToBBimap ::value_type;
AToBBimap bi_map;
bi_map.insert(AToBBimapValueT{"message1", "value"});
bi_map.insert(AToBBimapValueT{"message2", "value"});
bi_map.right.find("value");
问题:看起来只能得到迭代器,是否有可能得到一个同时匹配的列表?bi_map.right.find("value")
{"message1", "value"}
[{"message1", "value"}, {"message2", "value"}]
答:
3赞
Bing Lan
7/2/2018
#1
答案是 ,就像 和 一样。equal_range("value")
std::multiset
std::multimap
该成员返回一对迭代器,它与 Boost 的迭代器范围工厂非常方便地兼容,因此您可以使用它:
for (auto p : boost::make_iterator_range(bi_map.right.equal_range("value")))
do something with p.second;
评论