Skip to content

Commit 05edb38

Browse files
committed
Replace Boost::foreach dependency with range-based for
1 parent ce1daeb commit 05edb38

10 files changed

+35
-48
lines changed

CMakeLists.txt

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ target_link_libraries(boost_graph
2929
Boost::conversion
3030
Boost::core
3131
Boost::detail
32-
Boost::foreach
3332
Boost::function
3433
Boost::integer
3534
Boost::iterator

doc/incremental_components.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ <H3>Example</H3>
142142
print_graph(graph, get(boost::vertex_index, graph));
143143
std::cout << std::endl;
144144

145-
BOOST_FOREACH(Vertex current_vertex, vertices(graph)) {
145+
for (Vertex current_vertex: vertices(graph)) {
146146
std::cout << "representative[" << current_vertex << "] = " <<
147147
ds.find_set(current_vertex) << std::endl;
148148
}
@@ -158,12 +158,11 @@ <H3>Example</H3>
158158
Components components(parent.begin(), parent.end());
159159
160160
// Iterate through the component indices
161-
BOOST_FOREACH(VertexIndex current_index, components) {
161+
for (VertexIndex current_index: components) {
162162
std::cout << "component " << current_index << " contains: ";
163163

164164
// Iterate through the child vertex indices for [current_index]
165-
BOOST_FOREACH(VertexIndex child_index,
166-
components[current_index]) {
165+
for (VertexIndex child_index: components[current_index]) {
167166
std::cout << child_index << " ";
168167
}
169168

example/graph-thingie.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <boost/graph/graphviz.hpp>
1313
#include <boost/graph/adjacency_list.hpp>
14-
#include <boost/foreach.hpp>
1514
#include <string>
1615
#include <sstream>
1716
#include <cstdlib>
@@ -99,7 +98,7 @@ int main()
9998
cout << "graph " << get("name", dp, &graph) << " ("
10099
<< get("identifier", dp, &graph) << ")\n\n";
101100

102-
BOOST_FOREACH (graph_t::vertex_descriptor v, vertices(graph))
101+
for (graph_t::vertex_descriptor v: vertices(graph))
103102
{
104103
cout << "vertex " << get("node_id", dp, v) << " ("
105104
<< get("label", dp, v) << ")\n";

example/incremental-components-eg.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <iostream>
1212
#include <vector>
1313

14-
#include <boost/foreach.hpp>
1514
#include <boost/graph/adjacency_list.hpp>
1615
#include <boost/graph/incremental_components.hpp>
1716
#include <boost/pending/disjoint_sets.hpp>
@@ -53,7 +52,7 @@ int main(int argc, char* argv[])
5352
ds.union_set(4, 0);
5453
ds.union_set(2, 5);
5554

56-
BOOST_FOREACH (Vertex current_vertex, vertices(graph))
55+
for (Vertex current_vertex: vertices(graph))
5756
{
5857
std::cout << "representative[" << current_vertex
5958
<< "] = " << ds.find_set(current_vertex) << std::endl;
@@ -69,12 +68,12 @@ int main(int argc, char* argv[])
6968
Components components(parent.begin(), parent.end());
7069

7170
// Iterate through the component indices
72-
BOOST_FOREACH (VertexIndex component_index, components)
71+
for (VertexIndex component_index: components)
7372
{
7473
std::cout << "component " << component_index << " contains: ";
7574

7675
// Iterate through the child vertex indices for [component_index]
77-
BOOST_FOREACH (VertexIndex child_index, components[component_index])
76+
for (VertexIndex child_index: components[component_index])
7877
{
7978
std::cout << child_index << " ";
8079
}

example/incremental_components.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <iostream>
1111
#include <vector>
1212

13-
#include <boost/foreach.hpp>
1413
#include <boost/graph/adjacency_list.hpp>
1514
#include <boost/graph/graph_utility.hpp>
1615
#include <boost/graph/incremental_components.hpp>
@@ -86,7 +85,7 @@ int main(int argc, char* argv[])
8685
print_graph(graph, get(boost::vertex_index, graph));
8786
std::cout << std::endl;
8887

89-
BOOST_FOREACH (Vertex current_vertex, vertices(graph))
88+
for (Vertex current_vertex: vertices(graph))
9089
{
9190
std::cout << "representative[" << current_vertex
9291
<< "] = " << ds.find_set(current_vertex) << std::endl;
@@ -103,12 +102,12 @@ int main(int argc, char* argv[])
103102
Components components(parent.begin(), parent.end());
104103

105104
// Iterate through the component indices
106-
BOOST_FOREACH (VertexIndex current_index, components)
105+
for (VertexIndex current_index: components)
107106
{
108107
std::cout << "component " << current_index << " contains: ";
109108

110109
// Iterate through the child vertex indices for [current_index]
111-
BOOST_FOREACH (VertexIndex child_index, components[current_index])
110+
for (VertexIndex child_index: components[current_index])
112111
{
113112
std::cout << child_index << " ";
114113
}

include/boost/graph/graphviz.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
#include <boost/static_assert.hpp>
3535
#include <boost/algorithm/string/replace.hpp>
3636
#include <boost/xpressive/xpressive_static.hpp>
37-
#include <boost/foreach.hpp>
3837

3938
namespace boost
4039
{
@@ -843,13 +842,13 @@ namespace detail
843842
edge_permutation_from_sorting[temp[e]] = e;
844843
}
845844
typedef boost::tuple< id_t, bgl_vertex_t, id_t > v_prop;
846-
BOOST_FOREACH (const v_prop& t, vertex_props)
845+
for (const v_prop& t: vertex_props)
847846
{
848847
put(boost::get< 0 >(t), dp_, boost::get< 1 >(t),
849848
boost::get< 2 >(t));
850849
}
851850
typedef boost::tuple< id_t, bgl_edge_t, id_t > e_prop;
852-
BOOST_FOREACH (const e_prop& t, edge_props)
851+
for (const e_prop& t: edge_props)
853852
{
854853
put(boost::get< 0 >(t), dp_,
855854
edge_permutation_from_sorting[boost::get< 1 >(t)],

include/boost/graph/hawick_circuits.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
#include <algorithm>
1111
#include <boost/assert.hpp>
12-
#include <boost/foreach.hpp>
1312
#include <boost/graph/graph_traits.hpp>
1413
#include <boost/graph/one_bit_color_map.hpp>
1514
#include <boost/graph/properties.hpp>
@@ -134,7 +133,7 @@ namespace hawick_circuits_detail
134133
// documented above.
135134
bool blocked_map_starts_all_unblocked() const
136135
{
137-
BOOST_FOREACH (Vertex v, vertices(graph_))
136+
for (Vertex v: vertices(graph_))
138137
if (is_blocked(v))
139138
return false;
140139
return true;
@@ -144,7 +143,7 @@ namespace hawick_circuits_detail
144143
// sharing data structures between iterations does not break the code.
145144
bool all_closed_rows_are_empty() const
146145
{
147-
BOOST_FOREACH (typename ClosedMatrix::reference row, closed_)
146+
for (const auto& row: closed_)
148147
if (!row.empty())
149148
return false;
150149
return true;

src/graphml.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
// Tiago de Paula Peixoto
1212

1313
#define BOOST_GRAPH_SOURCE
14-
#include <boost/foreach.hpp>
1514
#include <boost/optional.hpp>
1615
#include <boost/throw_exception.hpp>
1716
#include <boost/graph/graphml.hpp>
@@ -44,7 +43,7 @@ class graphml_reader
4443
using boost::property_tree::ptree;
4544
size_t current_idx = 0;
4645
bool is_first = is_root;
47-
BOOST_FOREACH (const ptree::value_type& n, top)
46+
for (const ptree::value_type& n: top)
4847
{
4948
if (n.first == "graph")
5049
{
@@ -54,7 +53,7 @@ class graphml_reader
5453
if (is_first)
5554
{
5655
is_first = false;
57-
BOOST_FOREACH (const ptree::value_type& attr, n.second)
56+
for (const ptree::value_type& attr: n.second)
5857
{
5958
if (attr.first != "data")
6059
continue;
@@ -83,7 +82,7 @@ class graphml_reader
8382
| boost::property_tree::xml_parser::trim_whitespace);
8483
ptree gml = pt.get_child(path("graphml"));
8584
// Search for attributes
86-
BOOST_FOREACH (const ptree::value_type& child, gml)
85+
for (const ptree::value_type& child: gml)
8786
{
8887
if (child.first != "key")
8988
continue;
@@ -127,17 +126,17 @@ class graphml_reader
127126
std::vector< const ptree* > graphs;
128127
handle_graph();
129128
get_graphs(gml, desired_idx, true, graphs);
130-
BOOST_FOREACH (const ptree* gr, graphs)
129+
for (const ptree* gr: graphs)
131130
{
132131
// Search for nodes
133-
BOOST_FOREACH (const ptree::value_type& node, *gr)
132+
for (const ptree::value_type& node: *gr)
134133
{
135134
if (node.first != "node")
136135
continue;
137136
std::string id
138137
= node.second.get< std::string >(path("<xmlattr>/id"));
139138
handle_vertex(id);
140-
BOOST_FOREACH (const ptree::value_type& attr, node.second)
139+
for (const ptree::value_type& attr: node.second)
141140
{
142141
if (attr.first != "data")
143142
continue;
@@ -148,13 +147,13 @@ class graphml_reader
148147
}
149148
}
150149
}
151-
BOOST_FOREACH (const ptree* gr, graphs)
150+
for (const ptree* gr: graphs)
152151
{
153152
bool default_directed
154153
= gr->get< std::string >(path("<xmlattr>/edgedefault"))
155154
== "directed";
156155
// Search for edges
157-
BOOST_FOREACH (const ptree::value_type& edge, *gr)
156+
for (const ptree::value_type& edge: *gr)
158157
{
159158
if (edge.first != "edge")
160159
continue;
@@ -180,7 +179,7 @@ class graphml_reader
180179
}
181180
size_t old_edges_size = m_edge.size();
182181
handle_edge(source, target);
183-
BOOST_FOREACH (const ptree::value_type& attr, edge.second)
182+
for (const ptree::value_type& attr: edge.second)
184183
{
185184
if (attr.first != "data")
186185
continue;

test/grid_graph_test.cpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <set>
1313
#include <ctime>
1414

15-
#include <boost/foreach.hpp>
1615
#include <boost/lexical_cast.hpp>
1716
#include <boost/graph/grid_graph.hpp>
1817
#include <boost/random.hpp>
@@ -100,7 +99,7 @@ template < unsigned int Dims > void do_test(minstd_rand& generator)
10099

101100
// Verify all vertices are within bounds
102101
vertices_size_type vertex_count = 0;
103-
BOOST_FOREACH (vertex_descriptor current_vertex, vertices(graph))
102+
for (vertex_descriptor current_vertex: vertices(graph))
104103
{
105104

106105
vertices_size_type current_index
@@ -118,8 +117,7 @@ template < unsigned int Dims > void do_test(minstd_rand& generator)
118117
edges_size_type out_edge_count = 0;
119118
std::set< vertices_size_type > target_vertices;
120119

121-
BOOST_FOREACH (
122-
edge_descriptor out_edge, out_edges(current_vertex, graph))
120+
for (edge_descriptor out_edge: out_edges(current_vertex, graph))
123121
{
124122

125123
target_vertices.insert(
@@ -133,7 +131,7 @@ template < unsigned int Dims > void do_test(minstd_rand& generator)
133131
// Verify in-edges of this vertex
134132
edges_size_type in_edge_count = 0;
135133

136-
BOOST_FOREACH (edge_descriptor in_edge, in_edges(current_vertex, graph))
134+
for (edge_descriptor in_edge: in_edges(current_vertex, graph))
137135
{
138136

139137
BOOST_TEST(target_vertices.count(get(boost::vertex_index, graph,
@@ -153,7 +151,7 @@ template < unsigned int Dims > void do_test(minstd_rand& generator)
153151
// Verify adjacent vertices to this vertex
154152
vertices_size_type adjacent_count = 0;
155153

156-
BOOST_FOREACH (vertex_descriptor adjacent_vertex,
154+
for (vertex_descriptor adjacent_vertex:
157155
adjacent_vertices(current_vertex, graph))
158156
{
159157

@@ -168,7 +166,7 @@ template < unsigned int Dims > void do_test(minstd_rand& generator)
168166

169167
// Verify that this vertex is not listed as connected to any
170168
// vertices outside of its adjacent vertices.
171-
BOOST_FOREACH (vertex_descriptor unconnected_vertex, vertices(graph))
169+
for (vertex_descriptor unconnected_vertex: vertices(graph))
172170
{
173171

174172
vertices_size_type unconnected_index
@@ -193,7 +191,7 @@ template < unsigned int Dims > void do_test(minstd_rand& generator)
193191

194192
// Verify all edges are within bounds
195193
edges_size_type edge_count = 0;
196-
BOOST_FOREACH (edge_descriptor current_edge, edges(graph))
194+
for (edge_descriptor current_edge: edges(graph))
197195
{
198196

199197
vertices_size_type source_index

test/incremental_components_test.cpp

+6-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <set>
1313
#include <ctime>
1414

15-
#include <boost/foreach.hpp>
1615
#include <boost/graph/adjacency_list.hpp>
1716
#include <boost/graph/incremental_components.hpp>
1817
#include <boost/graph/random.hpp>
@@ -69,20 +68,19 @@ template < typename Graph > void test_graph(const Graph& graph)
6968
// Create a reverse-lookup map for vertex indices
7069
std::vector< vertex_descriptor > reverse_index_map(num_vertices(graph));
7170

72-
BOOST_FOREACH (vertex_descriptor vertex, vertices(graph))
71+
for (vertex_descriptor vertex: vertices(graph))
7372
{
7473
reverse_index_map[get(get(boost::vertex_index, graph), vertex)]
7574
= vertex;
7675
}
7776

7877
// Verify that components are really connected
79-
BOOST_FOREACH (vertices_size_type component_index, vertex_components)
78+
for (vertices_size_type component_index: vertex_components)
8079
{
8180

8281
std::set< vertex_descriptor > component_vertices;
8382

84-
BOOST_FOREACH (
85-
vertices_size_type child_index, vertex_components[component_index])
83+
for (vertices_size_type child_index: vertex_components[component_index])
8684
{
8785

8886
vertex_descriptor child_vertex = reverse_index_map[child_index];
@@ -92,7 +90,7 @@ template < typename Graph > void test_graph(const Graph& graph)
9290

9391
// Verify that children are connected to each other in some
9492
// manner, but not to vertices outside their component.
95-
BOOST_FOREACH (vertex_descriptor child_vertex, component_vertices)
93+
for (vertex_descriptor child_vertex: component_vertices)
9694
{
9795

9896
// Skip orphan vertices
@@ -105,8 +103,7 @@ template < typename Graph > void test_graph(const Graph& graph)
105103
// another vertex in the component.
106104
bool edge_exists = false;
107105

108-
BOOST_FOREACH (
109-
edge_descriptor child_edge, out_edges(child_vertex, graph))
106+
for (edge_descriptor child_edge: out_edges(child_vertex, graph))
110107
{
111108

112109
if (component_vertices.count(target(child_edge, graph)) > 0)
@@ -162,7 +159,7 @@ int main(int argc, char* argv[])
162159

163160
// Assign indices to list_graph's vertices
164161
graph_traits< ListGraph >::vertices_size_type index = 0;
165-
BOOST_FOREACH (graph_traits< ListGraph >::vertex_descriptor vertex,
162+
for (graph_traits< ListGraph >::vertex_descriptor vertex:
166163
vertices(list_graph))
167164
{
168165
put(get(boost::vertex_index, list_graph), vertex, index++);

0 commit comments

Comments
 (0)