我正在尝试在EdgeProperties上使用具有严格弱排序的std :: multiset容器来获取boost :: adacency_list的EdgeList模板参数
namespace boost {
struct propOrderedMultisetS { };
template <class ValueType>
struct container_gen<propOrderedMultisetS,ValueType> {
struct less {
bool operator() (const ValueType& lhs, const ValueType& rhs) const {
return (lhs.get_property() < rhs.get_property());
};
};
typedef std::multiset<ValueType, less> type;
};
struct MyVertexProp { int v; };
struct MyEdgeProp {
bool operator<(const MyEdgeProp& rhs) const {
return this->weight < rhs.weight;
}
double weight;
}
typedef adjacency_list<listS, listS, undirectedS, MyVertexProp, MyEdgeProp,
no_property, propOrderedMultisetS> PropOrderedGraph;
}
using namespace boost;
int main() {
PropOrderedGraph g;
// ... adding some vertices and edges
for (auto e_range=edges(g); e_range.first != e_range.second; ++e_range.first) {
// works! prints the edges ordered by weight
std::cout << g[*e_range.first].weight << std::endl;
}
for (auto v_range=vertices(g); v_range.first != v_range.second; ++v_range.first) {
// works! prints all vertices (random order)
std::cout << g[*v_range.first].v << std::endl;
}
auto first_vertex = *vertices(g).first;
for (auto adj_v_range=adjacent_vertices(first_vertex, g); adj_v_range.first != adj_v_range.second; ++adj_v_range.first) {
// problem: dereferencing causes compiler error, see below
std::cout << g[*adj_v_range.first].v << std::endl;
}
return 0;
}
在第三个for循环中取消引用迭代器会导致编译器错误:
/usr/include/boost/graph/detail/adjacency_list.hpp:293:69:错误:从'const MyEdgeProp'类型的表达式初始化'MyEdgeProp&amp;'类型的引用无效 内联物业&amp; get_property(){return m_iter-&gt; get_property(); }
我有什么想法可以解决这个错误或者我怎么能完成任务?
答案 0 :(得分:0)
我更改了图库,现在正在使用LEMON,它为我的任务提供了一个类IterableValueMap。