I learned How to configure boost::graph to use my own (stable) index for vertices? in How to configure boost::graph to use my own (stable) index for vertices? so, I want use bread_first_search algorithm to do something, but I don't know what's wrong with my code.
#include <iostream>
#include <algorithm>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/properties.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/graph/named_function_params.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <boost/range/irange.hpp>
#include <boost/graph/visitors.hpp>
#include <boost/graph/graph_utility.hpp>
using namespace std;
using namespace boost;
template < class NewGraph, class Tag >
struct graph_copier
: public boost::base_visitor< graph_copier< NewGraph, Tag > >
{
typedef Tag event_filter;
graph_copier(NewGraph& graph) : new_g(graph) {}
template < class Edge, class Graph > void operator()(Edge e, Graph& g)
{
boost::add_edge(boost::source(e, g), boost::target(e, g), new_g);
}
private:
NewGraph& new_g;
};
template < class NewGraph, class Tag >
inline graph_copier< NewGraph, Tag > copy_graph(NewGraph& g, Tag)
{
return graph_copier< NewGraph, Tag >(g);
}
typedef boost::adjacency_list<boost::vecS, boost::listS, boost::directedS, Vertex, boost::no_property> Graph;
// traits
template <> struct boost::graph::internal_vertex_name<Vertex> {
struct type {
using result_type = size_t;
result_type const& operator()(Vertex const& bundle) const {
return bundle.id;
}
};
};
template <> struct boost::graph::internal_vertex_constructor<Vertex> {
struct type {
private:
using extractor = typename internal_vertex_name<Vertex>::type;
using name_t = std::decay_t<typename extractor::result_type>;
public:
using argument_type = name_t;
using result_type = Vertex;
result_type operator()(const name_t& id) const { return {id}; }
};
};
void test4(){
Graph graph;
add_edge(100000, 100001, graph);
add_edge(100000, 100002, graph);
add_edge(100003, 100004, graph);
typedef Graph::vertex_descriptor vd;
vd s = add_vertex(100005, graph);
print_graph(graph, get(&Vertex::id, graph), std::cout << "---\n");
vd x = *graph.named_vertices.find(100000);
Graph G_copy;
boost::graph_traits<Graph>::vertices_size_type d[6];
boost::breadth_first_search(graph, x,
boost::visitor(boost::make_bfs_visitor(
std::make_pair(boost::record_distances(d, boost::on_tree_edge())
, copy_graph(G_copy, boost::on_examine_edge())))));
print_graph(G_copy, get(&Vertex::id, G_copy), std::cout << "---\n");
}
int main() {
test4();
return 0;
}
it's wrong at bfs. The error is as follows
In file included from /Users/diaodonghui/CLionProjects/boost_graph_dev/main.cpp:4:
In file included from /usr/local/include/boost/graph/adjacency_list.hpp:255:
/usr/local/include/boost/graph/detail/adjacency_list.hpp:2601:27: error: cannot form a reference to 'void'
typedef value_type& reference;
and I also wonder why when I Changed 'listS' to 'vecS' or 'setS', it both doesn't work??