C++ 如何称呼;boost::删除“U顶点”;不重新索引顶点?
我注意到,如果我调用C++ 如何称呼;boost::删除“U顶点”;不重新索引顶点?,c++,boost,boost-graph,C++,Boost,Boost Graph,我注意到,如果我调用boost::remove_vertex,顶点将被重新索引,从零开始 例如: #include <boost/graph/adjacency_list.hpp> #include <utility> #include <algorithm> #include <iterator> #include <iostream> int main() { boost::adjacency_list<> g;
boost::remove_vertex
,顶点将被重新索引,从零开始
例如:
#include <boost/graph/adjacency_list.hpp>
#include <utility>
#include <algorithm>
#include <iterator>
#include <iostream>
int main()
{
boost::adjacency_list<> g;
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::remove_vertex(0, g); // remove vertex 0
std::pair<boost::adjacency_list<>::vertex_iterator,
boost::adjacency_list<>::vertex_iterator> vs = boost::vertices(g);
std::copy(vs.first, vs.second,
std::ostream_iterator<boost::adjacency_list<>::vertex_descriptor>{
std::cout, "\n"
});
// expects: 1, 2 and 3
// actual: 0, 1 and 2, I suspect re-indexing happened.
}
#包括
#包括
#包括
#包括
#包括
int main()
{
boost::邻接列表g;
boost::添加_顶点(g);
boost::添加_顶点(g);
boost::添加_顶点(g);
boost::添加_顶点(g);
boost::remove_顶点(0,g);//移除顶点0
std::pair vs=boost::顶点(g);
标准::复制(相对于第一个,相对于第二个,
std::ostream_迭代器{
std::cout,“\n”
});
//期望值:1、2和3
//实际:0、1和2,我怀疑发生了重新索引。
}
我想知道如何使上述代码输出1、2和3?顶点索引无效的原因是
邻接列表
模板的顶点容器选择器(顶点列表
)的默认值
template <class OutEdgeListS = vecS,
class VertexListS = vecS,
class DirectedS = directedS,
...
class adjacency_list {};
typedef boost::adjacency_list<boost::vecS,boost::listS> graph;
graph g;
graph::vertex_descriptor desc1 = boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::add_vertex(g);
boost::remove_vertex(desc1, g);
std::pair<graph::vertex_iterator,
graph::vertex_iterator> vs = boost::vertices(g);
std::copy(vs.first, vs.second,
std::ostream_iterator<graph::vertex_descriptor>{
std::cout, "\n"
});