compare std::maps

I have a map like this

Map<std::pair<double, double>, double>. I need to compare two maps of this kind.

I have used a const_iterator as suggested and have something like this

1
2
3
4
5
6
7
Map<pair<double, double>, double>::const_iterator i= data.begin();

for(Map<pair<double, double>, double>::const_iterator j= map.begin();j!=map.end();i++,j++)
       {
         if(*i != *j)
          return false; 
       }


Is this right? I want complete equality and not just key equality.
Last edited on
regular operator== checks complete equality, not just key equality
Thanks for reply

So just
1
2
3
4
if(data == map)
  return true;
else
  return false;
is sufficient?

When would we want to use iterators and when would we use ==?
If I understand correctly, == will do the job if comparing pointers to the same map (I guess it checks sizes and if each element is at the same position). If the maps are different then iterators should be used? If this is correct, is my code any good?
http://en.cppreference.com/w/cpp/container/map/operator_cmp
cppreference wrote:
Checks if the contents of lhs and rhs are equal, that is, whether lhs.size() == rhs.size() and each element in lhs compares equal with the element in rhs at the same position.
Where "each element" is a pair mapping the key to the value, so:
http://en.cppreference.com/w/cpp/utility/pair/operator_cmp
cppreference wrote:
Tests if both elements of lhs and rhs are equal, that is, compares lhs.first with rhs.first and lhs.second with rhs.second
So just mapA == mapB is all you need.
Topic archived. No new replies allowed.