From a3786d7f7e77af5301ac91abb39765334bf4487b Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Tue, 26 Oct 2010 18:24:01 +0000 Subject: [PATCH] Repaired copy_component() using suggestion from Christopher Alfeld; fixes #4793 [SVN r66203] --- include/boost/graph/copy.hpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/include/boost/graph/copy.hpp b/include/boost/graph/copy.hpp index 402e75f2..970166d5 100644 --- a/include/boost/graph/copy.hpp +++ b/include/boost/graph/copy.hpp @@ -350,15 +350,28 @@ namespace boost { : g_out(graph), orig2copy(c), copy_vertex(cv), copy_edge(ce) { } template - void examine_vertex(Vertex u, const Graph& g_in) const { + typename graph_traits::vertex_descriptor copy_one_vertex(Vertex u, const Graph& g_in) const { typename graph_traits::vertex_descriptor new_u = add_vertex(g_out); put(orig2copy, u, new_u); copy_vertex(u, new_u); + return new_u; } template - void examine_edge(Edge e, const Graph& g_in) const { + void tree_edge(Edge e, const Graph& g_in) const { + // For a tree edge, the target vertex has not been copied yet. + typename graph_traits::edge_descriptor new_e; + bool inserted; + boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(e, g_in)), + this->copy_one_vertex(target(e, g_in), g_in), + g_out); + copy_edge(e, new_e); + } + + template + void non_tree_edge(Edge e, const Graph& g_in) const { + // For a non-tree edge, the target vertex has already been copied. typename graph_traits::edge_descriptor new_e; bool inserted; boost::tie(new_e, inserted) = add_edge(get(orig2copy, source(e, g_in)), @@ -387,8 +400,10 @@ namespace boost { { graph_copy_visitor vis(g_out, orig2copy, copy_vertex, copy_edge); + typename graph_traits::vertex_descriptor src_copy + = vis.copy_one_vertex(src); breadth_first_search(g_in, src, params.visitor(vis)); - return get(orig2copy, src); + return src_copy; } } // namespace detail