Reputation: 231
I'm trying to build a graph with vertices stored in a std::list
instead of a std::vector
.
However I am confused by a compilation error I get. The minimal code I'm using is
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
int main() {
typedef adjacency_list< listS,listS > Graph;
Graph g;
add_edge(0,1,g);
return 0;
}
Compiling with gcc-4.7.3
I get the following error:
/Users/matteo/Documents/workspace/graph-gravity-dec/src/test.cpp: In function 'int main()':
/Users/matteo/Documents/workspace/graph-gravity-dec/src/test.cpp:12:17: error: invalid conversion from 'int' to 'boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, boost::listS>, boost::listS, boost::listS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>::config::vertex_descriptor {aka void*}' [-fpermissive]
In file included from /opt/local/include/boost/graph/adjacency_list.hpp:246:0,
from /Users/matteo/Documents/workspace/graph-gravity-dec/src/test.cpp:2:
/opt/local/include/boost/graph/detail/adjacency_list.hpp:681:5: error: initializing argument 2 of 'std::pair<typename Config::edge_descriptor, bool> boost::add_edge(typename Config::vertex_descriptor, typename Config::vertex_descriptor, boost::directed_graph_helper<Config>&) [with Config = boost::detail::adj_list_gen<boost::adjacency_list<boost::listS, boost::listS>, boost::listS, boost::listS, boost::directedS, boost::no_property, boost::no_property, boost::no_property, boost::listS>::config; typename Config::edge_descriptor = boost::detail::edge_desc_impl<boost::directed_tag, void*>; typename Config::vertex_descriptor = void*]' [-fpermissive]
that seems complaining about an invalid conversion from int
to void*
.
However if I change listS
to vecS
everything works fine
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
int main() {
typedef adjacency_list< listS, vecS > Graph;
Graph g;
add_edge(0,1,g);
return 0;
}
What am I missing? Isn't the container of vertices supposed to be interchangeable without further modification of the rest of the code?
Upvotes: 2
Views: 488
Reputation: 19232
As people have said, you can't use 0, or 1 for a node in a list backed graph. This will work though:
typedef adjacency_list< listS,listS > Graph;
Graph g;
typedef boost::graph_traits < Graph >::vertex_descriptor Vertex;
Vertex v0 = boost::add_vertex(g);
Vertex v1 = boost::add_vertex(g);
boost::add_edge(v0, v1, g);
You need to make a vertex to add. There are some helpful bits of code in this question
Upvotes: 4