我想存储一系列指针std::unordered_set.我希望散列函数不是基于内存地址,而是基于指针引用的实际对象中包含的某些值.
例如(using std和boost名称空间以便于阅读)
class MyClass {
...
//some values I want to use as the key for the hash
double a;
int b;
int c;
}
typedef shared_ptr<MyClass> MyClassPtr;
set<MyClassPtr> mySet;
Run Code Online (Sandbox Code Playgroud)
我并不担心结合实际的哈希值(在这里找到答案:http://www.boost.org/doc/libs/1_47_0/doc/html/hash/combine.html),而是取消引用shared_ptr以获取键.
我所关注的另一个问题== operator是已经确定了boost::shared_ptr,我想知道这是否会导致我的方法出现问题?我需要测试对象的相等性,而不是指针.
在集合中存储指针,因为代码的其他几个部分通过自己的指针引用对象.也欢迎任何替代方法.
谢谢