Boost logo

Boost Users :

Subject: [Boost-users] [Hash] Custom hash_value for Pointers
From: Hossein Haeri (powerprogman_at_[hidden])
Date: 2010-08-27 13:53:09

Dear all,

Should not the program in the P.S. output "I got used!"? If not, how can I ensure that it's size_t hash_value(B*) which gets called upon use of bPtrHasher's operator()?



namespace Bs
struct B
  virtual string id() const {return "This is a B!";}

struct D: B
  string id() const {return "And, this one is a D.";}

size_t hash_value(B* bptr)
  cout << "I got used!" << endl;
  boost::hash<string> hasher;
  return hasher(bptr->id());

int main()
  Bs::B* bp1 = new Bs::B;
  Bs::B* bp2 = new Bs::D;
  boost::hash<Bs::B*> bPtrHasher;
  size_t h1 = bPtrHasher(bp1), h2 = bPtrHasher(bp2);

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at