[graph] vertex property Graph type cyclic definition problem. forward declaration not possible.

Hi, i would like to use the bundled properties feature of the boost graph library to specify the vertex properties of my graph. The problem is that i would like to have some graph type dependent descriptor type map defined within these vertex properties. Here is the example: // begin code #include <iostream> #include <boost/graph/adjacency_list.hpp> struct vertex_properties { vertex_properties () : color (-1) {} int color; std::list <int> free_colors; std::map<int,link_graph_traits::edge_descriptor> used_colors; // this is a cycle def problem }; struct edge_properties { edge_properties () : color (-1) {} int color; }; struct graph_properties { int delta; }; typedef boost::adjacency_list < boost::listS, boost::vecS, boost::bidirectionalS, vertex_properties,// this is a cycle problem edge_properties, graph_properties> link_graph; typedef boost::graph_traits <link_graph> link_graph_traits; int main(int argc, char** argv) { link_graph g; return 0; } // end code This example won't compile because the 'struct vertex_properties' contains a variable declaration of a std::map which contains the type ('link_graph_traits::edge_descriptor') as a template parameter that is not defined yet. I tried to forward declare the 'struct vertex_properties;' and move the definition of 'struct vertex_properties {...};' behind the graph type definition but then the compiler complained about. The forward declaration code, that does not compile, too follows: // begin code #include <iostream> #include <boost/graph/adjacency_list.hpp> struct vertex_properties; struct edge_properties { edge_properties () : color (-1) {} int color; }; struct graph_properties { int delta; }; typedef boost::adjacency_list < boost::listS, boost::vecS, boost::bidirectionalS, vertex_properties, edge_properties, graph_properties> link_graph; typedef boost::graph_traits <link_graph> link_graph_traits; struct vertex_properties { vertex_properties () : color (-1) {} int color; std::list <int> free_colors; std::map <int, link_graph_traits::edge_descriptor> used_colors; }; int main(int argc, char** argv) { link_graph g; return 0; } // end code I do not want to use (void*) and std::reinterpret_cast to work around this problem. I hope that you can help me with a technique not using casts. I assume that there may be a possibility to first declare the graph type without the vertex_properties struct and then 'adding' the vertex_propterties struct after defining the graph. best regards Christoph

On Wed, 12 Oct 2011, Christoph wrote:
Hi,
i would like to use the bundled properties feature of the boost graph library to specify the vertex properties of my graph. The problem is that i would like to have some graph type dependent descriptor type map defined within these vertex properties.
(snip)
I do not want to use (void*) and std::reinterpret_cast to work around this problem. I hope that you can help me with a technique not using casts.
I assume that there may be a possibility to first declare the graph type without the vertex_properties struct and then 'adding' the vertex_propterties struct after defining the graph.
You can use the adjacency_list_traits class for that; see <URL:http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/adjacency_list_traits.html> for details. -- Jeremiah Willcock

On Wed, 2011-10-12 at 14:56 -0400, Jeremiah Willcock wrote:
On Wed, 12 Oct 2011, Christoph wrote:
Hi,
i would like to use the bundled properties feature of the boost graph library to specify the vertex properties of my graph. The problem is that i would like to have some graph type dependent descriptor type map defined within these vertex properties. [...] You can use the adjacency_list_traits class for that; see <URL:http://www.boost.org/doc/libs/1_47_0/libs/graph/doc/adjacency_list_traits.html> for details.
This is exactly the answer to my problem. Thank you for your assistance. best regards Christoph
participants (2)
-
Christoph
-
Jeremiah Willcock