这是Find connected components using Boost Graph library, with the vertex and edge type being boost::listS的后续问题
按照以下代码使用自定义顶点和边类型时,无法获得提供的解决方案进行编译
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/connected_components.hpp>
#include <iostream>
struct Vertex { int foo; };
struct Edge { std::string blah; };
typedef boost::adjacency_list<
boost::listS,
boost::listS,
boost::undirectedS,
Vertex, Edge
> Cluster;
int main() {
using namespace boost;
Cluster A;
add_vertex(Vertex{ 0 }, A);
add_vertex(Vertex{ 1 }, A);
add_vertex(Vertex{ 2 }, A);
add_vertex(Vertex{ 3 }, A);
for (int i = 0; i < 2; i++) {
for (int j = (i + 1); j < 3; j++) {
std::cout << i << " -- " << j << "\n";
add_edge(vertex(i, A), vertex(j, A), Edge{ "edge" }, A);
}
} // add edge between 0-1, 0-2, 1-2.
std::map<Cluster::vertex_descriptor, int> subclusters;
int nclusters = boost::connected_components(A, boost::make_assoc_property_map(subclusters)); // find the connected components
for (auto& p : subclusters) {
std::cout << "Vertex " << A[p.first].foo << " is in cluster " << p.second << "\n";
}
return 0;
}
错误是
1>D:\boost_1_66_0\boost/graph/detail/adjacency_list.hpp(2544): error : reference to void is not allowed
1> typedef value_type& reference;
1> ^
1> detected during:
1> instantiation of class "boost::adj_list_any_vertex_pa::bind_<Tag, Graph, Property> [with Tag=boost::vertex_index_t, Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, Property=Vert_ptr]" at line 2615
1> instantiation of class "boost::detail::adj_list_choose_vertex_pa<Tag, Graph, Property> [with Tag=boost::vertex_index_t, Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, Property=Vert_ptr]" at line 2752
1> instantiation of class "boost::adj_list_vertex_property_selector::bind_<Graph, Property, Tag> [with Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, Property=Vert_ptr, Tag=boost::vertex_index_t]" at line 202 of "D:\boost_1_66_0\boost/graph/properties.hpp"
1> instantiation of class "boost::detail::vertex_property_map<Graph, PropertyTag> [with Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, PropertyTag=boost::vertex_index_t]" at line 213 of "D:\boost_1_66_0\boost/graph/properties.hpp"
1> instantiation of class "boost::property_map<Graph, Property, Enable> [with Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, Property=boost::vertex_index_t, Enable=void]" at line 290 of "D:\boost_1_66_0\boost/graph/graphviz.hpp"
1> instantiation of "void boost::write_graphviz(std::ostream &, const Graph &, VertexPropertiesWriter, EdgePropertiesWriter, GraphPropertiesWriter, boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type) [with Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>,
1> VertexPropertiesWriter=boost::label_writer<boost::transform_value_property_map<Name, boost::adj_list_vertex_property_map<boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, Vert_ptr, Vert_ptr &, boost::vertex_bundle_t>, std::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, EdgePropertiesWriter=boost::default_writer, GraphPropertiesWriter=boost::default_writer]" at line 309 of
1> "D:\boost_1_66_0\boost/graph/graphviz.hpp"
1> instantiation of "void boost::write_graphviz(std::ostream &, const Graph &, VertexWriter, boost::enable_if_c<boost::is_base_and_derived<boost::vertex_list_graph_tag, boost::graph_traits<Graph>::traversal_category>::value, boost::graph::detail::no_parameter>::type) [with Graph=boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>, VertexWriter=boost::label_writer<boost::transform_value_property_map<Name,
1> boost::adj_list_vertex_property_map<boost::adjacency_list<boost::listS, boost::listS, boost::directedS, Vert_ptr, boost::no_property, boost::no_property, boost::listS>