【问题标题】:Printing boost::graph edge_descriptor打印 boost::graph edge_descriptor
【发布时间】:2015-03-10 15:18:35
【问题描述】:

我正在使用boost::graph,我注意到当我只使用std::cout << *ei 时,其中ei 是从boost::edges 命令获得的边迭代器,我看到类似" (x, y)" 被打印出来,其中 xy 是整数。我假设这些数字代表顶点描述符。 据此,我有一些问题:

  • vertex_descriptor 表示在 boost::graph 中的默认类型是 int 吗?
  • 在 boost 中定义了 edge_descriptor 的任何 operator<< 以使输出看起来像我上面描述的那样?否则,我无法理解它是如何以这种方式工作的。

谢谢

【问题讨论】:

    标签: c++ boost graph


    【解决方案1】:

    Q. vertex_descriptor 在 boost::graph 中表示的默认类型是 int 吗?

    boost::graph 不是类型。

    存在许多图形类型(BGL 是一个通用模板库)。

    vertex_descriptor 的实际类型是不透明的,可以是整数。例如。它与adjacecy_list 模板参数列表中的vecS 顶点容器选择是一体的。

    Q. 是否在 boost 中定义了任何用于 edge_descriptor 的运算符

    是的。对于这样的图类型,operator<< 的以下重载被注入到命名空间std(参见boost/graph/detail/edge.hpp):

    namespace std {
    
      template <class Char, class Traits, class D, class V>
      std::basic_ostream<Char, Traits>& 
      operator<<(std::basic_ostream<Char, Traits>& os,
                 const boost::detail::edge_desc_impl<D,V>& e)
      {
        return os << "(" << e.m_source << "," << e.m_target << ")";
      }
    
    }
    

    ¹ 请注意,它可能是size_t,而不是int

    【讨论】:

    • 谢谢,真的很有帮助!
    猜你喜欢
    • 2018-08-07
    • 1970-01-01
    • 2011-03-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 2016-09-23
    相关资源
    最近更新 更多