Boost logo

Boost Users :

Subject: [Boost-users] Boost Graph: iterating over internal vertex property
From: Trevor Harmon (Trevor.W.Harmon_at_[hidden])
Date: 2010-03-30 20:50:11


Hi,

My graph is defined like this:

   typedef adjacency_list<vecS, vecS, directedS, Foo*> Graph;

The vertex indices can be iterated over like this:

   typedef property_map<Graph, vertex_index_t>::type IndexMap;
   IndexMap index = get(vertex_index, g);
   typedef graph_traits<Graph>::vertex_iterator vertex_iter;
   std::pair<vertex_iter, vertex_iter> vp;
   for (vp = vertices(g); vp.first != vp.second; ++vp.first) {
     std::cout << index[*vp.first] << " ";
   }

(This is straight out of the "Quick Tour" document.)

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];
   }

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.

Thanks for any tips,

Trevor


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