BGL:当包含 random_spanning_tree.hpp 时,对 strong_components 的调用无法编译

BGL: call to strong_components fails to compile when random_spanning_tree.hpp is included

这是一个奇怪的问题,我希望在一个现有函数中使用 boost::random_spanning_tree,该函数也调用 boost::strong_components 但仅包含 boost/graph/random_spanning_tree.hpp 而不修改代码会导致 gcc 生成编译错误。

函数看起来像这样:

#include "boost/graph/adjacency_list.hpp"
#include "boost/graph/strong_components.hpp"                                    
//#include "boost/graph/random_spanning_tree.hpp" // can't include this!

void foo() {
  boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> g;

  // TODO: add some vertices

  std::vector<unsigned> component(boost::num_vertices(g));
  unsigned num = boost::strong_components(g, &component[0]);
}

gcc 抱怨:

error: no matching function for call to ‘get(unsigned int*&, boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS> >::vertex_descriptor&)’
           if (get(comp, w) == (std::numeric_limits<comp_type>::max)())

是代码本身有缺陷还是这是 Boost 的问题?

编辑:

我必须道歉,我在我的最小示例中犯了一个小错误,如果包含 boost/graph/random_spanning_tree.hpp,上面的代码只能在我的系统(Linus,g++ 8.2.1,Boost 1.67)上编译失败 之前 boost/graph/strong_components.hpp。使用 wandbox,我发现没有编译器/Boost 版本的组合不会发生这种情况。

我会为此提交一张票,但 Boost 使这变得不必要地困难(我没有 TICKET_CREATE Boost's Trac 的权利,但在任何地方都没有指定如何获得这些权利)。

这里没问题:Live On Coliru

Also try

这让我相信这是您 code/compiler 配置的其余部分的问题。

你在 windows 吗?我看到 maxwindows.h 中的一个 MACRO。一定不要包括它(如果你使用它,还要检查 stdafx.h

更新

经过您的编辑,我能够重现错误。这是 boost 中的一个错误,我已经在 the bug tracker

为它创建了一张票