gpt4 book ai didi

c++ - 我如何在 C++ 中编写哈希函数?

转载 作者:搜寻专家 更新时间:2023-10-30 23:58:09 25 4
gpt4 key购买 nike

如何为我的自定义类型声明一个哈希函数,以便我可以在 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.
}
};
}

关于c++ - 我如何在 C++ 中编写哈希函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21575786/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com