piotr
piotr

Reputation: 5787

Boost graph recursive template problem

Hi I have a boost graph like:

struct Vertex;
struct Edge;



typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Vertex, Edge> Graph_t;


struct Vertex {
};

struct Edge {
    typedef std::vector<Graph_t::vertex_descriptor> intermediate_vertices_t;
    intermediate_vertices_t intermediate_vertices;
};

The problem is with the recursive template in the Edge class. I need to store a vector of vertices.

Upvotes: 0

Views: 237

Answers (3)

user1252091
user1252091

Reputation:

You can use adjacency_list_traits to get around this problem. This class allows the user access to the vertex and edge descriptor types without requiring the user to provide the property types for the graph.

struct Vertex {
};

typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::bidirectionalS>::vertex_descriptor VertexDescriptor;
struct Edge {
    typedef std::vector<VertexDescriptor> intermediate_vertices_t;
    intermediate_vertices_t intermediate_vertices;
};
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Vertex, Edge> Graph_t;

Upvotes: 3

piotr
piotr

Reputation: 5787

I ended up using a small wrapper class like:

typedef Graph_t::vertex_descriptor vd_t;                           

struct iVertexWrap{                                                
    iVertexWrap(vd_t v) : v(v)
    {}                                                             
    vd_t v;
};

forward declaring it before the Edge class.

Upvotes: 0

Pau
Pau

Reputation: 1

Try using an adjacency_list:

http://www.boost.org/doc/libs/1_36_0/libs/graph/doc/adjacency_list.html

Upvotes: 0

Related Questions