I want to use std::multimap whose Keys and Values are of type GUID. For that, I needed to define comparison operator. Here is the related question.
struct GUIDPairsComparer
{
bool operator()(const GUID &left, const GUID &right) const
{
if (left.Data1 < right.Data1)
return true;
if (left.Data2 < right.Data2)
return true;
if (left.Data3 < right.Data3)
return true;
return false;
}
};
Class A{
private:
multimap<GUID, GUID, GUIDPairsComparer> myMap;
multimap<GUID, GUID, GUIDPairsComparer>::iterator it_myMap;
public:
FunctionUsingMultiMap(){...}
};
But, I have difficulties when using myMap.count(GUID x) and myMap.find(GUID x).
Using myMap.count(GUID x) produces exception, while when I use myMap.find(GUID x) with the GUID element that I know for sure is in the multimap, I get the iterator to the last element in multimap, which means that the given element is not found in multimap.
Do you, by any means, have a clue why is this happening?
Somehow I think it's related to comparison operator I've defined in the structure which afterwards I use for multimap construction, but I don't know exactly why. Also here is a definition of GUID type:
typedef struct _GUID {
unsigned long Data1;
unsigned short Data2;
unsigned short Data3;
unsigned char Data4[ 8 ];
} GUID;
As you can see, I've used Data1, Data2 and Data3 in comparison function, but didn't use Data4 char array since I don't see any logical way to compare that part of GUID.