From 568dda59651b4ffd89f8539fae95fafdb8f12dd5 Mon Sep 17 00:00:00 2001
From: Dmitri Naumov <dmitri.naumov@ufz.de>
Date: Wed, 7 Nov 2012 19:30:52 +0100
Subject: [PATCH] Replace uniqueListInsert() with uniquePushBack().

This also removes uniqueVectorInsert(). The new function is working for all containers, which provide begin() and end() and typedef value_type.
---
 BaseLib/uniqueInsert.h               | 28 +++++-----------------------
 MathLib/EarClippingTriangulation.cpp |  8 ++++----
 2 files changed, 9 insertions(+), 27 deletions(-)

diff --git a/BaseLib/uniqueInsert.h b/BaseLib/uniqueInsert.h
index c5a9c238cba..6b28069d3d9 100644
--- a/BaseLib/uniqueInsert.h
+++ b/BaseLib/uniqueInsert.h
@@ -13,35 +13,17 @@
 #ifndef UNIQUELISTINSERT_H_
 #define UNIQUELISTINSERT_H_
 
-#include <list>
-#include <vector>
+#include <algorithm>
 
 namespace BaseLib {
 
-template<typename T>
-void uniqueListInsert (std::list<T>& list, T element)
+template<typename Container>
+void uniquePushBack(Container& container, typename Container::value_type const& element)
 {
-	// search element
-	typename std::list<T>::const_iterator it;
-	for (it = list.begin (); it != list.end(); it++) {
-		if (*it == element) return;
-	}
-	// element not found -> insert
-	list.push_back (element);
+    if (std::find(container.begin(), container.end(), element) == container.end())
+        container.push_back(element);
 }
 
-template<typename T>
-void uniqueVectorInsert (std::vector<T>& vec, T element)
-{
-	// search element
-	typename std::vector<T>::const_iterator it;
-	for (it = vec.begin (); it != vec.end(); ++it)
-		if (*it == element) return;
-	// element not found -> insert
-	vec.push_back (element);
-}
-
-
 } // end namespace BaseLib
 
 #endif /* UNIQUELISTINSERT_H_ */
diff --git a/MathLib/EarClippingTriangulation.cpp b/MathLib/EarClippingTriangulation.cpp
index 27482f4fea6..05f485f1097 100644
--- a/MathLib/EarClippingTriangulation.cpp
+++ b/MathLib/EarClippingTriangulation.cpp
@@ -226,11 +226,11 @@ void EarClippingTriangulation::clipEars()
 				MathLib::Orientation orientation = getOrientation(_pnts[*prevprev], _pnts[*prev],
 						_pnts[*next]);
 				if (orientation == CW) {
-					BaseLib::uniqueListInsert<std::size_t>(_convex_vertex_list, *prev);
+					BaseLib::uniquePushBack(_convex_vertex_list, *prev);
 					// prev is convex
 					if (isEar(*prevprev, *prev, *next)) {
 						// prev is an ear tip
-						BaseLib::uniqueListInsert<std::size_t>(_ear_list, *prev);
+						BaseLib::uniquePushBack(_ear_list, *prev);
 					} else {
 						// if necessary remove prev
 						_ear_list.remove(*prev);
@@ -265,11 +265,11 @@ void EarClippingTriangulation::clipEars()
 				orientation = getOrientation(_pnts[*prev], _pnts[*next],
 						_pnts[*nextnext]);
 				if (orientation == CW) {
-					BaseLib::uniqueListInsert<std::size_t>(_convex_vertex_list, *next);
+					BaseLib::uniquePushBack(_convex_vertex_list, *next);
 					// next is convex
 					if (isEar(*prev, *next, *nextnext)) {
 						// next is an ear tip
-						BaseLib::uniqueListInsert<std::size_t>(_ear_list, *next);
+						BaseLib::uniquePushBack(_ear_list, *next);
 					} else {
 						// if necessary remove *next
 						_ear_list.remove(*next);
-- 
GitLab