I've (successfully) implemented a custom visitor for my BFS:
(See also: Find all reachable vertices in a Boost BGL graph using BFS)
...
...
ListVisitor vis;
boost::breadth_first_visit(mListGraph, start, Q, vis, colormap);
Visitor defined in my header file:
class ListVisitor : public boost::default_bfs_visitor
{
public:
template <typename Vertex, typename Graph>
void discover_vertex(Vertex u, const Graph& /*g*/) const
{
std::cout << u << std::endl;
}
};
This works as expected... so everything could be fine. :-)
However I wanted to change my code to use make_bfs_visitor instead
and changed my code like this:
boost::breadth_first_visit(mListGraph, start, Q,
boost::visitor(
boost::make_bfs_visitor(
ListVisitor<boost::on_discover_vertex>()
)
), colormap);
and in the .h:
template <typename event_type>
struct ListVisitor : public boost::default_bfs_visitor
{
using event_filter = event_type;
template<typename GRAPH>
void operator()(GRAPH::vertex_descriptor vert, const GRAPH& graph) const
{
std::cout << u << std::endl;
}
};
Unfortunately this produces an error:
Error C2061 syntax error: identifier 'vertex_descriptor'
I also tried to use the real type instead of templated types:
void operator()(ListGraph_t::vertex_descriptor vert, const ListGraph_t& graph) const
but it only changes the error:
Error C2039 'discover_vertex': is not a member of ...
Error C2039 'examine_vertex': is not a member of ...
Error C2039 'examine_edge': is not a member of ...
and so on..........
My question:
- Is it possible to use make_bfs_visitor with breadth_first_visit algorithm? All examples I've found are implemented with breadth_first_search!
- Could this (one or more visitors like examine_edge, examine_vertex) even be implemented using lambda expressions?
- Are there any reasons (e.g. performance penalty) using one over the other solution?