[英]How do i write a hash function in C++?
如何为自定义类型声明哈希函数,以便可以在unordered_map
使用它?
namespace std {
template<>
struct hash<my_custom_type>
{
using argument_type = my_custom_type;
using result_type = size_t;
size_t operator()(my_custom_type const& x) const
{
// Perform your hash algorithm here.
}
};
}
可能最好的方法是使用std :: hash <mytype>提供std :: hash <class Key>的特化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.