BGL Adding an edge with multiple properties

与世无争的帅哥 提交于 2019-12-04 09:16:22

If you look at the implementation of boost::property you'll see that a property value cannot be initialized this way. And even then, the syntax you have (weight, capacity) is not valid anyways, so, if it was possible to initialize the property like that, it would be written EdgeProperty prop = EdgeProperty(weight, capacity); or just EdgeProperty prop(weight, capacity);. But, again, that won't work. Technically, this is the way you would need to initialize the property value:

EdgeProperty prop = EdgeProperty(weight, property<edge_capacity_t, int>(capacity));

But this is kind of ugly as the number of properties increase. So, it would be cleaner to default-construct the edge-property and then manually set each individual property:

EdgeProperty prop;
get_property_value(prop, edge_weight_t) = weight;
get_property_value(prop, edge_capacity_t) = capacity;

Of course, the better alternative is to use bundled properties instead of the older boost::property chains.

The correct form is:

EdgeProperty prop;
get_property_value(prop, edge_weight) = weight;
get_property_value(prop, edge_capacity) = capacity;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!