Boost logo

Boost Users :

Subject: [Boost-users] [graph] vertex property Graph type cyclic definition problem. forward declaration not possible.
From: Christoph (c_p_at_[hidden])
Date: 2011-10-12 12:31:05


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


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net