Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-05-26 13:49:01 +0300
committerVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2016-05-27 14:17:14 +0300
commite060fd2fa6898a41d8f849b8d575dd17cd1d2bb4 (patch)
tree398814db7e8d3463b04e6eff7b8d84a85974f9f5 /base/stl_helpers.hpp
parent36c26c63894dfe127d5d3ecf521e9d6a17bf20f5 (diff)
SortUnique refactoring.
Diffstat (limited to 'base/stl_helpers.hpp')
-rw-r--r--base/stl_helpers.hpp17
1 files changed, 5 insertions, 12 deletions
diff --git a/base/stl_helpers.hpp b/base/stl_helpers.hpp
index 035b77e161..b11f95eec7 100644
--- a/base/stl_helpers.hpp
+++ b/base/stl_helpers.hpp
@@ -86,20 +86,13 @@ void SortUnique(vector<T> & v)
v.erase(unique(v.begin(), v.end()), v.end());
}
-// Sorts and removes duplicate entries from |v| according to |comp|.
-// Note. If several entries are equivalent according to |comp| an arbitrary entry of them
-// is left in |v| after a call of this method.
-// Note. |comp| should implement operator<. It means the expression
-// !comp(t1, t2) && !comp(t2, t1) should return true iff t1 is equivalent to t2.
-// It's necessary for std::unique.
-template <typename T>
-void SortUnique(function<bool(T const &, T const &)> const & comp, vector<T> & v)
+// Sorts according to |comp| and removes duplicate entries according to |pred| from |v|.
+// Note. If several entries are equal according to |pred| an arbitrary entry of them
+// is left in |v| after a call of this function.
+template <typename T, typename TComp, typename TPred>
+void SortUnique(vector<T> & v, TComp && comp, TPred && pred)
{
sort(v.begin(), v.end(), comp);
- function<bool(T const &, T const &)> const pred = [&comp](T const & t1, T const & t2)
- {
- return !comp(t1, t2) && !comp(t2, t1);
- };
v.erase(unique(v.begin(), v.end(), pred), v.end());
}