diff --git a/include/boost/graph/directed_graph.hpp b/include/boost/graph/directed_graph.hpp index 585308d1..2c56a4e0 100644 --- a/include/boost/graph/directed_graph.hpp +++ b/include/boost/graph/directed_graph.hpp @@ -307,7 +307,7 @@ public: void swap(directed_graph& g) { - m_graph.swap(g); + m_graph.swap(g.m_graph); std::swap(m_num_vertices, g.m_num_vertices); std::swap(m_max_vertex_index, g.m_max_vertex_index); std::swap(m_num_edges, g.m_num_edges); diff --git a/include/boost/graph/undirected_graph.hpp b/include/boost/graph/undirected_graph.hpp index 5c000dc2..1db21a64 100644 --- a/include/boost/graph/undirected_graph.hpp +++ b/include/boost/graph/undirected_graph.hpp @@ -294,7 +294,7 @@ public: } void swap(undirected_graph& g) { - m_graph.swap(g); + m_graph.swap(g.m_graph); std::swap(m_num_vertices, g.m_num_vertices); std::swap(m_max_vertex_index, g.m_max_vertex_index); std::swap(m_num_edges, g.m_num_edges); diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 5487631f..0523f100 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -79,6 +79,7 @@ test-suite graph_test : [ run adjacency_matrix_test.cpp ] [ compile vector_graph_cc.cpp ] [ compile copy.cpp ] + [ compile swap.cpp ] [ compile property_iter.cpp ] [ run bundled_properties.cpp ] [ run floyd_warshall_test.cpp ] diff --git a/test/swap.cpp b/test/swap.cpp new file mode 100644 index 00000000..f47b234f --- /dev/null +++ b/test/swap.cpp @@ -0,0 +1,21 @@ +// Copyright (C) Ben Pope 2014. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include + +template +void test_member_swap() +{ + Graph lhs, rhs; + lhs.swap(rhs); +} + +int main() +{ + test_member_swap >(); + test_member_swap >(); + test_member_swap >(); +}