我是 BGL 新手,我在制作自己的属性映射时遇到问题,关键是 edge_property
你能告诉我我做错了什么,以下代码打印不: (0,1) == (0,1) 吗?1 但 (0,1) == (0,1) ?0
这是代码
#include <boost/graph/adjacency_list.hpp>
#include <iostream>
#include <map>
using namespace std;
class A {};
class B {};
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::bidirectionalS,
A, B > Graph;
typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor;
typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
typedef boost::graph_traits<Graph>::edge_iterator edge_iterator;
typedef boost::graph_traits<Graph>::in_edge_iterator in_edge_iterator;
typedef boost::graph_traits<Graph>::out_edge_iterator out_edge_iterator;
map<edge_descriptor, int> fun(Graph g){
map<edge_descriptor, int> m;
m[*(edges(g).first)] = 5;
return m;
}
int main(){
Graph g;
vertex_descriptor a = add_vertex(g);
vertex_descriptor b = add_vertex(g);
add_edge(a, b, g);
map<edge_descriptor, int> m = fun(g);
edge_iterator ei, ei_end;
for(tie(ei, ei_end) = edges(g) ; ei !=ei_end ; ++ei){
cout << m.begin()->first << " == " << *ei << " ? " << (m.begin()->first == *ei) << endl;
}
}
非常感谢!
编辑:也许有比 edge_property 值更好的方法来映射边缘?