鉴于我有两个 std::map
s,说:
map<int, double> A;
map<int, double> B;
我想得到两张地图的交集,形式如下:
map<int, pair<double,double> > C;
Where the keys are the values in both A
and B
and the value is a pair of the values from A
and B
respectively.有没有使用标准库的干净方法?
原文由 Hooked 发布,翻译遵循 CC BY-SA 4.0 许可协议
我还没有测试过,甚至没有编译过……但它应该是 O(n)。因为它是模板化的,所以它应该适用于任何两个共享相同键类型的映射。