
Hi Matthias, The only thing that's likely to be a little counter intuitive is that visitors are copied by value. Typically, instantiate your std::list (or whatever container you decide to use) just prior to instantiating your visitor and pass a non-const reference into the visitor's constructor. e.g. template <typename VertexNameMap> class bfs_name_printer : public default_bfs_visitor { public: explicit bfs_name_printer(VertexNameMap & _name_map) : name_map(_name_map) {} private: VertexNameMap & name_map; // your visitor methods ... }; ... then typdef std::list<foo_t> vertex_name_map_t; vertex_name_map_t vertex_name_map; bfs_name_printer<vertex_name_map_t> visitor(vertex_name_map); ... and so on. HTH - Chris "Matthias Linkenheil" <M.Linkenheil@dkfz-heidelberg.de> wrote in message news:41DC1524.6010209@dkfz-heidelberg.de...
Dear all,
i want to use the breadth_first_search algorithm to store the visited nodes e.g. in a list for access in the main function. Has anyone an idea to handle this? In my code i print out the visited nodes.
The examples in the Boost User Guide about the visitor concept are sometimes not so easy to understand.
... using namespace boost; template <typename VertexNameMap> class bfs_name_printer:public default_bfs_visitor { public: bfs_name_printer(VertexNameMap n_map) : m_name_map(n_map){} template <typename Vertex, typename Graph> void discover_vertex(Vertex u, const Graph& ) const { std::cout<<get(m_name_map, u) <<" "; } private: VertexNameMap m_name_map;
}; ...
main(){
... typedef property_map<Graph, vertex_index_t>::type VertexNameMap; VertexNameMap id = get(vertex_index, g); bfs_name_printer<VertexNameMap> vis(id); breadth_first_search(fg, s, visitor(vis));
...
Regards, Matthias