在Boost图库(BGL)中,如何以编程方式获取属性的类型,例如与boost::edge_weight_t
关联的属性?
我搜索并找到了很多关于如何获取 属性映射 类型的示例,但没有找到属性本身的类型。例如,下面的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);
}
但是如何获得边缘重量的类型? (float
,int
等)
如何使用适当的类型表达式(下面的)声明边权重的变量,以便我可以,例如,从文件/流中读取这些权重值。
typedef ... DirectedGraph;
...
??? w;
input_s >> w;
答案 0 :(得分: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;