C++0x 增加了 hash<...>(...)
。
我找不到 hash_combine
函数,如 boost 中所述。实现这样的事情的最干净的方法是什么?也许,使用 C++0x xor_combine
?
原文由 Neil G 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用我开发的 第一个 C++ 库来执行此操作:
#include "rst/stl/hash.h"
struct Point {
Point(const int x, const int y) : x(x), y(y) {}
int x = 0;
int y = 0;
};
bool operator==(const Point lhs, const Point rhs) {
return (lhs.x == rhs.x) && (lhs.y == rhs.y);
}
namespace std {
template <>
struct hash<Point> {
size_t operator()(const Point point) const {
return rst::HashCombine({point.x, point.y});
}
};
}
原文由 Sergey Abbakumov 发布,翻译遵循 CC BY-SA 4.0 许可协议
3 回答2k 阅读✓ 已解决
2 回答3.9k 阅读✓ 已解决
2 回答3.2k 阅读✓ 已解决
1 回答3.2k 阅读✓ 已解决
1 回答2.7k 阅读✓ 已解决
3 回答3.4k 阅读
1 回答1.6k 阅读✓ 已解决
好吧,就像助推器那样做: