From 69e12f5bd10459ff7c239b82519107ae2a755bc0 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Mon, 24 Jul 2023 15:08:16 -0400 Subject: add upstream 12.5 --- zen/stl_tools.h | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) (limited to 'zen/stl_tools.h') 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& v, CompLess less) template inline void removeDuplicates(std::vector& v) { - removeDuplicates(v, std::less(), std::equal_to()); + removeDuplicates(v, std::less{}, std::equal_to{}); } @@ -196,14 +196,14 @@ void removeDuplicatesStable(std::vector& v, CompLess less) { std::set 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 inline void removeDuplicatesStable(std::vector& v) { - removeDuplicatesStable(v, std::less()); + removeDuplicatesStable(v, std::less{}); } @@ -234,30 +234,28 @@ BidirectionalIterator findLast(const BidirectionalIterator first, const Bidirect } -template inline +template 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 inline +template 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 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) { -- cgit