|
Boost Users : |
Subject: Re: [Boost-users] Boost Graph: iterating over internal vertex property
From: Andrew Sutton (andrew.n.sutton_at_[hidden])
Date: 2010-03-30 21:04:16
> But what if I want to iterate over the Foo pointers in my graph? I suppose
> one way is this:
>
> for (int i = 0; i < num_vertices(g); i++) {
> Foo *foo = g[i];
> }
>
Yup.
But I assume this wouldn't scale if I were to use listS instead vecS. Also,
> I'd want to use a proper vertex_iterator anyway, so I can grab all the
> properties I want in one loop. But how can I access my Foo pointer from the
> vertex_iterator? I've looked though the docs and sample code but I just
> can't figure it out.
>
Pretty much the same way:
typename graph_traits<G>::vertex_iterator i, end;
for(tie(i, end) = vertices(g); i != end; ++ii) {
Foo* f = g[*i];
}
Dereferencing a vertex iterator returns a vertex descriptor. The same is
true for edge iterators and edge descriptors, if it comes up.
Andrew Sutton
andrew.n.sutton_at_[hidden]
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