Skip to content

Commit 11225a9

Browse files
authored
Merge pull request #681 from Becheler/fix/strong-components-adl-get
bug: strong_components fails with pointer map after reverse_graph.hpp
2 parents 50d5ac7 + 061decd commit 11225a9

4 files changed

Lines changed: 20 additions & 16 deletions

File tree

‎doc/modules/ROOT/pages/adaptors/reverse_graph.adoc‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ underlying graph, and vice versa.
139139
Property maps from the underlying graph are accessible through the reversed
140140
view. Additionally, the `edge_underlying_t` property maps reversed edge
141141
descriptors back to the underlying edge descriptors.
142+
This map is read-only.
142143

143144
[source,cpp]
144145
----

‎include/boost/graph/detail/compressed_sparse_row_struct.hpp‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2005-2009 The Trustees of Indiana University.
2+
// Copyright (c) 2026 Arnaud Becheler
23

34
// Distributed under the Boost Software License, Version 1.0.
45
// (See accompanying file LICENSE_1_0.txt or copy at
@@ -54,20 +55,18 @@ namespace detail
5455
template < typename Vertex, typename EdgeIndex > class csr_edge_descriptor;
5556

5657
// Add edge_index property map
57-
template < typename Vertex, typename EdgeIndex > struct csr_edge_index_map
58+
// A get declared here would hide boost::get from code in boost::detail.
59+
template < typename Vertex, typename EdgeIndex >
60+
struct csr_edge_index_map
61+
: public ::boost::put_get_helper< EdgeIndex, csr_edge_index_map< Vertex, EdgeIndex > >
5862
{
5963
typedef EdgeIndex value_type;
6064
typedef EdgeIndex reference;
6165
typedef csr_edge_descriptor< Vertex, EdgeIndex > key_type;
6266
typedef readable_property_map_tag category;
63-
};
6467

65-
template < typename Vertex, typename EdgeIndex >
66-
inline EdgeIndex get(const csr_edge_index_map< Vertex, EdgeIndex >&,
67-
const csr_edge_descriptor< Vertex, EdgeIndex >& key)
68-
{
69-
return key.idx;
70-
}
68+
EdgeIndex operator[](const key_type& key) const { return key.idx; }
69+
};
7170

7271
/** Compressed sparse row graph internal structure.
7372
*

‎include/boost/graph/reverse_graph.hpp‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// (C) Copyright David Abrahams 2000.
2+
// Copyright (c) 2026 Arnaud Becheler
23
// Distributed under the Boost Software License, Version 1.0. (See
34
// accompanying file LICENSE_1_0.txt or copy at
45
// http://www.boost.org/LICENSE_1_0.txt)
@@ -549,20 +550,16 @@ void put(Property p, reverse_graph< BidirectionalGraph, GRef >& g, const Key& k,
549550

550551
namespace detail
551552
{
552-
template < class E > struct underlying_edge_desc_map_type
553+
// A get declared here would hide boost::get from code in boost::detail.
554+
template < class E >
555+
struct underlying_edge_desc_map_type
556+
: public ::boost::put_get_helper< E, underlying_edge_desc_map_type< E > >
553557
{
554558
E operator[](const reverse_graph_edge_descriptor< E >& k) const
555559
{
556560
return k.underlying_descx;
557561
}
558562
};
559-
560-
template < class E >
561-
E get(underlying_edge_desc_map_type< E > m,
562-
const reverse_graph_edge_descriptor< E >& k)
563-
{
564-
return m[k];
565-
}
566563
}
567564

568565
template < class E >

‎test/strong_components_test.cpp‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//=======================================================================
22
// Copyright 2014 Alexander Lauser.
3+
// Copyright (c) 2026 Arnaud Becheler
34
// Authors: Alexander Lauser
45
//
56
// Distributed under the Boost Software License, Version 1.0. (See
@@ -23,6 +24,8 @@ Vertex c is in component 0 and has root 0
2324
#include <boost/config.hpp>
2425
#include <iostream>
2526
#include <vector>
27+
// Must precede strong_components.hpp to reproduce issue #116.
28+
#include <boost/graph/reverse_graph.hpp>
2629
#include <boost/graph/strong_components.hpp>
2730
#include <boost/graph/adjacency_list.hpp>
2831
#include <boost/graph/graph_utility.hpp>
@@ -64,6 +67,10 @@ int main(int, char*[])
6467
.discover_time_map(make_iterator_property_map(
6568
discover_time.begin(), get(vertex_index, G))));
6669

70+
// A raw pointer component map must compile.
71+
std::vector< int > pointer_component(::boost::num_vertices(G));
72+
::boost::strong_components(G, &pointer_component[0]);
73+
6774
#if VERBOSE
6875
for (std::vector< int >::size_type i = 0; i != component.size(); ++i)
6976
std::cout << "Vertex " << name[i] << " is in component " << component[i]

0 commit comments

Comments
 (0)