From d4e89e66391b36b57b3ef1913325efbb8bb8b327 Mon Sep 17 00:00:00 2001
From: Dmitrij Naumov <dmitrij@naumov.de>
Date: Fri, 2 Nov 2012 19:08:33 +0100
Subject: [PATCH] Replace BaseLib::swap with std::swap.

---
 BaseLib/quicksort.h                           | 37 +++++++++----------
 BaseLib/swap.h                                | 29 ---------------
 FileIO/MeshIO/GMSHInterface.cpp               |  1 -
 GeoLib/Polygon.cpp                            |  7 ++--
 GeoLib/Polyline.cpp                           |  5 +--
 MathLib/AnalyticalGeometry.cpp                |  1 -
 MathLib/EarClippingTriangulation.cpp          |  3 +-
 .../PiecewiseLinearInterpolation.cpp          |  1 -
 MathLib/LinAlg/Solvers/GaussAlgorithm.cpp     |  5 +--
 MathLib/LinAlg/Sparse/CRSMatrix.h             | 15 ++++----
 .../NestedDissectionPermutation/AdjMat.cpp    |  9 ++---
 .../CRSMatrixReordered.cpp                    |  6 +--
 .../NestedDissectionPermutation/Cluster.cpp   | 13 +++----
 .../NestedDissectionPermutation/Separator.cpp |  5 +--
 Tests/BaseLib/TestSwap.cpp                    |  8 ++--
 15 files changed, 51 insertions(+), 94 deletions(-)
 delete mode 100644 BaseLib/swap.h

diff --git a/BaseLib/quicksort.h b/BaseLib/quicksort.h
index aed83fd6624..d7c74a16537 100644
--- a/BaseLib/quicksort.h
+++ b/BaseLib/quicksort.h
@@ -17,7 +17,6 @@
 #include <cstddef>
 
 // Base
-#include "swap.h"
 
 namespace BaseLib {
 
@@ -33,10 +32,10 @@ unsigned partition_(T* array, unsigned beg, unsigned end)
     while ((j>beg) && !(array[j] < m)) j--;
 
     if (i >= j) break;
-    BaseLib::swap(array[i], array[j]);
+    std::swap(array[i], array[j]);
   }
 
-  BaseLib::swap(array[beg], array[j]);
+  std::swap(array[beg], array[j]);
   return j;
 }
 
@@ -76,12 +75,12 @@ std::size_t partition_(T1* array, std::size_t beg, std::size_t end, T2 *second_a
 
 		if (i >= j) break;
 
-		BaseLib::swap(array[i], array[j]);
-		BaseLib::swap(second_array[i], second_array[j]);
+		std::swap(array[i], array[j]);
+		std::swap(second_array[i], second_array[j]);
 	}
 
-	BaseLib::swap(array[beg], array[j]);
-	BaseLib::swap(second_array[beg], second_array[j]);
+	std::swap(array[beg], array[j]);
+	std::swap(second_array[beg], second_array[j]);
 
 	return j;
 }
@@ -133,12 +132,12 @@ private:
 
 			if (i >= j)
 				break;
-			BaseLib::swap(array[i], array[j]);
-			BaseLib::swap(perm[i], perm[j]);
+			std::swap(array[i], array[j]);
+			std::swap(perm[i], perm[j]);
 		}
 
-		BaseLib::swap(array[beg], array[j]);
-		BaseLib::swap(perm[beg], perm[j]);
+		std::swap(array[beg], array[j]);
+		std::swap(perm[beg], perm[j]);
 		return j;
 	}
 
@@ -181,12 +180,12 @@ private:
 
 			if (i >= j)
 				break;
-			BaseLib::swap(array[i], array[j]);
-			BaseLib::swap(perm[i], perm[j]);
+			std::swap(array[i], array[j]);
+			std::swap(perm[i], perm[j]);
 		}
 
-		BaseLib::swap(array[beg], array[j]);
-		BaseLib::swap(perm[beg], perm[j]);
+		std::swap(array[beg], array[j]);
+		std::swap(perm[beg], perm[j]);
 		return j;
 	}
 
@@ -213,12 +212,12 @@ private:
 
 			if (i >= j)
 				break;
