Boost logo

Boost Users :

From: Vladimir Prus (ghost_at_[hidden])
Date: 2004-10-20 01:51:49


David M. Jones wrote:

> "Martin Magnusson" <martin.magnusson_at_[hidden]> wrote in message
> news:cl2vmc$lob$1_at_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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net