C++11使用自定义hash函数及比较函数的unordered_set

#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;
}

猜你喜欢

转载自blog.csdn.net/adream307/article/details/83989213