mardi 24 janvier 2023

Unordered map where key is a pair

I have an unordered map where my key is a pair of <int, const Foo*> and value is a vector. I do not see any compilation or runtime error during insertion or lookup but I am not sure if this is most efficient code. Will the compiler create an efficient hash function for computing hash value of the key or should I use boost::hash?


`class Foo {
  public:
   Foo():var1(0){};
   ~Foo();
   void func(int a) {
      var1 = a;
   }
   int var1;
}

int main()
{
    Foo f1;
    f1.func(10);
    const Foo* fp = &f1;
    std::unordered_map<std::pair<uint,const Foo*>,std::vector<uint>> umap1;
    umap1[std::make_pair(1,fp)].emplace_back(100);
}
 `

Aucun commentaire:

Enregistrer un commentaire