如何在C ++中创建无序的整数对? [英] How to make unordered set of pairs of integers in C++?
本文介绍了如何在C ++中创建无序的整数对?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
程序不编译无序的整数对,而是整数。可以在用户定义的类型上使用unordered_set及其成员函数,以及如何定义它?
The program does not compile an unordered set of pairs of integers, but it does for integers. Can unordered_set and its member functions be used on user defined types, and how can I define it?
#include <unordered_set>
...
class A{
...
private:
std::unordered_set< std::pair<int, int> > u_edge_;
};
error: no matching function for call to 'std::unordered_set<std::pair<unsigned int, unsigned int> >::unordered_set()'
推荐答案
在VS2010 SP1(VC10),但它无法编译与GCC g ++ 4.7.2。
Your code compiles on VS2010 SP1 (VC10), but it fails to compile with GCC g++ 4.7.2.
但是,你可能要考虑 boost ::哈希
从 Boost.Functional 哈希 std :: pair
(此外,您的代码也使用g ++编译)。
However, you may want to consider boost::hash
from Boost.Functional to hash a std::pair
(with this addition, your code compiles also with g++).
#include <unordered_set>
#include <boost/functional/hash.hpp>
class A
{
private:
std::unordered_set<
std::pair<int, int>,
boost::hash< std::pair<int, int> >
> u_edge_;
};
这篇关于如何在C ++中创建无序的整数对?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文