提问人:Jordan Palmer 提问时间:11/19/2019 最后编辑:Jordan Palmer 更新时间:11/20/2019 访问量:64
有没有办法强制 (multiset_of<int>,multiset_of<int>) boost::bimap 的每个元素都是唯一的?
Is there a way to force every element of a (multiset_of<int>,multiset_of<int>) boost::bimap to be unique?
问:
我有一个多集 Bimap,如下所示:
6 <--> 71
6 <--> 71
6 <--> 71
8 <--> 71
8 <--> 71
10 <--> 71
10 <--> 74
element = 左键 + 右键,或上面块中的一行
我想删除线条等效于另一条线的元素,例如,我想删除 6 <的两批——> 71。从本质上讲,每个 bimap 元素都必须是唯一的。对于我的用例,左键和右键必须是多组。我还想写这篇文章创建双地图。是否有要求每个元素都唯一的内置函数?如果不是这种情况,有谁知道这样做的好方法?
我使用的最小代码如下:
typedef boost::bimap<boost::bimaps::multiset_of<int>,
boost::bimaps::multiset_of<int>> bimap;
bimap bm;
//fill with elements from two vectors
//vectors have the same size by definition
for(int j = 0; j < matching1.size(); j++){
bm.insert({matching1[j],matching2[j]});
}
答:
0赞
Caleth
11/20/2019
#1
是的。您可以使用 bimap
的第三个参数来约束整个集合。
typedef boost::bimap<boost::bimaps::multiset_of<int>,
boost::bimaps::multiset_of<int>,
boost::bimaps::set_of_relation<>
> bimap;
如果要首先构造具有重复对的双映射,请使用原始定义。您可以从第一个 bimap 初始化第二个 bimap,例如
typedef boost::bimap<boost::bimaps::multiset_of<int>,
boost::bimaps::multiset_of<int>
> bimap;
typedef boost::bimap<boost::bimaps::multiset_of<int>,
boost::bimaps::multiset_of<int>,
boost::bimaps::set_of_relation<>
> unique_bimap;
bimap data = { ... };
unique_bimap uniqued_data { data.begin(), data.end() };
评论
0赞
Jordan Palmer
11/20/2019
谢谢!这正是我想要的
评论