Skip to content

Commit

Permalink
examples: C++11: Replace BOOST_FOREACH() with range-based for.
Browse files Browse the repository at this point in the history
  • Loading branch information
murraycu committed Nov 29, 2018
1 parent 9b27366 commit 99b1a6e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions example/graph-thingie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include <boost/graph/graphviz.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/foreach.hpp>
#include "range_pair.hpp"
#include <string>
#include <sstream>
#include <cstdlib>
Expand Down Expand Up @@ -93,7 +93,7 @@ const char* dot =
std::cout << "graph " << get("name",dp,&graph) <<
" (" << get("identifier",dp,&graph) << ")\n\n";

BOOST_FOREACH( graph_t::vertex_descriptor v, vertices(graph) ) {
for (auto v : make_range_pair(vertices(graph))) {
std::cout << "vertex " << get("node_id",dp,v) <<
" (" << get("label",dp,v) << ")\n";
}
Expand Down
9 changes: 4 additions & 5 deletions example/incremental-components-eg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
#include <iostream>
#include <vector>

#include <boost/foreach.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/incremental_components.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include "range_pair.hpp"

using namespace boost;

Expand Down Expand Up @@ -53,7 +53,7 @@ int main(int argc, char* argv[])
ds.union_set(4, 0);
ds.union_set(2, 5);

BOOST_FOREACH(Vertex current_vertex, vertices(graph)) {
for (auto current_vertex : make_range_pair(vertices(graph))) {
std::cout << "representative[" << current_vertex << "] = " <<
ds.find_set(current_vertex) << std::endl;
}
Expand All @@ -68,12 +68,11 @@ int main(int argc, char* argv[])
Components components(parent.begin(), parent.end());

// Iterate through the component indices
BOOST_FOREACH(VertexIndex component_index, components) {
for (auto component_index : components) {
std::cout << "component " << component_index << " contains: ";

// Iterate through the child vertex indices for [component_index]
BOOST_FOREACH(VertexIndex child_index,
components[component_index]) {
for (auto child_index : make_range_pair(components[component_index])) {
std::cout << child_index << " ";
}

Expand Down
9 changes: 4 additions & 5 deletions example/incremental_components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
#include <iostream>
#include <vector>

#include <boost/foreach.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/graph_utility.hpp>
#include <boost/graph/incremental_components.hpp>
#include <boost/pending/disjoint_sets.hpp>
#include "range_pair.hpp"

/*
Expand Down Expand Up @@ -83,7 +83,7 @@ int main(int argc, char* argv[])
print_graph(graph, get(boost::vertex_index, graph));
std::cout << std::endl;

BOOST_FOREACH(Vertex current_vertex, vertices(graph)) {
for ( auto current_vertex : make_range_pair(vertices(graph)) ) {
std::cout << "representative[" << current_vertex << "] = " <<
ds.find_set(current_vertex) << std::endl;
}
Expand All @@ -99,12 +99,11 @@ int main(int argc, char* argv[])
Components components(parent.begin(), parent.end());

// Iterate through the component indices
BOOST_FOREACH(VertexIndex current_index, components) {
for (auto current_index : components) {
std::cout << "component " << current_index << " contains: ";

// Iterate through the child vertex indices for [current_index]
BOOST_FOREACH(VertexIndex child_index,
components[current_index]) {
for (auto child_index : make_range_pair(components[current_index])) {
std::cout << child_index << " ";
}

Expand Down

0 comments on commit 99b1a6e

Please sign in to comment.