-			BaseLib::swap(perm[i], perm[j]);
-			BaseLib::swap(array[i], array[j]);
+			std::swap(perm[i], perm[j]);
+			std::swap(array[i], array[j]);
 		}
 
-		BaseLib::swap(perm[beg], perm[j]);
-		BaseLib::swap(array[beg], array[j]);
+		std::swap(perm[beg], perm[j]);
+		std::swap(array[beg], array[j]);
 		return j;
 	}
 
diff --git a/BaseLib/swap.h b/BaseLib/swap.h
deleted file mode 100644
index 0dc1bbd27df..00000000000
--- a/BaseLib/swap.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/**
- * Copyright (c) 2012, OpenGeoSys Community (http://www.opengeosys.org)
- *            Distributed under a Modified BSD License.
- *              See accompanying file LICENSE.txt or
- *              http://www.opengeosys.org/project/license
- *
- *
- * \file swap.h
- *
- * Created on xxxx-xx-xx by xx
- */
-#ifndef SWAP_H_
-#define SWAP_H_
-
-namespace BaseLib {
-
-/**
- * swap the content of arg0 and arg1
- */
-template<class T> void swap(T& arg0, T& arg1)
-{
-  T temp(arg0);
-  arg0 = arg1;
-  arg1 = temp;
-}
-
-} // end namespace BaseLib
-
-#endif //SWAP_H_
diff --git a/FileIO/MeshIO/GMSHInterface.cpp b/FileIO/MeshIO/GMSHInterface.cpp
index 9ab147541f9..f0788fac1ab 100644
--- a/FileIO/MeshIO/GMSHInterface.cpp
+++ b/FileIO/MeshIO/GMSHInterface.cpp
@@ -13,7 +13,6 @@
 #include <vector>
 
 // BaseLib
-#include "swap.h"
 #include "StringTools.h"
 #include "Configure.h"
 #include "BuildInfo.h"
diff --git a/GeoLib/Polygon.cpp b/GeoLib/Polygon.cpp
index fad8c185511..cbbda7a96bb 100644
--- a/GeoLib/Polygon.cpp
+++ b/GeoLib/Polygon.cpp
@@ -25,7 +25,6 @@
 
 // Base
 #include "quicksort.h"
-#include "swap.h"
 
 namespace GeoLib
 {
@@ -304,7 +303,7 @@ void Polygon::ensureCWOrientation ()
 		size_t tmp_n_pnts (n_pnts);
 		tmp_n_pnts++; // include last point of polygon (which is identical to the first)
 		for (size_t k(0); k < tmp_n_pnts / 2; k++)
-			BaseLib::swap (_ply_pnt_ids[k], _ply_pnt_ids[tmp_n_pnts - 1 - k]);
+			std::swap (_ply_pnt_ids[k], _ply_pnt_ids[tmp_n_pnts - 1 - k]);
 	}
 
 	for (size_t k(0); k < n_pnts; k++)
