I'm using boost::hash_combine in a custom hash object for a std::array defining a position in a two-dimensional grid.
struct PositionHasher {
std::size_t operator()(const std::array<int, 2> &position) const {
std::size_t seed;
boost::hash_combine(seed, position[0]);
boost::hash_combine(seed, position[1]);
return seed;
};
};
The calls to boost::hash combine are equivalent to:
seed ^= position[0] + 0x9e3779b9 + (seed << 6) + (seed >> 2);
seed ^= position[1] + 0x9e3779b9 + (seed << 6) + (seed >> 2);
When building my app in release mode, I get different hashing behaviour than in debug mode. I suspect that I in fact get different has values for the same std::array objects. This behaviour persists even if I remove the 0x9e3779b9 from the function.
How is this possible? I'm using VS2015 and full /Ox optimisation, and I'm using the custom hash to lookup the position objects in a std::unordered_set.