An alternate solution would be to use property maps. Here's an example.
// Edge weight.
typedef boost::property<boost::edge_weight_t, int> EdgeWeightProperty;
// Graph.
typedef boost::adjacency_list< boost::listS,
boost::vecS,
boost::undirectedS,
boost::no_property,
EdgeWeightProperty > Graph;
// Vertex descriptor.
typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
// The Graph object
Graph g;
// Populates the graph.
Vertex v1 = boost::add_vertex(g);
Vertex v2 = boost::add_vertex(g);
Vertex v3 = boost::add_vertex(g);
boost::add_edge(v1, v2, EdgeWeightProperty(2), g);
boost::add_edge(v1, v3, EdgeWeightProperty(4), g);
boost::add_edge(v2, v3, EdgeWeightProperty(5), g);
// The property map associated with the weights.
boost::property_map < Graph,
boost::edge_weight_t >::type EdgeWeightMap = get(boost::edge_weight, g);
// Loops over all edges and add 10 to their weight.
boost::graph_traits< Graph >::edge_iterator e_it, e_end;
for(std::tie(e_it, e_end) = boost::edges(g); e_it != e_end; ++e_it)
{
EdgeWeightMap[*e_it] += 10;
}
// Prints the weighted edgelist.
for(std::tie(e_it, e_end) = boost::edges(g); e_it != e_end; ++e_it)
{
std::cout << boost::source(*e_it, g) << " "
<< boost::target(*e_it, g) << " "
<< EdgeWeightMap[*e_it] << std::endl;
}