Comparing two STL maps..

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Comparing two STL maps..

 
0
  #1
Aug 4th, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Comparing two STL maps..

 
0
  #2
Aug 4th, 2005
>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?
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Comparing two STL maps..

 
0
  #3
Aug 4th, 2005
Go to google, type in "compare C++ maps", and press the I'm Feeling Lucky button.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Comparing two STL maps..

 
0
  #4
Aug 4th, 2005
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...
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 2,039
Reputation: Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice Rashakil Fol is just really nice 
Solved Threads: 139
Team Colleague
Rashakil Fol's Avatar
Rashakil Fol Rashakil Fol is offline Offline
Super Senior Demiposter

Re: Comparing two STL maps..

 
0
  #5
Aug 4th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Comparing two STL maps..

 
0
  #6
Aug 4th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 716
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: Comparing two STL maps..

 
0
  #7
Aug 5th, 2005
You want the symmetric difference of the two maps. Conveniently enough, the standard library provides you with the set_symmetric_difference template function in <algorithm>.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 466
Reputation: winbatch is on a distinguished road 
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: Comparing two STL maps..

 
0
  #8
Aug 6th, 2005
I'll check it out, thanks.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC