Skip to content

Commit

Permalink
examples: C++11: More use of range-based for loops.
Browse files Browse the repository at this point in the history
  • Loading branch information
murraycu committed May 12, 2017
1 parent e15388e commit 5b82ca3
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 41 deletions.
4 changes: 2 additions & 2 deletions example/copy-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ main()
E edges[] = { E(a, c), E(a, d), E(b, a), E(b, d), E(c, f),
E(d, c), E(d, e), E(d, f), E(e, b), E(e, g), E(f, e), E(f, g)
};
for (int i = 0; i < 12; ++i)
add_edge(edges[i].first, edges[i].second, G);
for (const auto& edge : edges)
add_edge(edge.first, edge.second, G);

print_graph(G, name_map);
std::cout << std::endl;
Expand Down
2 changes: 1 addition & 1 deletion example/cuthill_mckee_ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int , char* [])
using size_type = graph_traits<Graph>::vertices_size_type;

using Pair = std::pair<std::size_t, std::size_t>;
Pair edges[14] = { Pair(0,3), //a-d
Pair edges[] = { Pair(0,3), //a-d
Pair(0,5), //a-f
Pair(1,2), //b-c
Pair(1,4), //b-e
Expand Down
6 changes: 3 additions & 3 deletions example/edge_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,15 @@ main()
using MyGraph = adjacency_list<>;

using Pair = std::pair<int,int>;
Pair edge_array[8] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair edge_array[] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1) };

// Construct a graph using the edge_array (passing in pointers
// (iterators) to the beginning and end of the array), and
// specifying the number of vertices as 5
MyGraph G(5);
for (int i=0; i<8; ++i)
add_edge(edge_array[i].first, edge_array[i].second, G);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, G);

// Use the STL for_each algorithm to "exercise" all of the edges in
// the graph
Expand Down
10 changes: 5 additions & 5 deletions example/edge_coloring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ int main(int, char *[])
using Graph = adjacency_list<vecS, vecS, undirectedS, no_property, size_t, no_property>;

using Pair = std::pair<std::size_t, std::size_t>;
Pair edges[14] = { Pair(0,3), //a-d
Pair edges[] = { Pair(0,3), //a-d
Pair(0,5), //a-f
Pair(1,2), //b-c
Pair(1,4), //b-e
Expand All @@ -55,14 +55,14 @@ int main(int, char *[])

Graph G(10);

for (size_t i = 0; i < sizeof(edges)/sizeof(edges[0]); i++)
add_edge(edges[i].first, edges[i].second, G);
for (const auto& edge : edges)
add_edge(edge.first, edge.second, G);

auto colors = edge_coloring(G, get(edge_bundle, G));

std::cout << "Colored using " << colors << " colors" << std::endl;
for (size_t i = 0; i < sizeof(edges)/sizeof(edges[0]); i++) {
std::cout << " " << (char)('a' + edges[i].first) << "-" << (char)('a' + edges[i].second) << ": " << G[edge(edges[i].first, edges[i].second, G).first] << std::endl;
for (const auto& edge : edges) {
std::cout << " " << (char)('a' + edge.first) << "-" << (char)('a' + edge.second) << ": " << G[edge(edge.first, edge.second, G).first] << std::endl;
}

return 0;
Expand Down
6 changes: 3 additions & 3 deletions example/exterior_property_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ main(int, char*[])
using MyGraphType = adjacency_list<>;

using Pair = std::pair<int,int>;
Pair edge_array[11] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair edge_array[] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1),
Pair(3,4), Pair(4,0), Pair(4,1) };

MyGraphType G(5);
for (int i=0; i<11; ++i)
add_edge(edge_array[i].first, edge_array[i].second, G);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, G);

who_owes_who(edges(G).first, edges(G).second, G, names);

Expand Down
4 changes: 2 additions & 2 deletions example/filtered-copy-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ main()
E edges[] = { E(a, c), E(a, d), E(b, a), E(b, d), E(c, f),
E(d, c), E(d, e), E(d, f), E(e, b), E(e, g), E(f, e), E(f, g)
};
for (int i = 0; i < 12; ++i)
add_edge(edges[i].first, edges[i].second, G);
for (const auto& edge : edges)
add_edge(edge.first, edge.second, G);

print_graph(G, name_map);
std::cout << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions example/interior_pmap_bundled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ main()
using MyGraphType = adjacency_list<vecS, vecS, directedS, VertexData>;

using Pair = std::pair<int,int>;
Pair edge_array[11] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair edge_array[] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1),
Pair(3,4), Pair(4,0), Pair(4,1) };

MyGraphType G(5);
for (int i=0; i<11; ++i)
add_edge(edge_array[i].first, edge_array[i].second, G);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, G);

G[0].first_name = "Jeremy";
G[1].first_name = "Rich";
Expand Down
6 changes: 3 additions & 3 deletions example/interior_property_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,13 @@ main()
property<vertex_first_name_t, std::string>>;

using Pair = std::pair<int,int>;
Pair edge_array[11] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair edge_array[] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1),
Pair(3,4), Pair(4,0), Pair(4,1) };

