[BGL] problem about copy graph
typedef adjacency_list<vecS, vecS, undirectedS, no_property, edge_ex> graph_t; typedef graph_traits<graph_t>::vertex_descriptor vertex_t; typedef graph_traits<graph_t>::edge_descriptor edge_t; struct edge_ex { //int index; bw_t az_capacity; bw_t za_capacity; int cost; vertex_t fake_source; }; // init a graph g and assign edge_ex values, and get a std::pair<edge_t, bool> r when add_edge(5,6,g); graph_t g2 = g; std::pair<edge_t, bool> rr = edge(5,6,g2); g2[rr.first].cost = 1000; std::cout<<g[r.first].cost<<" "<<g2[r.first].cost<<" "<<g2[rr.first]; //output is: old_value old_value 1000 WHY?? It seems a bug, g2[r.first] should be 1000 rather than the value assign to g even r.first is a descriptor that belongs to g OK, this is problematic usage, but... g2[r.first] works, it doesn't make sense. -- View this message in context: http://www.nabble.com/-BGL--problem-about-copy-graph-tp23921384p23921384.htm... Sent from the Boost - Users mailing list archive at Nabble.com.
Li Ning wrote:
typedef adjacency_list<vecS, vecS, undirectedS, no_property, edge_ex> graph_t;
typedef graph_traits<graph_t>::vertex_descriptor vertex_t; typedef graph_traits<graph_t>::edge_descriptor edge_t;
struct edge_ex { //int index; bw_t az_capacity; bw_t za_capacity; int cost; vertex_t fake_source; }; // init a graph g and assign edge_ex values, and get a std::pair<edge_t, bool> r when add_edge(5,6,g); graph_t g2 = g; std::pair<edge_t, bool> rr = edge(5,6,g2); g2[rr.first].cost = 1000;
std::cout<<g[r.first].cost<<" "<<g2[r.first].cost<<" "<<g2[rr.first];
//output is: old_value old_value 1000
WHY?? It seems a bug, g2[r.first] should be 1000 rather than the value assign to g even r.first is a descriptor that belongs to g OK, this is problematic usage, but... g2[r.first] works, it doesn't make sense.
Sorry, should be std::cout<<g[r.first].cost<<" "<<g2[r.first].cost<<" "<<g2[rr.first].cost; -- View this message in context: http://www.nabble.com/-BGL--problem-about-copy-graph-tp23921384p23921431.htm... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (1)
-
Li Ning