diff options
author | B. Stack <bgstack15@gmail.com> | 2021-05-10 12:09:24 +0000 |
---|---|---|
committer | B. Stack <bgstack15@gmail.com> | 2021-05-10 12:09:24 +0000 |
commit | 692fd264ae30b5b844f748626262e79bc3d5a7e2 (patch) | |
tree | 9261c60b81eb28e068f0f2f44fd8e60214462b2a /zen/stl_tools.h | |
parent | Merge branch '11.9' into 'master' (diff) | |
parent | add upstream 11.10 (diff) | |
download | FreeFileSync-692fd264ae30b5b844f748626262e79bc3d5a7e2.tar.gz FreeFileSync-692fd264ae30b5b844f748626262e79bc3d5a7e2.tar.bz2 FreeFileSync-692fd264ae30b5b844f748626262e79bc3d5a7e2.zip |
Merge branch '11.10' into 'master'11.10
add upstream 11.10
See merge request opensource-tracking/FreeFileSync!33
Diffstat (limited to 'zen/stl_tools.h')
-rw-r--r-- | zen/stl_tools.h | 22 |
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) { |