我正在尝试使用一个std::multiset容器,在EdgeProperties上对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;
for (auto e_range=edges(g); e_range.first != e_range.second; ++e_range.first) {
std::cout << g[*e_range.first].weight << std::endl;
}
for (auto v_range=vertices(g); v_range.first != v_range.second; ++v_range.first) {
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) {
std::cout << g[*adj_v_range.first].v << std::endl;
}
return 0;
}
在第三个for循环中取消对迭代器的引用会导致编译器错误:
/usr/include/boost/graphic/detail/aximity_list.hpp:293:69:错误:MyEdgeProp&来自const MyEdgeProp类型的表达式
内联属性&get_property(){return m_iter->get_propery();}
你知道我该如何纠正这个错误,或者我该如何完成任务吗?