I have defined an unordered_map like this
struct pht {
pht(int t, vector<bool> pat)
: tag(t), pattern(32) {}
private:
int tag;
vector<bool> pattern;
};
unordered_map< pair<int, int>, pht > predictor;
int main()
{
int pc, addr, offset, tag;
vector<bool> pat;
srand(time(0));
tag = 1000; pc = 100; offset = 10;
for ( int i = 0; i < 32; i++ )
pat.push_back( rand() % 2 );
predictor.insert(make_pair( make_pair(pc, offset), pht(tag, pat) ) );
return 0;
}
However I get this error:
(UPDATED)
error C2440: 'type cast' : cannot convert from 'const std::pair<_Ty1,_Ty2>' to 'size_t'
how can I fix that?
The error message is misleading; the real reason is that there’s no
std::hashspecialisation forstd::pair<int, int>which is required byunordered_map. You need to either provide this specialisation or (recommended) create anunordered_mapwhich specifies a custom hasher:And then declare the map as: