BGL, swapping two graphs can invalidate vertex descriptors?

Dear list, I had to fix a bug in a program of mine using the boost graph library. In the program I need to add and remove vertices quickly, so I used listS both for edges and vertices. Besides, I need to refer to vertices with special ids (that are integers), so I added to each vertex a integer and to the graph itself a map between the ids and the vertices. The interface ensures that when vertices are added and this data structures are updated properly. For reference I put the whole (minified) graph definition after the email. Now, I had a crash when using boost::out_edges in some part of the programs and not in others. After some debugging it really seems that it happens that the vertex descriptors, that are addresses to the vertices, change after a swap. Unfortunately I could not manage to make this behaviour in a small example so I am still unsure and I decided to ask here. It is possible that swapping two graphs (with listS as OutEdgeList and VertexList) invalidates the vertex descriptors? Yours faithfully, Paolo #include <boost/graph/adjacency_list.hpp> namespace graph_prop { struct vertex { int id{}; }; struct edge { int lenght{}; }; struct graph; } typedef boost::adjacency_list< boost::listS, boost::listS, boost::undirectedS, graph_prop::vertex, graph_prop::edge, graph_prop::graph > Graph; namespace graph_prop { struct graph { std::unordered_map<int, Graph::vertex_descriptor> ids{}; }; }
participants (1)
-
Paolo Bolzoni