Permalink
Browse files

C++17: Use structured bindings

This lets us replace lots of typedefs and declarations with auto.
  • Loading branch information...
murraycu committed May 15, 2017
1 parent a1fae0d commit 78254e31a5b04ebc9c2855615d8a3801750f8674
Showing with 339 additions and 642 deletions.
  1. +6 −13 include/boost/graph/adjacency_matrix.hpp
  2. +3 −7 include/boost/graph/astar_search.hpp
  3. +3 −6 include/boost/graph/bandwidth.hpp
  4. +3 −6 include/boost/graph/bellman_ford_shortest_paths.hpp
  5. +5 −12 include/boost/graph/betweenness_centrality.hpp
  6. +13 −21 include/boost/graph/boykov_kolmogorov_max_flow.hpp
  7. +2 −4 include/boost/graph/breadth_first_search.hpp
  8. +1 −3 include/boost/graph/bron_kerbosch_all_cliques.hpp
  9. +1 −2 include/boost/graph/closeness_centrality.hpp
  10. +5 −13 include/boost/graph/clustering_coefficient.hpp
  11. +13 −27 include/boost/graph/copy.hpp
  12. +3 −6 include/boost/graph/create_condensation_graph.hpp
  13. +1 −1 include/boost/graph/cuthill_mckee_ordering.hpp
  14. +3 −4 include/boost/graph/dag_shortest_paths.hpp
  15. +1 −3 include/boost/graph/degree_centrality.hpp
  16. +6 −8 include/boost/graph/depth_first_search.hpp
  17. +27 −59 include/boost/graph/detail/adjacency_list.hpp
  18. +1 −4 include/boost/graph/detail/compressed_sparse_row_struct.hpp
  19. +1 −3 include/boost/graph/detail/geodesic.hpp
  20. +1 −2 include/boost/graph/detail/sparse_ordering.hpp
  21. +1 −2 include/boost/graph/dijkstra_shortest_paths.hpp
  22. +3 −6 include/boost/graph/directed_graph.hpp
  23. +8 −11 include/boost/graph/dominator_tree.hpp
  24. +2 −7 include/boost/graph/eccentricity.hpp
  25. +13 −23 include/boost/graph/edge_connectivity.hpp
  26. +5 −7 include/boost/graph/edmonds_karp_max_flow.hpp
  27. +10 −20 include/boost/graph/filtered_graph.hpp
  28. +10 −19 include/boost/graph/floyd_warshall_shortest.hpp
  29. +4 −18 include/boost/graph/fruchterman_reingold.hpp
  30. +1 −3 include/boost/graph/geodesic_distance.hpp
  31. +19 −34 include/boost/graph/graph_utility.hpp
  32. +2 −6 include/boost/graph/graphml.hpp
  33. +3 −3 include/boost/graph/graphviz.hpp
  34. +2 −5 include/boost/graph/gursoy_atun_layout.hpp
  35. +1 −3 include/boost/graph/hawick_circuits.hpp
  36. +7 −12 include/boost/graph/howard_cycle_ratio.hpp
  37. +1 −3 include/boost/graph/incremental_components.hpp
  38. +3 −5 include/boost/graph/is_kuratowski_subgraph.hpp
  39. +1 −2 include/boost/graph/is_straight_line_drawing.hpp
  40. +12 −17 include/boost/graph/johnson_all_pairs_shortest.hpp
  41. +3 −4 include/boost/graph/king_ordering.hpp
  42. +2 −4 include/boost/graph/kruskal_min_spanning_tree.hpp
  43. +5 −9 include/boost/graph/max_cardinality_matching.hpp
  44. +3 −10 include/boost/graph/mcgregor_common_subgraphs.hpp
  45. +1 −3 include/boost/graph/metric_tsp_approx.hpp
  46. +6 −11 include/boost/graph/minimum_degree_ordering.hpp
  47. +3 −6 include/boost/graph/neighbor_bfs.hpp
  48. +1 −2 include/boost/graph/page_rank.hpp
  49. +10 −11 include/boost/graph/planar_detail/boyer_myrvold_impl.hpp
  50. +1 −2 include/boost/graph/profile.hpp
  51. +21 −27 include/boost/graph/push_relabel_max_flow.hpp
  52. +4 −10 include/boost/graph/random.hpp
  53. +2 −5 include/boost/graph/read_dimacs.hpp
  54. +1 −2 include/boost/graph/reverse_graph.hpp
  55. +5 −12 include/boost/graph/rmat_graph_generator.hpp
  56. +1 −2 include/boost/graph/sequential_vertex_coloring.hpp
  57. +6 −8 include/boost/graph/sloan_ordering.hpp
  58. +2 −3 include/boost/graph/smallest_last_ordering.hpp
  59. +1 −2 include/boost/graph/stanford_graph.hpp
  60. +1 −1 include/boost/graph/stoer_wagner_min_cut.hpp
  61. +5 −9 include/boost/graph/strong_components.hpp
  62. +11 −24 include/boost/graph/subgraph.hpp
  63. +3 −9 include/boost/graph/tiernan_all_cycles.hpp
  64. +14 −22 include/boost/graph/transitive_closure.hpp
  65. +1 −2 include/boost/graph/transitive_reduction.hpp
  66. +1 −2 include/boost/graph/tree_traits.hpp
  67. +4 −7 include/boost/graph/two_graphs_common_spanning_trees.hpp
  68. +5 −7 include/boost/graph/undirected_dfs.hpp
  69. +3 −6 include/boost/graph/undirected_graph.hpp
  70. +6 −10 include/boost/graph/wavefront.hpp
