diff --git a/example/cuthill_mckee_ordering.cpp b/example/cuthill_mckee_ordering.cpp index 6406e933..3ca7e028 100644 --- a/example/cuthill_mckee_ordering.cpp +++ b/example/cuthill_mckee_ordering.cpp @@ -57,8 +57,8 @@ int main(int, char*[]) Pair(6, 7) }; // g-h Graph G(10); - for (int i = 0; i < 14; ++i) - add_edge(edges[i].first, edges[i].second, G); + for (auto const& edge : edges) + add_edge(edge.first, edge.second, G); graph_traits< Graph >::vertex_iterator ui, ui_end; @@ -79,8 +79,8 @@ int main(int, char*[]) get(vertex_degree, G)); cout << "Reverse Cuthill-McKee ordering starting at: " << s << endl; cout << " "; - for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i) - cout << index_map[*i] << " "; + for (auto const& vertex : inv_perm) + cout << index_map[vertex] << " "; cout << endl; for (size_type c = 0; c != inv_perm.size(); ++c) @@ -98,8 +98,8 @@ int main(int, char*[]) get(vertex_degree, G)); cout << "Reverse Cuthill-McKee ordering starting at: " << s << endl; cout << " "; - for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i) - cout << index_map[*i] << " "; + for (auto const& vertex : inv_perm) + cout << index_map[vertex] << " "; cout << endl; for (size_type c = 0; c != inv_perm.size(); ++c) @@ -118,8 +118,8 @@ int main(int, char*[]) cout << "Reverse Cuthill-McKee ordering:" << endl; cout << " "; - for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i) - cout << index_map[*i] << " "; + for (auto const& vertex : inv_perm) + cout << index_map[vertex] << " "; cout << endl; for (size_type c = 0; c != inv_perm.size(); ++c) diff --git a/example/edge-connectivity.cpp b/example/edge-connectivity.cpp index 5f93d54e..422013b1 100644 --- a/example/edge-connectivity.cpp +++ b/example/edge-connectivity.cpp @@ -136,13 +136,13 @@ typename graph_traits< VertexListGraph >::degree_size_type edge_connectivity( } std::vector< bool > in_S_star(num_vertices(g), false); - for (auto si = S_star.begin(); si != S_star.end(); ++si) - in_S_star[*si] = true; + for (auto const& vertex : S_star.begin()) + in_S_star[vertex] = true; degree_size_type c = 0; - for (auto si = S_star.begin(); si != S_star.end(); ++si) + for (auto const& vertex : S_star.begin()) { typename graph_traits< VertexListGraph >::out_edge_iterator ei, ei_end; - for (boost::tie(ei, ei_end) = out_edges(*si, g); ei != ei_end; ++ei) + for (boost::tie(ei, ei_end) = out_edges(vertex, g); ei != ei_end; ++ei) if (!in_S_star[target(*ei, g)]) { *disconnecting_set++ = *ei; @@ -170,9 +170,9 @@ int main() auto attr_map = get(vertex_attribute, g); std::cout << "The disconnecting set is {"; - for (auto i = disconnecting_set.begin(); i != disconnecting_set.end(); ++i) - std::cout << "(" << attr_map[source(*i, g)]["label"] << "," - << attr_map[target(*i, g)]["label"] << ") "; + for (auto const& edge : disconnecting_set) + std::cout << "(" << attr_map[source(edge, g)]["label"] << "," + << attr_map[target(edge, g)]["label"] << ") "; std::cout << "}." << std::endl; return EXIT_SUCCESS; } diff --git a/example/king_ordering.cpp b/example/king_ordering.cpp index ad335091..211f2540 100644 --- a/example/king_ordering.cpp +++ b/example/king_ordering.cpp @@ -98,8 +98,8 @@ int main(int, char*[]) get(vertex_degree, G), get(vertex_index, G)); cout << "King ordering starting at: " << s << endl; cout << " "; - for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i) - cout << index_map[*i] << " "; + for (auto const& vertex : inv_perm) + cout << index_map[vertex] << " "; cout << endl; for (size_type c = 0; c != inv_perm.size(); ++c) @@ -118,8 +118,8 @@ int main(int, char*[]) cout << "King ordering:" << endl; cout << " "; - for (auto i = inv_perm.begin(); i != inv_perm.end(); ++i) - cout << index_map[*i] << " "; + for (auto const& vertex : inv_perm) + cout << index_map[vertex] << " "; cout << endl; for (size_type c = 0; c != inv_perm.size(); ++c) diff --git a/example/kruskal-telephone.cpp b/example/kruskal-telephone.cpp index 78f62896..e4a48ab9 100644 --- a/example/kruskal-telephone.cpp +++ b/example/kruskal-telephone.cpp @@ -46,14 +46,14 @@ int main() auto weight = get(edge_weight, g); int total_weight = 0; - for (size_type e = 0; e < mst.size(); ++e) - total_weight += get(weight, mst[e]); + for (auto const& edge : mst) + total_weight += get(weight, edge); std::cout << "total weight: " << total_weight << std::endl; typedef graph_traits< Graph >::vertex_descriptor Vertex; - for (size_type i = 0; i < mst.size(); ++i) + for (auto const& edge : mst) { - auto u = source(mst[i], g), v = target(mst[i], g); + auto u = source(edge, g), v = target(edge, g); edge_attr_map[edge(u, v, g_dot).first]["color"] = "black"; } std::ofstream out("figs/telephone-mst-kruskal.dot"); diff --git a/example/matching_example.cpp b/example/matching_example.cpp index ccbf1736..39c9b7cd 100644 --- a/example/matching_example.cpp +++ b/example/matching_example.cpp @@ -74,8 +74,8 @@ int main() std::cout << "In the following graph:" << std::endl << std::endl; - for (auto itr = ascii_graph.begin(); itr != ascii_graph.end(); ++itr) - std::cout << *itr << std::endl; + for (auto const& str : ascii_graph) + std::cout << str << std::endl; std::cout << std::endl << "Found a matching of size " << matching_size(g, &mate[0]) diff --git a/example/topo-sort1.cpp b/example/topo-sort1.cpp index 4db2cb3b..9b5b0dd2 100644 --- a/example/topo-sort1.cpp +++ b/example/topo-sort1.cpp @@ -28,9 +28,8 @@ int main() topological_sort(g, std::front_inserter(topo_order), vertex_index_map(identity_property_map())); - int n = 1; - for (auto i = topo_order.begin(); i != topo_order.end(); ++i, ++n) - std::cout << tasks[*i] << std::endl; + for (auto const& vertex : topo_order) + std::cout << tasks[vertex] << std::endl; return EXIT_SUCCESS; } diff --git a/example/topo-sort2.cpp b/example/topo-sort2.cpp index 97c15e0a..941abcb4 100644 --- a/example/topo-sort2.cpp +++ b/example/topo-sort2.cpp @@ -35,9 +35,8 @@ int main() topological_sort(g, std::front_inserter(topo_order), vertex_index_map(identity_property_map())); - int n = 1; - for (auto i = topo_order.begin(); i != topo_order.end(); ++i, ++n) - std::cout << tasks[*i] << std::endl; + for (auto const& vertex : topo_order) + std::cout << tasks[vertex] << std::endl; return EXIT_SUCCESS; }