From ff7cb91d9cd3d00107765a3f4f441f9debe552d5 Mon Sep 17 00:00:00 2001 From: Patrick Niklaus Date: Wed, 16 Dec 2015 18:12:18 +0100 Subject: [PATCH] Use the Koenig swap and add free swap function for DeallocationVector --- data_structures/deallocating_vector.hpp | 14 ++++++++++++++ extractor/edge_based_graph_factory.cpp | 9 ++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/data_structures/deallocating_vector.hpp b/data_structures/deallocating_vector.hpp index 51bebb957..72cb0816c 100644 --- a/data_structures/deallocating_vector.hpp +++ b/data_structures/deallocating_vector.hpp @@ -237,6 +237,12 @@ class DeallocatingVectorRemoveIterator } }; +template +class DeallocatingVector; + +template +void swap(DeallocatingVector& lhs, DeallocatingVector& rhs); + template class DeallocatingVector { @@ -257,6 +263,8 @@ class DeallocatingVector ~DeallocatingVector() { clear(); } + friend void swap<>(DeallocatingVector& lhs, DeallocatingVector& rhs); + void swap(DeallocatingVector &other) { std::swap(current_size, other.current_size); @@ -386,4 +394,10 @@ class DeallocatingVector } }; +template +void swap(DeallocatingVector& lhs, DeallocatingVector& rhs) +{ + lhs.swap(rhs); +} + #endif /* DEALLOCATING_VECTOR_HPP */ diff --git a/extractor/edge_based_graph_factory.cpp b/extractor/edge_based_graph_factory.cpp index 03f801d62..f0c083d2d 100644 --- a/extractor/edge_based_graph_factory.cpp +++ b/extractor/edge_based_graph_factory.cpp @@ -61,7 +61,8 @@ EdgeBasedGraphFactory::EdgeBasedGraphFactory( void EdgeBasedGraphFactory::GetEdgeBasedEdges(DeallocatingVector &output_edge_list) { BOOST_ASSERT_MSG(0 == output_edge_list.size(), "Vector is not empty"); - std::swap(m_edge_based_edge_list, output_edge_list); + using std::swap; // Koenig swap + swap(m_edge_based_edge_list, output_edge_list); } void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector &nodes) @@ -75,12 +76,14 @@ void EdgeBasedGraphFactory::GetEdgeBasedNodes(std::vector &nodes) BOOST_ASSERT(m_node_info_list.at(node.v).lat != INT_MAX); } #endif - std::swap(nodes, m_edge_based_node_list); + using std::swap; // Koenig swap + swap(nodes, m_edge_based_node_list); } void EdgeBasedGraphFactory::GetStartPointMarkers(std::vector &node_is_startpoint) { - std::swap(m_edge_based_node_is_startpoint, node_is_startpoint); + using std::swap; // Koenig swap + swap(m_edge_based_node_is_startpoint, node_is_startpoint); } unsigned EdgeBasedGraphFactory::GetHighestEdgeID()