为什么可以';我使用boost graph write_graphviz,OutEdgeList=列表,VertexList=列表

为什么可以';我使用boost graph write_graphviz,OutEdgeList=列表,VertexList=列表,boost,boost-graph,Boost,Boost Graph,为什么我不能编译以下简单的应用程序。如果我将列表更改为vecS,一切正常。(我正在使用boost 1.46.1和gcc 4.4.5) #包括 #包括 #包括 int main(int argc,const char*argv[]{ boost::adjacence_listg; boost::write_graphviz(std::cout,g); 返回0; } write_graphviz需要顶点id属性来显示顶点标识符标签。使用列表作为顶点容器的邻接列表不会自动提供此顶点id属性。这种行为是

为什么我不能编译以下简单的应用程序。如果我将列表更改为vecS,一切正常。(我正在使用boost 1.46.1和gcc 4.4.5)

#包括
#包括
#包括
int main(int argc,const char*argv[]{
boost::adjacence_listg;
boost::write_graphviz(std::cout,g);
返回0;
}

write_graphviz
需要
顶点id
属性来显示顶点标识符标签。使用
列表
作为顶点容器的
邻接列表
不会自动提供此
顶点id
属性。这种行为是有意义的,因为在链表中,没有键或索引这样的东西可以用来唯一地标识元素。请记住,链表既不是随机访问序列,也不是关联容器

您必须提供自己的
vertex\u id
属性getter,或者使用具有固有
vertex\u id
属性的顶点容器

#include <iostream>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graphviz.hpp>

int main(int argc, const char *argv[]) {
    boost::adjacency_list< boost::listS, boost::listS, boost::bidirectionalS > g;

    boost::write_graphviz(std::cout, g);

    return 0;
}