Question

I was hoping if there is any other way to use boost::filtered_graph () without the print_edges() or print_graph() functions.

in the link here, it seems that the filter works on every node only when the print graph or print edge function is called.

I do understand that the predicate acts on every node or edge of the graph when it is getting printed to std::cout

Is there any other way, I could use it ? could I use may be for_each( begin_iter, end_iter ) or something like that? please suggest.

Was it helpful?

Solution

You can use #include <boost/graph/graph_utility.hpp> where plenty of iterator macros are defined: BGL_FORALL_EDGES, BGL_FORALL_VERTICES, BGL_FORALL_OUTEDGES, etc.

Your typical code could look like:

BGL_FORALL_VERTICES(src, g, MyGraph_t )
{
    BGL_FORALL_OUTEDGES(src, ed, g, MyGraph_t )
    {
        MyGraph_t::vertex_descriptor tgt = target(ed, g);
        ... do something ...
    }
}

This code will work regardless whether MyGraph_t is a filtered_graph or adjacency_list or any other BGL graph type.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top