Reputation: 49
I have a problem copying a graph using boost? My code is given below: It doesn't let me to create IndexMap as a type.
template <class Graph>
int abc(Graph& G){
typename graph_traits<Graph>::vertex_descriptor NodeID;
typedef map<size_t, NodeID> IndexMap; //It doesn't let me to create NodeID type
typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);
Graph g1, g2;
int i=0;
BGL_FORALL_VERTICES(v, g2, Graph)
{
put(propmapIndex, v, i++);
}
g1.clear();
copy_graph( g2, g1, vertex_index_map( propmapIndex ) );
g2.clear();
}
int main(){
typedef adjacency_list<listS, vecS, undirectedS,
WeightProperty, property<edge_color_t, default_color_type> MyGraphType;
typename graph_traits<MyGraphType>::adjacency_iterator ai, ai_end;
typename graph_traits<MyGraphType>::vertex_descriptor Vertex;
...
...
MyGraphType G;
... //addition of vertices and edges
abc(G);
}
Thank you for the help.
Upvotes: 1
Views: 181
Reputation:
I guess
typename graph_traits<Graph>::vertex_descriptor NodeID;
should be
typedef typename graph_traits<Graph>::vertex_descriptor NodeID;
The upper variant is a declaration of a variable NodeID
of type graph_traits<Graph>::vertex_descriptor
, while the latter is a typedef for the same type.
Upvotes: 4