Is there a (builtin) way to compare the contents of two stl maps? (Assuming of course that the maps have the same data types).

I thought of writing this myself, but iterating through each map and seeing if the contents are found in the other map (and then doing the reverse), but was wondering if this exists already...

>Is there a (builtin) way to compare the contents of two stl maps?
Have you tried the relational operators? Or did you just come running here before attempting anything so that you could waste time waiting for an answer?

All of the operators return bool, I was looking for something that details the differences (ie 'X' appears in map 1 and not in map 2, 'Y' appears in map 2 and not map1, etc.). I wasn't looking for whether or not the whole thing is equal or not...

Then be more specific. Which of the following do you want to do:

1. Find all the x in S that are not in T.
2. Find all the x in S or T that are not in both.
3. Find all the x that are in both S and T.

basically #2.

I know how to write this myself by iterating through each map and checking in the other map to see if it exists, but I figure anything built in would be faster than what I would write.

This article has been dead for over six months. Start a new discussion instead.