MyGraphType G(5);
for (int i=0; i<11; ++i)
add_edge(edge_array[i].first, edge_array[i].second, G);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, G);

auto name = get(vertex_first_name, G);

Expand Down
6 changes: 3 additions & 3 deletions example/king_ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int main(int , char* [])
using size_type = graph_traits<Graph>::vertices_size_type;

using Pair = std::pair<std::size_t, std::size_t>;
Pair edges[14] = { Pair(0,3), //a-d
Pair edges[] = { Pair(0,3), //a-d
Pair(0,5), //a-f
Pair(1,2), //b-c
Pair(1,4), //b-e
Expand All @@ -56,8 +56,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 (const auto& edge : edges)
add_edge(edge.first, edge.second, G);

auto deg = get(vertex_degree, G);
for (const auto& vertex : make_range_pair(vertices(G)))
Expand Down
2 changes: 1 addition & 1 deletion example/knights_tour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ using namespace boost;

using Position = std::pair<int, int>;
Position
knight_jumps[8] = {
knight_jumps[] = {
Position(2, -1),
Position(1, -2),
Position(-1, -2),
Expand Down
2 changes: 1 addition & 1 deletion example/modify_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ void modify_demo(MutableGraph& g)

assert(out_degree(u, g) == 0);

for (const auto & vertex : make_range_pair(vertices(g))) {
for (const auto& vertex : make_range_pair(vertices(g))) {
for (const auto& adjacent_vertex : make_range_pair(adjacent_vertices(vertex, g)))
assert(adjacent_vertex != vertex);
}
Expand Down
6 changes: 3 additions & 3 deletions example/remove_edge_if_bidir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ int
main()
{
using Edge = std::pair<std::size_t,std::size_t>;
Edge edge_array[6] = { Edge(0,3), Edge(0,2), Edge(0, 3),
Edge edge_array[] = { Edge(0,3), Edge(0,2), Edge(0, 3),
Edge(1,3),
Edge(2, 0),
Edge(3, 2) };

#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
Graph g(4);
for (std::size_t j = 0; j < 6; ++j)
add_edge(edge_array[j].first, edge_array[j].second, g);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, g);
#else
Graph g(edge_array, edge_array + 6, 4);
#endif
Expand Down
6 changes: 3 additions & 3 deletions example/remove_edge_if_undir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ int
main()
{
using Edge = std::pair<std::size_t,std::size_t>;
Edge edge_array[5] = { Edge(0, 3), Edge(0, 3),
Edge edge_array[] = { Edge(0, 3), Edge(0, 3),
Edge(1, 3),
Edge(2, 0),
Edge(3, 2) };

#if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
Graph g(4);
for (std::size_t j = 0; j < 5; ++j)
add_edge(edge_array[j].first, edge_array[j].second, g);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, g);
#else
Graph g(edge_array, edge_array + 5, 4);
#endif
Expand Down
6 changes: 3 additions & 3 deletions example/sloan_ordering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ int main(int , char* [])

using Pair = std::pair<std::size_t, std::size_t>;

Pair edges[14] = { Pair(0,3), //a-d
Pair edges[] = { Pair(0,3), //a-d
Pair(0,5), //a-f
Pair(1,2), //b-c
Pair(1,4), //b-e
Expand All @@ -106,8 +106,8 @@ int main(int , char* [])

//Creating a graph and adding the edges from above into it
Graph G(10);
for (int i = 0; i < 14; ++i)
add_edge(edges[i].first, edges[i].second, G);
for (const auto& edge : edges)
add_edge(edge.first, edge.second, G);

//Creating a property_map with the degrees of the degrees of each vertex
auto deg = get(vertex_degree, G);
Expand Down
4 changes: 2 additions & 2 deletions example/transpose-example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ main()
E edge_array[] = { E(a, c), E(a, d), E(b, a), E(b, d), E(c, f),
E(d, c), E(d, e), E(d, f), E(e, b), E(e, g), E(f, e), E(f, g)
};
for (int i = 0; i < 12; ++i)
add_edge(edge_array[i].first, edge_array[i].second, G);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, G);

print_graph(G, name_map);
std::cout << std::endl;
Expand Down
6 changes: 3 additions & 3 deletions example/vertex_basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,14 @@ main()
using MyGraphType = adjacency_list<vecS,vecS,bidirectionalS>;

using Pair = std::pair<int,int>;
Pair edge_array[11] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair edge_array[] = { Pair(0,1), Pair(0,2), Pair(0,3), Pair(0,4),
Pair(2,0), Pair(3,0), Pair(2,4), Pair(3,1),
Pair(3,4), Pair(4,0), Pair(4,1) };

/* Construct a graph using the edge_array*/
MyGraphType g(5);
for (int i=0; i<11; ++i)
add_edge(edge_array[i].first, edge_array[i].second, g);
for (const auto& edge : edge_array)
add_edge(edge.first, edge.second, g);

auto id = get(vertex_index, g);

Expand Down

0 comments on commit 5b82ca3

Please sign in to comment.