首页 文章

如何在Boost图库中获取属性的类型

提问于
浏览
2

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

我搜索并找到了很多关于如何获取 property map 类型的示例,但没有找到属性本身的类型 . 例如,BGL documentation下面的 edge_weight_t 属性 Map 的类型为 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;

1 回答

  • 2

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

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

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

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

相关问题