So consider this code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
unordered_map<vector<pair<int,int>>,int> mp ;
for(int i=0;i<10;i++)
{
vector<pair<int,int>> v ;
for(int j=0;j<10;j++)
v.push_back(make_pair(j,2*j)) ;
mp[v] = i ;
}
return 0;
}
What I'm doing here is creating an unordered_map
with keys of the type vector<pair<int,int>>
. As you can see here, this raises an error.
But when I change this unordered_map
to just a map
, this error doesn't occur anymore.
That is:
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<vector<pair<int,int>>,int> mp ;
for(int i=0;i<10;i++)
{
vector<pair<int,int>> v ;
for(int j=0;j<10;j++)
v.push_back(make_pair(j,2*j)) ;
mp[v] = i ;
}
return 0;
}
Works well.
So what is with unordered_map
s and putting vector
s in them as keys? What is going on here?