diff options
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) { |