迭代没有访问者的boost图

Iterate over boost graph without Visitor

本文关键字:boost 访问者 迭代      更新时间:2023-10-16

我需要遍历一个图(DFS),但不使用标准的DFS访问者回调技术。

是否有一种方法可以迭代地遍历图?

for(each edge in my graph visited in dfs) {
    do some complicated stuff;
}

是的,根据具体的图形类型,您可以直接使用

auto e = edges(g);
for (auto it = e.first; it != e.second; ++it)
{
}

如果你的图形模型不同的概念,你可能想要in_edges(g)out_edges(g): http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/graph_concepts.html

编辑更新注释:

那你得自己包装了。您可以使用Boost协程强制拉出接口。或者您可以使用访问器来填充队列,在DFS完成后使用该队列。