Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maintaining iterator in Boost::graph while performing DFS

Most of the examples for the Boost:graph library perform depth-first-search by calling boost's depth first search utilities. After creation of the vertices and edges, calling DFS on the graph traverses the entire graph in a depth-first manner and if we have a visitor method associated with it, it would call the visitor method to perform an action, for every node traversed.

What I am looking for is a way to maintain an iterator over the graph, where instead of traversing the graph in one go, when the client calls 'next()', the iterator would move to the next vertex that it would traversed to for DFS and upon calling next again, the iterator would move to the next vertex as dictated by DFS.

Are there any examples of performing the above using boost:graph?

Thanks

like image 910
sc_ray Avatar asked Aug 17 '12 19:08

sc_ray


1 Answers

Unfortunately for you, the boost::graph API is based on visitors, i.e. callbacks. In principle, the only way to convert that into iterators would be coroutines, which C++ does not have standard.

like image 73
sylvain.joyeux Avatar answered Oct 06 '22 02:10

sylvain.joyeux