[libcxx-commits] [libcxx] Optimize the implementation of std::find_first_of to use any_of #129319 (PR #129574)
Ali Raeisdanaei via libcxx-commits
libcxx-commits at lists.llvm.org
Sat Apr 19 16:32:38 PDT 2025
https://github.com/aliraeisdanaei updated https://github.com/llvm/llvm-project/pull/129574
>From 95937e669886d7b22c9106e6c503c9fa049ef3e1 Mon Sep 17 00:00:00 2001
From: aliraeisdanaei <mrrookie2 at gmail.com>
Date: Mon, 3 Mar 2025 14:14:06 -0500
Subject: [PATCH] Change the implementation of std::find_first_of.h to use
any_of #129319
---
libcxx/include/__algorithm/find_first_of.h | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/libcxx/include/__algorithm/find_first_of.h b/libcxx/include/__algorithm/find_first_of.h
index 45ec133154371..54c0dbd103ddb 100644
--- a/libcxx/include/__algorithm/find_first_of.h
+++ b/libcxx/include/__algorithm/find_first_of.h
@@ -26,11 +26,9 @@ _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 _ForwardIterator1 __find_fir
_ForwardIterator2 __first2,
_ForwardIterator2 __last2,
_BinaryPredicate&& __pred) {
- for (; __first1 != __last1; ++__first1)
- for (_ForwardIterator2 __j = __first2; __j != __last2; ++__j)
- if (__pred(*__first1, *__j))
- return __first1;
- return __last1;
+ return std::find_if(first1, last1, [&](const auto& x) {
+ return std::any_of(first2, last2, [&](const auto& y) { return x == y; });
+ });
}
template <class _ForwardIterator1, class _ForwardIterator2, class _BinaryPredicate>
More information about the libcxx-commits
mailing list