summaryrefslogtreecommitdiff
path: root/zen/stl_tools.h
diff options
context:
space:
mode:
authorB Stack <bgstack15@gmail.com>2018-09-10 02:46:25 +0000
committerB Stack <bgstack15@gmail.com>2018-09-10 02:46:25 +0000
commit728d32e6da9ce66968f8eef47a59505d613e2c1b (patch)
tree0f0441755ff0e6d65e12222d4502c648bffd6a7c /zen/stl_tools.h
parent10.3 (diff)
parentpull in latest 10.4 from upstream (diff)
downloadFreeFileSync-728d32e6da9ce66968f8eef47a59505d613e2c1b.tar.gz
FreeFileSync-728d32e6da9ce66968f8eef47a59505d613e2c1b.tar.bz2
FreeFileSync-728d32e6da9ce66968f8eef47a59505d613e2c1b.zip
Merge branch '10.4' into 'master'10.4
pull in latest 10.4 from upstream See merge request opensource-tracking/FreeFileSync!1
Diffstat (limited to 'zen/stl_tools.h')
-rwxr-xr-xzen/stl_tools.h30
1 files changed, 25 insertions, 5 deletions
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index 7365392f..be9bf710 100755
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -12,7 +12,7 @@
#include <vector>
#include <memory>
#include <algorithm>
-#include "type_traits.h"
+#include "string_traits.h"
#include "build_info.h"
@@ -42,8 +42,11 @@ void append(std::map<KeyType, ValueType, LessType, Alloc>& m, const C& c);
template <class T, class Alloc>
void removeDuplicates(std::vector<T, Alloc>& v);
+template <class T, class Alloc, class CompLess>
+void removeDuplicates(std::vector<T, Alloc>& v, CompLess less);
+
//binary search returning an iterator
-template <class Iterator, class T, typename CompLess>
+template <class Iterator, class T, class CompLess>
Iterator binary_search(Iterator first, Iterator last, const T& value, CompLess less);
template <class BidirectionalIterator, class T>
@@ -70,6 +73,9 @@ struct StringHash
};
+//why, oh wy is there no std::optional<T>::get()???
+template <class T> inline T* get( std::optional<T>& opt) { return opt ? &*opt : nullptr; }
+template <class T> inline const T* get(const std::optional<T>& opt) { return opt ? &*opt : nullptr; }
@@ -117,15 +123,29 @@ template <class KeyType, class ValueType, class LessType, class Alloc, class C>
void append(std::map<KeyType, ValueType, LessType, Alloc>& m, const C& c) { m.insert(c.begin(), c.end()); }
+template <class T, class Alloc, class CompLess, class CompEqual> inline
+void removeDuplicates(std::vector<T, Alloc>& v, CompLess less, CompEqual eq)
+{
+ std::sort(v.begin(), v.end(), less);
+ v.erase(std::unique(v.begin(), v.end(), eq), v.end());
+}
+
+
+template <class T, class Alloc, class CompLess> inline
+void removeDuplicates(std::vector<T, Alloc>& v, CompLess less)
+{
+ removeDuplicates(v, less, [&](const auto& lhs, const auto& rhs) { return !less(lhs, rhs) && !less(rhs, lhs); });
+}
+
+
template <class T, class Alloc> inline
void removeDuplicates(std::vector<T, Alloc>& v)
{
- std::sort(v.begin(), v.end());
- v.erase(std::unique(v.begin(), v.end()), v.end());
+ removeDuplicates(v, std::less<T>(), std::equal_to<T>());
}
-template <class Iterator, class T, typename CompLess> inline
+template <class Iterator, class T, class CompLess> inline
Iterator binary_search(Iterator first, Iterator last, const T& value, CompLess less)
{
static_assert(std::is_same_v<typename std::iterator_traits<Iterator>::iterator_category, std::random_access_iterator_tag>);
bgstack15