Constructing vertex_iterator from vertex_descriptor

I'm using BGL, and I noticed that add_vertex returns a vertex_descriptor to the new vertex. However, I would like to have a vertex_iterator pointing to the same element. Is there a way to construct a vertex_iterator when given a vertex_descriptor? / martin

"Martin Magnusson"
I'm using BGL, and I noticed that add_vertex returns a vertex_descriptor to the new vertex. However, I would like to have a vertex_iterator pointing to the same element. Is there a way to construct a vertex_iterator when given a vertex_descriptor?
Martin, If I have a BGL graph object g and a vertex descriptor vd, then std::find(vertices(g).first, vertices(g).second, vd) will return an iterator that points to vd. Hope this helps, David M. Jones

David M. Jones wrote:
"Martin Magnusson"
wrote in message news:cl2vmc$lob$1@sea.gmane.org... I'm using BGL, and I noticed that add_vertex returns a vertex_descriptor to the new vertex. However, I would like to have a vertex_iterator pointing to the same element. Is there a way to construct a vertex_iterator when given a vertex_descriptor?
Martin,
If I have a BGL graph object g and a vertex descriptor vd, then std::find(vertices(g).first, vertices(g).second, vd) will return an iterator that points to vd.
Of course, this is very slow (O(N)). If you're using vecS for vertices, you can try std::advance(vertices(g).first, vd) but I'd step the code with a debugger to make sure it does not loop internally for this case. - Volodya
participants (3)
-
David M. Jones
-
Martin Magnusson
-
Vladimir Prus