gpt4 book ai didi

c++ - boost 图形库,depth_first_search 不在 msvc 中调用 finish_edge

转载 作者:行者123 更新时间:2023-11-30 04:46:26 24 4
gpt4 key购买 nike

我在 vs-2017 中使用 Boost 1.70.0。使用 depth_first_search 时,我观察到访问者中的 finish_edge 函数在使用 msvc 编译器编译时未被调用。使用 gcc (8.3) 可以正确调用 finish_edge 函数

示例代码:

struct DfsVisitor : public boost::default_dfs_visitor
{
template <class Graph>
void
finish_edge(typename Graph::edge_descriptor ed, const Graph& g)
{
std::cout << "Finish edge " << boost::source(ed, g) << "->" << boost::target(ed, g) << std::endl;
}
};

DfsVisitor dfs;
boost::depth_first_search(g, boost::visitor(dfs)); // g is graph, adjacency_list

最佳答案

Do you have a SSCCE that we can actually run to observe the behavior? That will save a lot of time

我刚刚这样做了:刚刚这样做了:repro Boost 1.60 on msvc

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

struct DfsVisitor : public boost::default_dfs_visitor {
template <class Graph> void finish_edge(typename Graph::edge_descriptor ed, const Graph &g) {
std::cout << "Finish edge " << boost::source(ed, g) << "->" << boost::target(ed, g) << std::endl;
}
};

int main() {
boost::adjacency_list<> g(4);
add_edge(0,1,g);
add_edge(1,2,g);
add_edge(2,3,g);

DfsVisitor dfs;
boost::depth_first_search(g, boost::visitor(dfs));

std::cout << "Done\n";
}

只打印:

Done

为了比较,

很明显,它与 boost 版本的关系比与编译器的关系更大。 Godbolt 不会比 Boost 1.64 更早(仍然可以:https://godbolt.org/z/Ld8-8d)但 wandbox 可以:

检查 release notes for Boost 1.62.0似乎没有提到什么,但使用 github 历史确实发现了:

$ git clone https://github.com/boostorg/graph
$ cd graph
$ git log --oneline --graph --left-right --cherry-pick boost-1.61.0...boost-1.62.0 | grep -i finish
> a14f8df8 Fixed bug 10231 partly: If finish_edge was called, then now correctly. (#16)
> d6b7a717 Add finish_edge test case from Alex Lauser.
> 6a2d45ae Condition TTI finish_edge on supported compilers.
> 0e1414f4 Fix type traits so finish_edge is called when defined.

关于c++ - boost 图形库,depth_first_search 不在 msvc 中调用 finish_edge,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56746453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com