How does the == operator for multimaps behave ?
Hi,
How does the == operator for multimap in STL behave ? I was under the
impression that this is supposed to properly compare multimaps for
equality. It seems that what it actually does is just check if each
member in location L in one multimap is equal to the the member in
location L in the other multimap. The documentation on
http://www.sgi.com/tech/stl/Multimap.html says "Tests two multimaps
for equality. This is a global function, not a member function." and
nothing more.
Am I missing something ?
I have added an illustrative program with output.
Thanks,
Nikhil
#include <iostream>
#include <map>
int main(int argc, char *argv)
{
int numbers[] = {1,2,3,4,5};
std::multimap<int, int> a;
a.insert(std::pair<int, int>(numbers[0], numbers[2]));
a.insert(std::pair<int, int>(numbers[0], numbers[4]));
a.insert(std::pair<int, int>(numbers[1], numbers[3]));
a.insert(std::pair<int, int>(numbers[2], numbers[2]));
a.insert(std::pair<int, int>(numbers[2], numbers[4]));
std::multimap<int, int> b;
b.insert(std::pair<int, int>(numbers[0], numbers[2]));
b.insert(std::pair<int, int>(numbers[0], numbers[4]));
b.insert(std::pair<int, int>(numbers[1], numbers[3]));
b.insert(std::pair<int, int>(numbers[2], numbers[2]));
b.insert(std::pair<int, int>(numbers[2], numbers[4]));
std::cout << "Multimap a and b were found to be ";
if (a == b)
std::cout << "equal.\n";
else
std::cout << "unequal.\n";
std::multimap<int, int> c;
c.insert(std::pair<int, int>(numbers[0], numbers[4]));
c.insert(std::pair<int, int>(numbers[0], numbers[2]));
c.insert(std::pair<int, int>(numbers[1], numbers[3]));
c.insert(std::pair<int, int>(numbers[2], numbers[2]));
c.insert(std::pair<int, int>(numbers[2], numbers[4]));
std::cout << "Multimap a and c were found to be ";
if (a == c)
std::cout << "equal.\n";
else
std::cout << "unequal.\n";
return 0;
}
// Output
//------------------------------------------------------------------------------
// Multimap a and b were found to be equal.
// Multimap a and c were found to be unequal.
//------------------------------------------------------------------------------