Boost logo

Boost Users :

Subject: [Boost-users] [hash] Reliability of hash_value() for std::string
From: Szymon Gatner (szymon.gatner_at_[hidden])
Date: 2012-02-21 07:32:30


I am coding a simple serialization/factory lib and want to use class hash code
based on std::string representing class name as a factory identifier.

My question is: how portable / reliable is hash value produced by std::string
hash_value() overload? Will it be the same across platforms? Across
boost versions?
Or maybe actual algorithm is dictated by standard? Or should I just go
with explicit
algo like crc32?

btw. I was just very hardly bitten by the fact that hash_value() for
const char* !=
hash_value() for std::string, (it is just being treated as regular
pointer). In other
words hash_value("Class") != hash_value(std::string("Class")) which
gave me few more
gray hair. Is that desirable?

Szymon Gatner

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