#include <unordered_set>
#include <functional>
#include <iostream>
struct MyKey
{
int key;
};
struct MyKeyHashHasher
{
size_t operator()(const MyKey &k) const noexcept
{
return std::hash<int>{}(k.key);
}
};
struct MyKeyHashComparator
{
bool operator()(const MyKey &k1, const MyKey &k2) const noexcept
{
return k1.key == k2.key;
}
};
int main()
{
std::unordered_set<MyKey,MyKeyHashHasher,MyKeyHashComparator> ss;
return 0;
}
C++11使用自定义hash函数及比较函数的unordered_set
最新推荐文章于 2024-08-27 11:09:59 发布