@@ -329,7 +328,7 @@ void Polygon::splitPolygonAtIntersection (std::list<Polygon*>::iterator polygon_
 
 			// split Polygon
 			if (idx0 > idx1)
-				BaseLib::swap (idx0, idx1);
+				std::swap (idx0, idx1);
 
 			GeoLib::Polygon* polygon0 (new GeoLib::Polygon(
 			                                   (*polygon_it)->getPointsVec(), false));
@@ -396,7 +395,7 @@ void Polygon::splitPolygonAtPoint (std::list<GeoLib::Polygon*>::iterator polygon
 			delete [] id_vec;
 
 			if (idx0 > idx1)
-				BaseLib::swap (idx0, idx1);
+				std::swap (idx0, idx1);
 
 			// create two closed polylines
 			GeoLib::Polygon* polygon0 (new GeoLib::Polygon((*polygon_it)->getPointsVec()));
diff --git a/GeoLib/Polyline.cpp b/GeoLib/Polyline.cpp
index 188710edf49..9f7e0e7b567 100644
--- a/GeoLib/Polyline.cpp
+++ b/GeoLib/Polyline.cpp
@@ -10,7 +10,6 @@
  */
 
 // Base
-#include "swap.h"
 
 // GeoLib
 #include "Polyline.h"
@@ -368,14 +367,14 @@ bool containsEdge (const Polyline& ply, size_t id0, size_t id1)
 		return false;
 	}
 	if (id0 > id1)
-		BaseLib::swap (id0,id1);
+		std::swap (id0,id1);
 	const size_t n (ply.getNumberOfPoints() - 1);
 	for (size_t k(0); k < n; k++)
 	{
 		size_t ply_pnt0 (ply.getPointID (k));
 		size_t ply_pnt1 (ply.getPointID (k + 1));
 		if (ply_pnt0 > ply_pnt1)
-			BaseLib::swap (ply_pnt0, ply_pnt1);
+			std::swap (ply_pnt0, ply_pnt1);
 		if (ply_pnt0 == id0 && ply_pnt1 == id1)
 			return true;
 	}
diff --git a/MathLib/AnalyticalGeometry.cpp b/MathLib/AnalyticalGeometry.cpp
index 150103fa5ed..2a9e83c3876 100644
--- a/MathLib/AnalyticalGeometry.cpp
+++ b/MathLib/AnalyticalGeometry.cpp
@@ -17,7 +17,6 @@
 #include <fstream>
 
 // Base
-#include "swap.h"
 #include "quicksort.h"
 
 // GEO
diff --git a/MathLib/EarClippingTriangulation.cpp b/MathLib/EarClippingTriangulation.cpp
index 4d0369a26c2..27482f4fea6 100644
--- a/MathLib/EarClippingTriangulation.cpp
+++ b/MathLib/EarClippingTriangulation.cpp
@@ -14,7 +14,6 @@
 #include <vector>
 
 // BaseLib
-#include "swap.h"
 #include "printList.h"
 #include "uniqueInsert.h"
 
@@ -124,7 +123,7 @@ void EarClippingTriangulation::ensureCWOrientation ()
 	if (_original_orient == MathLib::CCW) {
 		// switch orientation
 		for (std::size_t k(0); k<n_pnts/2; k++) {
-			BaseLib::swap (_pnts[k], _pnts[n_pnts-1-k]);
+			std::swap (_pnts[k], _pnts[n_pnts-1-k]);
 		}
 	}
 }
diff --git a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp
index 4374c0f4b92..7b76b21cf34 100644
--- a/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp
+++ b/MathLib/InterpolationAlgorithms/PiecewiseLinearInterpolation.cpp
@@ -12,7 +12,6 @@
 
 #include "PiecewiseLinearInterpolation.h"
 #include "binarySearch.h"
-#include "swap.h"
 
 #include <iostream>
 
diff --git a/MathLib/LinAlg/Solvers/GaussAlgorithm.cpp b/MathLib/LinAlg/Solvers/GaussAlgorithm.cpp
index 461ca920c61..eb3ea309c62 100644
--- a/MathLib/LinAlg/Solvers/GaussAlgorithm.cpp
+++ b/MathLib/LinAlg/Solvers/GaussAlgorithm.cpp
@@ -12,7 +12,6 @@
 
 #include <cmath>
 #include "GaussAlgorithm.h"
-#include "swap.h"
 
 namespace MathLib {
 
@@ -35,7 +34,7 @@ GaussAlgorithm::GaussAlgorithm (Matrix <double> &A) :
 
 		// exchange rows
 		if (_perm[k] != k) {
-			for (j=0; j<nc; j++) BaseLib::swap (_mat(_perm[k],j), _mat(k,j));
+			for (j=0; j<nc; j++) std::swap (_mat(_perm[k],j), _mat(k,j));
 		}
 
 		// eliminate
@@ -64,7 +63,7 @@ void GaussAlgorithm::execute (double *b) const
 void GaussAlgorithm::permuteRHS (double* b) const
 {
 	for (size_t i=0; i<_n; i++) {
-		if (_perm[i] != i) BaseLib::swap(b[i], b[_perm[i]]);
+		if (_perm[i] != i) std::swap(b[i], b[_perm[i]]);
 	}
 }
 
diff --git a/MathLib/LinAlg/Sparse/CRSMatrix.h b/MathLib/LinAlg/Sparse/CRSMatrix.h
index e40b46d6f35..872adaea451 100644
--- a/MathLib/LinAlg/Sparse/CRSMatrix.h
+++ b/MathLib/LinAlg/Sparse/CRSMatrix.h
@@ -19,7 +19,6 @@
 #include <cassert>
 
 // Base
-#include "swap.h"
 
 // MathLib
 #include "SparseMatrixBase.h"
@@ -333,9 +332,9 @@ protected:
 		}
 
 		MatrixBase::_n_rows -= n_rows_cols;
