summaryrefslogtreecommitdiff
path: root/zen/stl_tools.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2021-05-10 08:05:45 -0400
committerB. Stack <bgstack15@gmail.com>2021-05-10 08:05:45 -0400
commit0d0f8635218a2893fcd00385019089253474f634 (patch)
tree9261c60b81eb28e068f0f2f44fd8e60214462b2a /zen/stl_tools.h
parentMerge branch '11.9' into 'master' (diff)
downloadFreeFileSync-0d0f8635218a2893fcd00385019089253474f634.tar.gz
FreeFileSync-0d0f8635218a2893fcd00385019089253474f634.tar.bz2
FreeFileSync-0d0f8635218a2893fcd00385019089253474f634.zip
add upstream 11.10
Diffstat (limited to 'zen/stl_tools.h')
-rw-r--r--zen/stl_tools.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index 53b95241..a1c5b7b1 100644
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -36,6 +36,12 @@ void removeDuplicates(std::vector<T, Alloc>& v);
template <class T, class Alloc, class CompLess>
void removeDuplicates(std::vector<T, Alloc>& v, CompLess less);
+template <class T, class Alloc, class CompLess>
+void removeDuplicatesStable(std::vector<T, Alloc>& v, CompLess less);
+
+template <class T, class Alloc>
+void removeDuplicatesStable(std::vector<T, Alloc>& v);
+
//searching STL containers
template <class BidirectionalIterator, class T>
BidirectionalIterator findLast(BidirectionalIterator first, BidirectionalIterator last, const T& value);
@@ -132,6 +138,22 @@ void removeDuplicates(std::vector<T, Alloc>& v)
}
+template <class T, class Alloc, class CompLess> inline
+void removeDuplicatesStable(std::vector<T, Alloc>& v, CompLess less)
+{
+ std::set<T, CompLess> usedItems(less);
+ v.erase(std::remove_if(v.begin(), v.end(),
+ [&usedItems](const T& e) { return !usedItems.insert(e).second; }), v.end());
+}
+
+
+template <class T, class Alloc> inline
+void removeDuplicatesStable(std::vector<T, Alloc>& v)
+{
+ removeDuplicatesStable(v, std::less());
+}
+
+
template <class Iterator, class T, class CompLess> inline
Iterator binarySearch(Iterator first, Iterator last, const T& value, CompLess less)
{
bgstack15