Reputation: 3284
I want to have all edges have to properties, weight and capacity. I found that BGL has these both already defined. So I define Edge and Vertex properties for the Graph
typedef property<vertex_name_t, string> VertexProperty;
typedef property<edge_weight_t, int, property<edge_capacity_t, int> > EdgeProperty;
typedef adjacency_list<listS,vecS, undirectedS, VertexProperty, EdgeProperty > Graph;
Here is where I am trying to add the edges to the graph:
172: EdgeProperty prop = (weight, capacity);
173: add_edge(vertex1,vertex2, prop, g);
If I had just 1 property I know it would be prop = 5; However, with two I am confused about the formatting.
Here is the error I am receiving:
graph.cc: In function ‘void con_graph()’:
graph.cc:172: warning: left-hand operand of comma has no effect
Upvotes: 5
Views: 1931
Reputation:
The correct form is:
EdgeProperty prop;
get_property_value(prop, edge_weight) = weight;
get_property_value(prop, edge_capacity) = capacity;
Upvotes: 0
Reputation: 18562
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.
Upvotes: 7