-		BaseLib::swap (row_ptr_new, _row_ptr);
-		BaseLib::swap (col_idx_new, _col_idx);
-		BaseLib::swap (data_new, _data);
+		std::swap (row_ptr_new, _row_ptr);
+		std::swap (col_idx_new, _col_idx);
+		std::swap (data_new, _data);
 
 		delete [] row_ptr_new_tmp;
 		delete [] row_ptr_new;
@@ -385,10 +384,10 @@ protected:
 			}
 		}
 
-		BaseLib::swap(MatrixBase::_n_rows, MatrixBase::_n_cols);
-		BaseLib::swap(row_ptr_trans, _row_ptr);
-		BaseLib::swap(col_idx_trans, _col_idx);
-		BaseLib::swap(data_trans, _data);
+		std::swap(MatrixBase::_n_rows, MatrixBase::_n_cols);
+		std::swap(row_ptr_trans, _row_ptr);
+		std::swap(col_idx_trans, _col_idx);
+		std::swap(data_trans, _data);
 
 		delete[] row_ptr_nnz;
 		delete[] row_ptr_trans;
diff --git a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/AdjMat.cpp b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/AdjMat.cpp
index 849ea3384c7..87ae7e5c325 100644
--- a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/AdjMat.cpp
+++ b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/AdjMat.cpp
@@ -11,7 +11,6 @@
  */
 
 // Base
-#include "swap.h"
 #include "quicksort.h"
 
 #include "LinAlg/Sparse/NestedDissectionPermutation/AdjMat.h"
@@ -142,8 +141,8 @@ void genAdjMat(unsigned n, unsigned* &iA, unsigned* &jA)
 			if (i < jA[k])
 				jAn[con[i]++] = jA[k];
 
-	BaseLib::swap(jA, jAn);
-	BaseLib::swap(iA, iAn);
+	std::swap(jA, jAn);
+	std::swap(iA, iAn);
 
 	delete[] jAn;
 	delete[] con;
@@ -189,8 +188,8 @@ void genFullAdjMat(unsigned n, unsigned* &iA, unsigned* &jA)
 		}
 	}
 
-	BaseLib::swap(jA, jAn);
-	BaseLib::swap(iA, iAn);
+	std::swap(jA, jAn);
+	std::swap(iA, iAn);
 
 	delete[] jAn;
 	delete[] iAn;
diff --git a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/CRSMatrixReordered.cpp b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/CRSMatrixReordered.cpp
index e147ac155d7..ed13a75c044 100644
--- a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/CRSMatrixReordered.cpp
+++ b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/CRSMatrixReordered.cpp
@@ -64,9 +64,9 @@ void CRSMatrixReordered::reorderMatrix(unsigned const*const op_perm, unsigned co
 	for (i = 0; i < size; ++i)
 		BaseLib::quicksort(jAn, static_cast<size_t>(iAn[i]), static_cast<size_t>(iAn[i + 1]), An);
 
-	BaseLib::swap(iAn, _row_ptr);
-	BaseLib::swap(jAn, _col_idx);
-	BaseLib::swap(An, _data);
+	std::swap(iAn, _row_ptr);
+	std::swap(jAn, _col_idx);
+	std::swap(An, _data);
 
 	delete [] iAn;
 	delete [] jAn;
diff --git a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Cluster.cpp b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Cluster.cpp
index cd6bc82442c..e4c1f480f72 100644
--- a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Cluster.cpp
+++ b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Cluster.cpp
@@ -13,7 +13,6 @@
 #include "metis.h"
 
 // BaseLib
-#include "swap.h"
 
 #include "LinAlg/Sparse/NestedDissectionPermutation/Cluster.h"
 //#include "blas.h"
@@ -162,9 +161,9 @@ void Cluster::updatePerm(unsigned* reordering, unsigned &isep0,
 			while (beg < end && reordering[end] >= 1)
 				--end;
 			// local permutation
-			BaseLib::swap(l_op_perm[beg], l_op_perm[end]);
-			BaseLib::swap(l_po_perm[l_op_perm[beg]], l_po_perm[l_op_perm[end]]);
-			BaseLib::swap(reordering[beg], reordering[end]);
+			std::swap(l_op_perm[beg], l_op_perm[end]);
+			std::swap(l_po_perm[l_op_perm[beg]], l_po_perm[l_op_perm[end]]);
+			std::swap(reordering[beg], reordering[end]);
 		}
 		++beg;
 	}
