From cc9ba43a316bc8d92d1c9d1ea4ac6099c541c8ea Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Thu, 7 Apr 2016 14:24:03 +0200 Subject: [PATCH] [BL] Impl. of makeVectorUnique(). --- BaseLib/makeVectorUnique.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 BaseLib/makeVectorUnique.h diff --git a/BaseLib/makeVectorUnique.h b/BaseLib/makeVectorUnique.h new file mode 100644 index 00000000000..160f1e84ae9 --- /dev/null +++ b/BaseLib/makeVectorUnique.h @@ -0,0 +1,31 @@ +/** + * + * \copyright + * Copyright (c) 2012-2016, OpenGeoSys Community (http://www.opengeosys.org) + * Distributed under a Modified BSD License. + * See accompanying file LICENSE.txt or + * http://www.opengeosys.org/project/license + * + */ + +#ifndef MAKEVECTORUNIQUE_H +#define MAKEVECTORUNIQUE_H + +#include <algorithm> +#include <vector> + +namespace BaseLib +{ + +/// Make the entries of the std::vector \c v unique. The remaining entries will +/// be sorted. +template <typename T> +void makeVectorUnique(std::vector<T>& v) +{ + std::sort(v.begin(), v.end()); + auto it = std::unique(v.begin(), v.end()); + v.erase(it, v.end()); +} + +} // end namespace BaseLib +#endif -- GitLab