tezheng wrote:
since std::map is some kind of std::set<std::pair>
can i use "set_difference" with std::map?
how to deal with the "operator =" of std::pair<T1, T2>, as T1 and T2 could
be various type.
set_difference does not use equality
operator. You need to define less than
predicate. this predicate must define
the same ordering as map's key comparator.
iteration from map::begin() to map::end() will
list all elements in ascending order WRT
map's key comparator.
if you wan't to compare the keys only
you could use value_comp member
function from map.
so you can write:
std::set_difference(m1.begin(), m1.end()
, m2.begin(), m2.end(), some_output_iterator
, m1.value_comp());
set_difference stores input into
some_output_iterator. You would ether have to
write one yourself, or use back_inserter
on a list, or a vector, and then manually
insert those elements into your output
map.