[property_map, graph] optional properties

Is there any support for optional properties in boost.graph? Suppose I want to write/read a graph to/from a file format that supports edge weights. It should be possible to write a function template that works with all graphs and writes/reads edge weights if those properties are in the graph. Is this currently possible using boost.graph? Would the following make sense: - add an operator bool() to the property_map concept that returns true for existing property map classes - add a class empty_property_map with an operator bool() that always returns false - make Graph.get() return empty_property_map for non-existing properties This would enable constructs such as: edge_weight_property_map = get(edge_weight, graph); if (edge_weight_property_map ) { std::cout >> edge_weight_property_map[0] >> ... } -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/

Hello, If i understand correctly, what you're asking is to be able to detect if a property is part of a graph or not.
edge_weight_property_map = get(edge_weight, graph); if (edge_weight_property_map ) {...}
It's pretty clear in the example you've given that this information is held by the type of the object "edge_weight_property_map". So the bool() operator you're asking for is, in my opinion, not necessary. Play a bit with boost::enable_if and boost::property_map<Graph, edge_weight_t> and you should be able to do what you want. BenoƮt

Benoit wrote:
It's pretty clear in the example you've given that this information is held by the type of the object "edge_weight_property_map". So the bool() operator you're asking for is, in my opinion, not necessary. Play a bit with boost::enable_if and boost::property_map<Graph, edge_weight_t> and you should be able to do what you want.
True, but I was looking for a bit more concise way. PS: This would also blend in well with the "pointer as property map" concept. -- Ares Lagae Computer Graphics Research Group, Katholieke Universiteit Leuven http://www.cs.kuleuven.be/~ares/
participants (2)
-
Ares Lagae
-
Benoit