[英]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.