@@ -180,9 +179,9 @@ void Cluster::updatePerm(unsigned* reordering, unsigned &isep0,
 			while (beg < end && reordering[end] == 2)
 				--end;
 			// local permutation
-			BaseLib::swap(l_op_perm[beg], l_op_perm[end]);
-			BaseLib::swap(l_po_perm[l_op_perm[beg]], l_po_perm[l_op_perm[end]]);
-			BaseLib::swap(reordering[beg], reordering[end]);
+			std::swap(l_op_perm[beg], l_op_perm[end]);
+			std::swap(l_po_perm[l_op_perm[beg]], l_po_perm[l_op_perm[end]]);
+			std::swap(reordering[beg], reordering[end]);
 		}
 		++beg;
 	}
diff --git a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Separator.cpp b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Separator.cpp
index fd5f31beb5c..f65c1aa6815 100644
--- a/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Separator.cpp
+++ b/MathLib/LinAlg/Sparse/NestedDissectionPermutation/Separator.cpp
@@ -11,7 +11,6 @@
  */
 
 // BaseLib
-#include "swap.h"
 
 #include "LinAlg/Sparse/NestedDissectionPermutation/Separator.h"
 
@@ -39,8 +38,8 @@ unsigned Separator::updatePerm(unsigned* reordering, unsigned* l_op_perm, unsign
       --end;
       while (beg < end && reordering[end] == 1) --end;
       // local permutation
-      BaseLib::swap(l_op_perm [beg], l_op_perm[end]);
-      BaseLib::swap(l_po_perm[l_op_perm [beg]], l_po_perm[l_op_perm[end]]);
+      std::swap(l_op_perm [beg], l_op_perm[end]);
+      std::swap(l_po_perm[l_op_perm [beg]], l_po_perm[l_op_perm[end]]);
     }
     ++beg;
   }
diff --git a/Tests/BaseLib/TestSwap.cpp b/Tests/BaseLib/TestSwap.cpp
index c5094b4627e..2265a30a11f 100644
--- a/Tests/BaseLib/TestSwap.cpp
+++ b/Tests/BaseLib/TestSwap.cpp
@@ -12,12 +12,10 @@
 // ** INCLUDES **
 #include "gtest.h"
 
-#include "swap.h"
-
 TEST(BaseLib, SwapInt) {
 	int arg0 = 5;
 	int arg1 = 10;
-	BaseLib::swap(arg0, arg1);
+	std::swap(arg0, arg1);
 	ASSERT_EQ ( arg0, 10 );
 	ASSERT_EQ ( arg1, 5 );
 }
@@ -25,7 +23,7 @@ TEST(BaseLib, SwapInt) {
 TEST(BaseLib, SwapDouble) {
 	double arg0 = 5.0;
 	double arg1 = 10.0;
-	BaseLib::swap(arg0, arg1);
+	std::swap(arg0, arg1);
 	ASSERT_EQ ( arg0, 10.0 );
 	ASSERT_EQ ( arg1, 5.0 );
 }
@@ -33,7 +31,7 @@ TEST(BaseLib, SwapDouble) {
 TEST(BaseLib, SwapString) {
 	std::string arg0 = "5";
 	std::string arg1 = "10";
-	BaseLib::swap(arg0, arg1);
+	std::swap(arg0, arg1);
 	ASSERT_EQ ( arg0, std::string("10") );
 	ASSERT_EQ ( arg1, std::string("5") );
 }
-- 
GitLab