【发布时间】:2015-06-17 23:35:59
【问题描述】:
我正在尝试将 boost 的图形库 adjacency_list 与 C++11 unorunordered_set 一起使用。 虽然将它用作第二个模板参数(即顶点列表)编译得很好,但当尝试将它用作“外边”类型(第一个模板参数)时,我收到以下错误: ““C++ 标准不提供这种类型的哈希值。” 这是有问题的代码:
#include <unordered_set>
#include <boost/config.hpp>
#include <boost/graph/adjacency_list.hpp>
struct NodeProperty{
std::string FirstName;
std::string LastName;
};
namespace std{
template<>
struct hash<NodeProperty>
{
std::hash<std::string> hasher;
size_t operator()(const NodeProperty& key) const
{
return hasher(key.FirstName) ^ hasher(key.LastName);
}
};
}
namespace boost {
struct std_unorunordered_setS{};
template <class ValueType>
struct container_gen<std_unorunordered_setS, ValueType> {
typedef std::unordered_set<ValueType> type;
};
template <>
struct parallel_edge_traits<std_unorunordered_setS> {
typedef disallow_parallel_edge_tag type;
};
}
using namespace boost;
int main(int, char*[])
{
typedef adjacency_list< std_unorunordered_setS, std_unorunordered_setS, bidirectionalS,
NodeProperty > Graph;
typedef graph_traits<Graph>::vertex_descriptor Vertex;
}
许多 10 倍, 安德烈
【问题讨论】:
标签: c++11 boost boost-graph