开发者

Boost graph recursive template problem

Hi I have a boost graph like:

struct Vertex;
struct Edge;



typedef boo开发者_开发知识库st::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.


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;


Try using an adjacency_list:

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