2
我正在试图使用boost的图形库adjacency_list与C++ 11 unorunordered_set。 使用它作为第二个模板参数(即顶点列表)编译罚款,当试图使用它作为“出边”类型(第一个模板参数)时,我得到以下错误: “”C++标准没有'提供这种类型的散列。“ 这里是一个问题的代码:如何使用带有标准unorunordered_set的BGL的adjacency_list作为出界边界列表模板参数
#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;
}
许多10X, 安德烈
许多10倍!奇迹般有效。 – Andrey