I need to iterate around the edges of the graph and check the weight of each edge. I do not change the edges, so my function accepts a const link to the chart. However, the only way I know to get the weight of the borders is to access the property map, which apparently violates the constant.
void printEdgeWeights(const Graph& graph) {
typedef Graph::edge_iterator EdgeIterator;
std::pair<EdgeIterator, EdgeIterator> edges = boost::edges(graph);
typedef boost::property_map<Graph, boost::edge_weight_t>::type WeightMap;
WeightMap weights = boost::get(boost::edge_weight_t(), graph);
EdgeIterator edge;
for (edge = edges.first; edge != edges.second; ++edge) {
std::cout << boost::get(weights, *edge) << std::endl;
}
}
So I have to do this:
Graph& trust_me = const_cast<Graph&>(graph);
WeightMap weights = boost::get(boost::edge_weight_t(), trust_me);
Is there any way to avoid this?
On a side note, will property searches be constant?
For reference, here is my definition of Graph.
struct FeatureIndex { ... };
typedef boost::property<boost::vertex_index_t, int,
FeatureIndex>
VertexProperty;
typedef boost::property<boost::edge_index_t, int,
boost::property<boost::edge_weight_t, int> >
EdgeProperty;
typedef boost::subgraph<
boost::adjacency_list<boost::vecS,
boost::vecS,
boost::undirectedS,
VertexProperty,
EdgeProperty> >
Graph;
Thank!
source
share