我想用纯 C++11 等价物替换顶点或边上的 BGL 迭代。BGL 代码(来自: http: //www.boost.org/doc/libs/1_52_0/libs/graph/doc/quick_tour.html)是:
typename boost::graph_traits<Graph>::out_edge_iterator out_i, out_end;
typename boost::graph_traits<Graph>::edge_descriptor e;
for (std::tie(out_i, out_end) = out_edges(v, g);
out_i != out_end; ++out_i)
{
e = *out_i;
Vertex src = source(e, g), targ = target(e, g);
std::cout << "(" << name[get(vertex_id, src)]
<< "," << name[get(vertex_id, targ)] << ") ";
}
我从这里尝试了几个建议:Replace BOOST_FOREACH with "pure" C++11 alternative? 但没有运气。
我希望能够写出类似的东西:
for (auto &e : out_edges(v, g))
{ ... }
或类似的东西:
for (std::tie(auto out_i, auto out_end) = out_edges(v, g);
out_i != out_end; ++out_i)
{...}
是否可以?