【问题标题】:How to get the type of a property in Boost Graph Library如何在 Boost Graph Library 中获取属性的类型
【发布时间】:2018-06-10 04:51:11
【问题描述】:

在 Boost Graph Library (BGL) 中,如何以编程方式获取属性的类型,例如与 boost::edge_weight_t 关联的属性类型?

我搜索并找到了很多关于如何获取 property map 类型的示例,但没有找到 property 本身的类型。例如,下面的BGL documentation 具有edge_weight_t 的属性映射类型为property_map<DirectedGraph, edge_weight_t>::type

typedef ... DirectedGraph;
DirectedGraph digraph(V);
{
  ..
  property_map<DirectedGraph, edge_weight_t>::type
    weight = get(edge_weight, digraph);
}

但是我如何获得边缘权重的类型? (floatint 等)

如何使用适当的类型表达式(下面的???)为边缘权重声明变量,以便例如从文件/流中读取这些权重值。

typedef ... DirectedGraph;
...
??? w;
input_s >> w;

【问题讨论】:

标签: c++ boost boost-graph


【解决方案1】:

正如@llonesmiz 在 cmets 中指出的,对于属性映射类型

typedef property_map<Graph, boost::edge_weight_t>::type WeightMap

属性(权重)值的类型可以用property_traits检索为:

typedef typename boost::property_traits<WeightMap>::value_type edge_weight_type;

【讨论】:

  • 你是不是错过了::type::const_type
  • 简而言之,template &lt;typename Tag, typename Graph&gt; using propval_t = typename boost::property_traits&lt;typename property_map&lt;Graph, Tag&gt;::type&gt;::value_type; 之类的。请注意,我是凭记忆引用的。
  • 我已经 +1 了。现在我们甚至会混淆更少的未来访客:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-08
  • 1970-01-01
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 2016-03-11
相关资源
最近更新 更多