I've the following C++ code:
struct MyStruct
{
int a[2];
int b[2];
};
std::map<std::pair<int, int> , MyStruct*> MyMap;
Now I run this loop on MyMap:
for(std::map<std::pair<int, int> , MyStruct*>::iterator itr = MyMap.begin(); itr != MyMap.end(); ++itr)
{
std::pair<int, int> p (itr->first().second, itr->first().first);
auto i = MyMap.find(p);
if(i != MyMap.end())
{
//do something
}
}
What I'm actually trying to do is forming a pair by swapping the elements of another pair , so for example I have a key pair(12,16) in MyMap and also another key pair(16,12); these two key exists in MyMap and I know for sure. But when I apply the above technique MyMap don't return the value corresponding to the swapped key, what I'm guessing that MyMap.find(p) is matching the pointer of Key; but is there a way so that I can force MyMap.find(p) to match the corresponding value in Key (pair) instead of matching the pointers in Key (pair) ? Or is there anything I'm doing wrong here ?