#include BOOST_PARAMETER_NAME((_graph, graphs) graph) BOOST_PARAMETER_NAME((_visitor, graphs) visitor) BOOST_PARAMETER_NAME((_root_vertex, graphs) in(root_vertex)) BOOST_PARAMETER_NAME((_index_map, graphs) in(index_map)) BOOST_PARAMETER_NAME((_color_map, graphs) in_out(color_map)) #include #include #include #include #include #include struct vertex_descriptor_predicate { template struct apply : boost::mpl::if_< boost::is_convertible< T , typename boost::graph_traits< typename boost::parameter::value_type< Args , graphs::graph >::type >::vertex_descriptor > , boost::mpl::true_ , boost::mpl::false_ > { }; }; #include struct graph_predicate { template struct apply : boost::mpl::eval_if< boost::is_convertible< typename boost::graph_traits::traversal_category , boost::incidence_graph_tag > , boost::mpl::if_< boost::is_convertible< typename boost::graph_traits::traversal_category , boost::vertex_list_graph_tag > , boost::mpl::true_ , boost::mpl::false_ > , boost::mpl::false_ > { }; }; #include #include struct color_map_predicate { template struct apply : boost::mpl::if_< boost::is_same< typename boost::property_traits::key_type , typename boost::graph_traits< typename boost::parameter::value_type< Args , graphs::graph >::type >::vertex_descriptor > , boost::mpl::true_ , boost::mpl::false_ > { }; }; #include struct index_map_predicate { template struct apply : boost::mpl::eval_if< boost::is_integral< typename boost::property_traits::value_type > , boost::mpl::if_< boost::is_same< typename boost::property_traits::key_type , typename boost::graph_traits< typename boost::parameter::value_type< Args , graphs::graph >::type >::vertex_descriptor > , boost::mpl::true_ , boost::mpl::false_ > , boost::mpl::false_ > { }; }; #include #include template boost::iterator_property_map< std::vector::iterator , IndexMap , boost::default_color_type , boost::default_color_type& >& default_color_map(Size num_vertices, IndexMap const& index_map) { static std::vector colors(num_vertices); static boost::iterator_property_map< std::vector::iterator , IndexMap , boost::default_color_type , boost::default_color_type& > m(colors.begin(), index_map); return m; } #include BOOST_PARAMETER_FUNCTION((void), depth_first_search, graphs, (required (graph, *(graph_predicate)) ) (optional (visitor , * // not easily checkable , boost::dfs_visitor<>() ) (root_vertex , *(vertex_descriptor_predicate) , *vertices(graph).first ) (index_map , *(index_map_predicate) , get(boost::vertex_index, graph) ) (color_map , *(color_map_predicate) , default_color_map(num_vertices(graph), index_map) ) ) ) { } #include #include #include int main() { typedef boost::adjacency_list< boost::vecS , boost::vecS , boost::directedS > G; enum {u, v, w, x, y, z, N}; typedef std::pair E; E edges[] = { E(u, v), E(u, x), E(x, v), E(y, x), E(v, y), E(w, y), E(w, z), E(z, z) }; G g(edges, edges + sizeof(edges) / sizeof(E), N); ::depth_first_search(g); ::depth_first_search(g, _root_vertex = static_cast(x)); return boost::report_errors(); }