summaryrefslogtreecommitdiff
path: root/zen/stl_tools.h
diff options
context:
space:
mode:
authorB. Stack <bgstack15@gmail.com>2023-07-24 15:08:16 -0400
committerB. Stack <bgstack15@gmail.com>2023-07-24 15:08:16 -0400
commit69e12f5bd10459ff7c239b82519107ae2a755bc0 (patch)
tree8b22393241df7e46686c9426140582bd747a6d5a /zen/stl_tools.h
parentadd upstream 12.4 (diff)
downloadFreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.tar.gz
FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.tar.bz2
FreeFileSync-69e12f5bd10459ff7c239b82519107ae2a755bc0.zip
add upstream 12.5
Diffstat (limited to 'zen/stl_tools.h')
-rw-r--r--zen/stl_tools.h28
1 files changed, 13 insertions, 15 deletions
diff --git a/zen/stl_tools.h b/zen/stl_tools.h
index 03e7901a..ff574368 100644
--- a/zen/stl_tools.h
+++ b/zen/stl_tools.h
@@ -187,7 +187,7 @@ void removeDuplicates(std::vector<T, Alloc>& v, CompLess less)
template <class T, class Alloc> inline
void removeDuplicates(std::vector<T, Alloc>& v)
{
- removeDuplicates(v, std::less(), std::equal_to());
+ removeDuplicates(v, std::less{}, std::equal_to{});
}
@@ -196,14 +196,14 @@ 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());
+ /**/[&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());
+ removeDuplicatesStable(v, std::less{});
}
@@ -234,30 +234,28 @@ BidirectionalIterator findLast(const BidirectionalIterator first, const Bidirect
}
-template <class RandomAccessIterator1, class RandomAccessIterator2> inline
+template <class RandomAccessIterator1, class RandomAccessIterator2, class IsEq> inline
RandomAccessIterator1 searchFirst(const RandomAccessIterator1 first, const RandomAccessIterator1 last,
- const RandomAccessIterator2 needleFirst, const RandomAccessIterator2 needleLast)
+ const RandomAccessIterator2 needleFirst, const RandomAccessIterator2 needleLast, IsEq isEqual)
{
if (needleLast - needleFirst == 1) //don't use expensive std::search unless required!
- return std::find(first, last, *needleFirst);
+ return std::find_if(first, last, [needleFirst, isEqual](const auto c) { return isEqual(*needleFirst, c); });
+ //"*needleFirst" could be improved with value rather than pointer access, at least for built-in types like "char"
return std::search(first, last,
- needleFirst, needleLast);
+ needleFirst, needleLast, isEqual);
}
-template <class RandomAccessIterator1, class RandomAccessIterator2, class IsEq> inline
+template <class RandomAccessIterator1, class RandomAccessIterator2> inline
RandomAccessIterator1 searchFirst(const RandomAccessIterator1 first, const RandomAccessIterator1 last,
- const RandomAccessIterator2 needleFirst, const RandomAccessIterator2 needleLast, IsEq isEqual)
+ const RandomAccessIterator2 needleFirst, const RandomAccessIterator2 needleLast)
{
- if (needleLast - needleFirst == 1) //don't use expensive std::search unless required!
- return std::find_if(first, last, [needleFirst, isEqual](const auto c) { return isEqual(*needleFirst, c); });
-
- return std::search(first, last,
- needleFirst, needleLast, isEqual);
+ return searchFirst(first, last, needleFirst, needleLast, std::equal_to{});
}
+
template <class RandomAccessIterator1, class RandomAccessIterator2> inline
RandomAccessIterator1 searchLast(const RandomAccessIterator1 first, RandomAccessIterator1 last,
const RandomAccessIterator2 needleFirst, const RandomAccessIterator2 needleLast)
@@ -335,7 +333,7 @@ class FNV1aHash //FNV-1a: https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%8
{
public:
FNV1aHash() {}
- explicit FNV1aHash(Num startVal) : hashVal_(startVal) { assert(startVal != 0); /*(yes, might be a real hash, but) most likely bad init value*/}
+ explicit FNV1aHash(Num startVal) : hashVal_(startVal) { assert(startVal != 0); /*yes, might be a real hash, but most likely bad init value*/}
void add(Num n)
{
bgstack15