Search code examples
c++boostboost-graph

Simplest way to define ColorMap for depth_first_search


I want to use the depth_first_search algorithm. Since I need the DFS version where a start vertex is specified, I also have to define a ColorMap. That's the function I want to use :

template <class Graph, class DFSVisitor, class ColorMap>
void depth_first_search(const Graph& g, DFSVisitor vis, ColorMap color, 
             typename graph_traits<Graph>::vertex_descriptor start)

https://www.boost.org/doc/libs/1_67_0/libs/graph/doc/depth_first_search.html

Since the map is irrelevant for me, the default ColorMap would be fully sufficient. Could you give me a hint how to create and pass it as argument in depth_first_search it?


Solution

  • Just use the named parameter overload instead, which will let you specify a start vertex while just using the default color map.

    template <class Graph, class class P, class T, class R>
    void depth_first_search(Graph& G, const bgl_named_params<P, T, R>& params);
    

    Example:

    boost::depth_first_search(graph, boost::root_vertex(start_vertex));