@@ -749,8 +749,7 @@ namespace boost {
const adjacency_matrix<D,VP,EP,GP,A>& g)
{
typename adjacency_matrix<D,VP,EP,GP,A>::degree_size_type n = 0;
typename adjacency_matrix<D,VP,EP,GP,A>::out_edge_iterator f, l;
for (std::tie(f, l) = out_edges(u, g); f != l; ++f)
for (auto [f, l] = out_edges(u, g); f != l; ++f)
++n;
return n;
}
@@ -831,8 +830,7 @@ namespace boost {
const adjacency_matrix<D,VP,EP,GP,A>& g)
{
typename adjacency_matrix<D,VP,EP,GP,A>::degree_size_type n = 0;
typename adjacency_matrix<D,VP,EP,GP,A>::in_edge_iterator f, l;
for (std::tie(f, l) = in_edges(u, g); f != l; ++f)
for (auto [f, l] = in_edges(u, g); f != l; ++f)
++n;
return n;
}
@@ -851,8 +849,7 @@ namespace boost {
const auto& cg = static_cast<const Graph&>(g_);
auto& g = const_cast<Graph&>(cg);
typedef typename Graph::adjacency_iterator adjacency_iterator;
typename Graph::out_edge_iterator first, last;
std::tie(first, last) = out_edges(u, g);
auto [first, last] = out_edges(u, g);
return std::make_pair(adjacency_iterator(first, &g),
adjacency_iterator(last, &g));
}
@@ -999,11 +996,9 @@ namespace boost {
(typename adjacency_matrix<directedS,VP,EP,GP,A>::vertex_descriptor u,
adjacency_matrix<directedS,VP,EP,GP,A>& g)
{
typename adjacency_matrix<directedS,VP,EP,GP,A>::vertex_iterator
vi, vi_end;
for (std::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
for (auto [vi, vi_end] = vertices(g); vi != vi_end; ++vi)
remove_edge(u, *vi, g);
for (std::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
for (auto [vi, vi_end] = vertices(g); vi != vi_end; ++vi)
remove_edge(*vi, u, g);
}
@@ -1014,9 +1009,7 @@ namespace boost {
(typename adjacency_matrix<undirectedS,VP,EP,GP,A>::vertex_descriptor u,
adjacency_matrix<undirectedS,VP,EP,GP,A>& g)
{
typename adjacency_matrix<undirectedS,VP,EP,GP,A>::vertex_iterator
vi, vi_end;
for (std::tie(vi, vi_end) = vertices(g); vi != vi_end; ++vi)
for (auto [vi, vi_end] = vertices(g); vi != vi_end; ++vi)
remove_edge(u, *vi, g);
}
@@ -311,9 +311,7 @@ namespace boost {
vis.discover_vertex(s, g);
Q.push(std::make_pair(get(cost, s), s));
while (!Q.empty()) {
Vertex v;
Distance v_rank;
std::tie(v_rank, v) = Q.top();
auto [v_rank, v] = Q.top();
Q.pop();
vis.examine_vertex(v, g);
BGL_FORALL_OUTEDGES_T(v, e, g, VertexListGraph) {
@@ -362,8 +360,7 @@ namespace boost {
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end;
for (std::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
for (auto [ui, ui_end] = vertices(g); ui != ui_end; ++ui) {
put(color, *ui, Color::white());
put(distance, *ui, inf);
put(cost, *ui, inf);
@@ -397,8 +394,7 @@ namespace boost {
CostInf inf, CostZero zero)
{
typename graph_traits<VertexListGraph>::vertex_iterator ui, ui_end;
for (std::tie(ui, ui_end) = vertices(g); ui != ui_end; ++ui) {
for (auto [ui, ui_end] = vertices(g); ui != ui_end; ++ui) {
put(distance, *ui, inf);
put(cost, *ui, inf);
put(predecessor, *ui, *ui);
@@ -24,8 +24,7 @@ namespace boost {
using std::abs;
typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
vertices_size_type b = 0;
typename graph_traits<Graph>::out_edge_iterator e, end;
for (std::tie(e, end) = out_edges(i, g); e != end; ++e) {
for (auto [e, end] = out_edges(i, g); e != end; ++e) {
int f_i = get(index, i);
int f_j = get(index, target(*e, g));
b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, vertices_size_type(abs(f_i - f_j)));
@@ -49,8 +48,7 @@ namespace boost {
using std::abs;
typedef typename graph_traits<Graph>::vertices_size_type vertices_size_type;
vertices_size_type b = 0;
typename graph_traits<Graph>::edge_iterator i, end;
for (std::tie(i, end) = edges(g); i != end; ++i) {
for (auto [i, end] = edges(g); i != end; ++i) {
int f_i = get(index, source(*i, g));
int f_j = get(index, target(*i, g));
b = max BOOST_PREVENT_MACRO_SUBSTITUTION (b, vertices_size_type(abs(f_i - f_j)));
@@ -71,8 +69,7 @@ namespace boost {
{
typedef typename graph_traits<Graph>::vertices_size_type size_type;
size_type sum = 0;
typename graph_traits<Graph>::edge_iterator i, end;
for (std::tie(i, end) = edges(g); i != end; ++i) {
for (auto [i, end] = edges(g); i != end; ++i) {
auto f_u = get(index_map, source(*i, g));
auto f_v = get(index_map, target(*i, g));
using namespace std; // to call abs() unqualified
@@ -103,11 +103,9 @@ namespace boost {
BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<DistanceMap, Vertex> ));
BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<WeightMap, Edge> ));
typename GTraits::edge_iterator i, end;
for (Size k = 0; k < N; ++k) {
bool at_least_one_edge_relaxed = false;
for (std::tie(i, end) = edges(g); i != end; ++i) {
for (auto [i, end] = edges(g); i != end; ++i) {
v.examine_edge(*i, g);
if (relax(*i, g, weight, pred, distance, combine, compare)) {
at_least_one_edge_relaxed = true;
@@ -119,7 +117,7 @@ namespace boost {
break;
}
for (std::tie(i, end) = edges(g); i != end; ++i)
for (auto [i, end] = edges(g); i != end; ++i)
if (compare(combine(get(distance, source(*i, g)), get(weight, *i)),
get(distance, target(*i,g))))
{
@@ -146,8 +144,7 @@ namespace boost {
typedef typename property_traits<DistanceMap>::value_type D;
bellman_visitor<> null_vis;
typedef typename property_traits<WeightMap>::value_type weight_type;
typename graph_traits<VertexAndEdgeListGraph>::vertex_iterator v, v_end;
for (std::tie(v, v_end) = vertices(g); v != v_end; ++v) {
for (auto [v, v_end] = vertices(g); v != v_end; ++v) {
put(distance, *v, (std::numeric_limits<weight_type>::max)());
put(pred, *v, *v);
}
@@ -294,19 +294,16 @@ namespace detail { namespace graph {
VertexIndexMap vertex_index,
ShortestPaths shortest_paths)
{
typedef typename graph_traits<Graph>::vertex_iterator vertex_iterator;
typedef typename graph_traits<Graph>::vertex_descriptor vertex_descriptor;
// Initialize centrality
init_centrality_map(vertices(g), centrality);
init_centrality_map(edges(g), edge_centrality_map);
std::stack<vertex_descriptor> ordered_vertices;
vertex_iterator s, s_end;
for (std::tie(s, s_end) = vertices(g); s != s_end; ++s) {
for (auto [s, s_end] = vertices(g); s != s_end; ++s) {
// Initialize for this iteration
vertex_iterator w, w_end;
for (std::tie(w, w_end) = vertices(g); w != w_end; ++w) {
for (auto [w, w_end] = vertices(g); w != w_end; ++w) {
incoming[*w].clear();
put(path_count, *w, 0);
put(dependency, *w, 0);
@@ -568,13 +565,11 @@ template<typename Graph, typename CentralityMap>
void
relative_betweenness_centrality(const Graph& g, CentralityMap centrality)
{
typedef typename graph_traits<Graph>::vertex_iterator vertex_iterator;
typedef typename property_traits<CentralityMap>::value_type centrality_type;
auto n = num_vertices(g);
auto factor = centrality_type(2)/centrality_type(n*n - 3*n + 2);
vertex_iterator v, v_end;
for (std::tie(v, v_end) = vertices(g); v != v_end; ++v) {
for (auto [v, v_end] = vertices(g); v != v_end; ++v) {
put(centrality, *v, factor * get(centrality, *v));
}
}
@@ -587,21 +582,19 @@ central_point_dominance(const Graph& g, CentralityMap centrality
{
using std::max;
typedef typename graph_traits<Graph>::vertex_iterator vertex_iterator;
typedef typename property_traits<CentralityMap>::value_type centrality_type;
auto n = num_vertices(g);
// Find max centrality
centrality_type max_centrality(0);
vertex_iterator v, v_end;
for (std::tie(v, v_end) = vertices(g); v != v_end; ++v) {
for (auto [v, v_end] = vertices(g); v != v_end; ++v) {
max_centrality = (max)(max_centrality, get(centrality, *v));
}
// Compute central point dominance
centrality_type sum(0);
for (std::tie(v, v_end) = vertices(g); v != v_end; ++v) {
for (auto [v, v_end] = vertices(g); v != v_end; ++v) {
sum += (max_centrality - get(centrality, *v));
}
return sum/(n-1);
@@ -118,14 +118,12 @@ class bk_max_flow {
m_time(1),
m_last_grow_vertex(graph_traits<Graph>::null_vertex()){
// initialize the color-map with gray-values
vertex_iterator vi, v_end;
for(std::tie(vi, v_end) = vertices(m_g); vi != v_end; ++vi){
for(auto [vi, v_end] = vertices(m_g); vi != v_end; ++vi){
set_tree(*vi, tColorTraits::gray());
}
// Initialize flow to zero which means initializing
// the residual capacity equal to the capacity
edge_iterator ei, e_end;
for(std::tie(ei, e_end) = edges(m_g); ei != e_end; ++ei) {
for(auto [ei, e_end] = edges(m_g); ei != e_end; ++ei) {
put(m_res_cap_map, *ei, get(m_cap_map, *ei));
BOOST_ASSERT(get(m_rev_edge_map, get(m_rev_edge_map, *ei)) == *ei); //check if the reverse edge map is build up properly
}
@@ -141,9 +139,7 @@ class bk_max_flow {
augment_direct_paths();
//start the main-loop
while(true){
bool path_found;
edge_descriptor connecting_edge;
std::tie(connecting_edge, path_found) = grow(); //find a path from source to sink
auto [connecting_edge, path_found] = grow(); //find a path from source to sink
if(!path_found){
//we're finished, no more paths were found
break;
@@ -164,8 +160,7 @@ class bk_max_flow {
// graphcuts for segmentation, as most of the nodes have source/sink
// connects but shouldn't have an impact on other maxflow problems
// (this is done in grow() anyway)
out_edge_iterator ei, e_end;
for(std::tie(ei, e_end) = out_edges(m_source, m_g); ei != e_end; ++ei){
for(auto [ei, e_end] = out_edges(m_source, m_g); ei != e_end; ++ei){
auto from_source = *ei;
auto current_node = target(from_source, m_g);
if(current_node == m_sink){
@@ -174,9 +169,8 @@ class bk_max_flow {
m_flow += cap;
continue;
}
edge_descriptor to_sink;
bool is_there;
std::tie(to_sink, is_there) = lookup_edge(current_node, m_sink, m_g);
auto [to_sink, is_there] = lookup_edge(current_node, m_sink, m_g);
if(is_there){
auto cap_from_source = get(m_res_cap_map, from_source);
auto cap_to_sink = get(m_res_cap_map, to_sink);
@@ -216,7 +210,7 @@ class bk_max_flow {
add_active_node(current_node);
}
}
for(std::tie(ei, e_end) = out_edges(m_sink, m_g); ei != e_end; ++ei){
for(auto [ei, e_end] = out_edges(m_sink, m_g); ei != e_end; ++ei){
auto to_sink = get(m_rev_edge_map, *ei);
auto current_node = source(to_sink, m_g);
if(get(m_res_cap_map, to_sink)){
@@ -249,7 +243,7 @@ class bk_max_flow {
out_edge_iterator ei, e_end;
if(current_node != m_last_grow_vertex){
m_last_grow_vertex = current_node;
std::tie(m_last_grow_edge_it, m_last_grow_edge_end) = out_edges(current_node, m_g);
auto [m_last_grow_edge_it, m_last_grow_edge_end] = out_edges(current_node, m_g);
}
for(; m_last_grow_edge_it != m_last_grow_edge_end; ++m_last_grow_edge_it) {
auto out_edge = *m_last_grow_edge_it;
@@ -283,7 +277,7 @@ class bk_max_flow {
out_edge_iterator ei, e_end;
if(current_node != m_last_grow_vertex){
m_last_grow_vertex = current_node;
std::tie(m_last_grow_edge_it, m_last_grow_edge_end) = out_edges(current_node, m_g);
auto [m_last_grow_edge_it, m_last_grow_edge_end] = out_edges(current_node, m_g);
}
for(; m_last_grow_edge_it != m_last_grow_edge_end; ++m_last_grow_edge_it){
auto in_edge = get(m_rev_edge_map, *m_last_grow_edge_it);
@@ -419,8 +413,7 @@ class bk_max_flow {
//we're in the source-tree
auto min_distance = (std::numeric_limits<tDistanceVal>::max)();
edge_descriptor new_parent_edge;
out_edge_iterator ei, e_end;
for(std::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){
for(auto [ei, e_end] = out_edges(current_node, m_g); ei != e_end; ++ei){
const auto in_edge = get(m_rev_edge_map, *ei);
BOOST_ASSERT(target(in_edge, m_g) == current_node); //we should be the target of this edge
if(get(m_res_cap_map, in_edge) > 0){
@@ -439,7 +432,7 @@ class bk_max_flow {
put(m_time_map, current_node, m_time);
} else{
put(m_time_map, current_node, 0);
for(std::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){
for(auto [ei, e_end] = out_edges(current_node, m_g); ei != e_end; ++ei){
auto in_edge = get(m_rev_edge_map, *ei);
auto other_node = source(in_edge, m_g);
if(get_tree(other_node) == tColorTraits::black() && other_node != m_source){
@@ -460,10 +453,9 @@ class bk_max_flow {
else{
//now we should be in the sink-tree, check that...
BOOST_ASSERT(get_tree(current_node) == tColorTraits::white());
out_edge_iterator ei, e_end;
edge_descriptor new_parent_edge;
auto min_distance = (std::numeric_limits<tDistanceVal>::max)();
for(std::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){
for(auto [ei, e_end] = out_edges(current_node, m_g); ei != e_end; ++ei){
const auto out_edge = *ei;
if(get(m_res_cap_map, out_edge) > 0){
const auto other_node = target(out_edge, m_g);
@@ -480,7 +472,7 @@ class bk_max_flow {
put(m_time_map, current_node, m_time);
} else{
put(m_time_map, current_node, 0);
for(std::tie(ei, e_end) = out_edges(current_node, m_g); ei != e_end; ++ei){
for(auto [ei, e_end] = out_edges(current_node, m_g); ei != e_end; ++ei){
const auto out_edge = *ei;
const auto other_node = target(out_edge, m_g);
if(get_tree(other_node) == tColorTraits::white() && other_node != m_sink){
@@ -68,7 +68,6 @@ namespace boost {
BOOST_CONCEPT_ASSERT(( ReadWritePropertyMapConcept<ColorMap, Vertex> ));
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
typename GTraits::out_edge_iterator ei, ei_end;
for (; sources_begin != sources_end; ++sources_begin) {
auto s = *sources_begin;
@@ -77,7 +76,7 @@ namespace boost {
}
while (! Q.empty()) {
auto u = Q.top(); Q.pop(); vis.examine_vertex(u, g);
for (std::tie(ei, ei_end) = out_edges(u, g); ei != ei_end; ++ei) {
for (auto [ei, ei_end] = out_edges(u, g); ei != ei_end; ++ei) {
auto v = target(*ei, g); vis.examine_edge(*ei, g);
ColorValue v_color = get(color, v);
if (v_color == Color::white()) { vis.tree_edge(*ei, g);
@@ -116,8 +115,7 @@ namespace boost {
// Initialization
typedef typename property_traits<ColorMap>::value_type ColorValue;
typedef color_traits<ColorValue> Color;
typename boost::graph_traits<VertexListGraph>::vertex_iterator i, i_end;
for (std::tie(i, i_end) = vertices(g); i != i_end; ++i) {
for (auto [i, i_end] = vertices(g); i != i_end; ++i) {
vis.initialize_vertex(*i, g);
put(color, *i, Color::white());
}
@@ -273,16 +273,14 @@ bron_kerbosch_all_cliques(const Graph& g, Visitor vis, std::size_t min)
BOOST_CONCEPT_ASSERT(( VertexListGraphConcept<Graph> ));
BOOST_CONCEPT_ASSERT(( AdjacencyMatrixConcept<Graph> )); // Structural requirement only
typedef typename graph_traits<Graph>::vertex_descriptor Vertex;
typedef typename graph_traits<Graph>::vertex_iterator VertexIterator;
typedef std::vector<Vertex> VertexSet;
typedef std::deque<Vertex> Clique;
BOOST_CONCEPT_ASSERT(( CliqueVisitorConcept<Visitor,Clique,Graph> ));
// NOTE: We're using a deque to implement the clique, because it provides
// constant inserts and removals at the end and also a constant size.
VertexIterator i, end;
std::tie(i, end) = vertices(g);
auto [i, end] = vertices(g);
VertexSet cands(i, end); // start with all vertices as candidates
VertexSet nots; // start with no vertices visited
@@ -124,8 +124,7 @@ all_closeness_centralities(const Graph& g,
BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<DistanceMap,Vertex> ));
BOOST_CONCEPT_ASSERT(( WritablePropertyMapConcept<CentralityMap,Vertex> ));
typename graph_traits<Graph>::vertex_iterator i, end;
for(std::tie(i, end) = vertices(g); i != end; ++i) {
for(auto [i, end] = vertices(g); i != end; ++i) {
auto dm = get(dist, *i);
auto c = closeness_centrality(g, dm, measure);
put(cent, *i, c);
Oops, something went wrong.

0 comments on commit 78254e3

Please sign in to comment.