diff --git a/BaseLib/makeVectorUnique.h b/BaseLib/makeVectorUnique.h index 160f1e84ae9eb1ef59f93e7e3dec2934e98b9224..4fa9522d02296802e5ec947c7d735df22d4583a3 100644 --- a/BaseLib/makeVectorUnique.h +++ b/BaseLib/makeVectorUnique.h @@ -27,5 +27,15 @@ void makeVectorUnique(std::vector<T>& v) v.erase(it, v.end()); } +/// Make the entries of the std::vector \c v unique using the given binary +/// function. The remaining entries will be sorted. +template <typename T, class Compare> +void makeVectorUnique(std::vector<T>& v, Compare comp) +{ + std::sort(v.begin(), v.end(), comp); + auto it = std::unique(v.begin(), v.end()); + v.erase(it, v.end()); +} + } // end namespace BaseLib #endif