【发布时间】:2015-03-17 15:45:17
【问题描述】:
我正在尝试为 boost::adacency_list 的 EdgeList 模板参数使用在 EdgeProperties 上具有严格弱排序的 std::multiset 容器
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&”类型的引用无效初始化 内联属性& get_property() { return m_iter->get_property(); }
任何想法我可以如何解决该错误或我可以如何完成任务?
【问题讨论】:
标签: c++11 boost graph selector adjacency-list