Possible: Set Operations on Disparate Maps with Same Key Type?
Posted
by Catskul
on Stack Overflow
See other posts from Stack Overflow
or by Catskul
Published on 2010-03-23T22:46:03Z
Indexed on
2010/03/23
23:23 UTC
Read the original article
Hit count: 335
Let's say I have two maps:
typedef int Id;
std::map<Id, std::string> idToStringMap;
std::map<Id, double> idToDoubleMap;
And let's say I would like to do a set operation on the keys of the two maps. Is there an easier way to do this than to create a custom "inserter" iterator? such that I could do something like:
std::set<Id> resultSet;
set_difference( idToStringMap.begin(), idToStringMap.end(),
idToDoubleMap.begin(), idToDoubleMap.end(), resultSet.begin() );
My experimentation results imply that it will be necessary to create a custom inserter and perhaps a custom key comparer to do this, but I want for some insight/shortcut before doing so.
© Stack Overflow or respective owner