I have two multimaps.i would like to create a new multimap which has the common key-value pairs in the given those two multimaps:
for eg:
#include &l
Use the std::set_intersection function template from
std::multimap newMap;
std::set_intersection(map1.begin(), map1.end(),
map2.begin(), map2.end(),
std::inserter(newMap, newMap.begin());
Edit Yeah, apparently this doesn't work for a multimap as it would for a map. I suggest the following:
std::multimap newMap;
std::vector::value_type> v1(map1.begin(), map1.end());
std::sort(v1.begin(), v1.end());
std::vector::value_type> v2(map2.begin(), map2.end());
std::sort(v2.begin(), v2.end());
std::set_intersection(v1.begin(), v1.end(),
v2.begin(), v2.end(),
std::inserter(newMap, newMap.begin());