[libcxx-commits] [libcxx] [libc++] Implement any_of in terms of find_if (PR #207274)
Nikolas Klauser via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 7 01:29:44 PDT 2026
================
@@ -10,33 +10,37 @@
#ifndef _LIBCPP___ALGORITHM_ANY_OF_H
#define _LIBCPP___ALGORITHM_ANY_OF_H
+#include <__algorithm/find_if.h>
#include <__config>
#include <__functional/identity.h>
-#include <__type_traits/invoke.h>
+#include <__utility/forward.h>
+#include <__utility/move.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
+_LIBCPP_PUSH_MACROS
+#include <__undef_macros>
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Iter, class _Sent, class _Proj, class _Pred>
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 bool
__any_of(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
- for (; __first != __last; ++__first) {
- if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
- return true;
- }
- return false;
+ auto __found = std::__find_if(std::move(__first), __last, __pred, __proj);
+ return __found != __last;
----------------
philnik777 wrote:
```suggestion
return std::__find_if(std::move(__first), __last, __pred, __proj) != __last;
```
No strong feelings either way. (Though I don't like `__found`, since it sounds like a bool)
https://github.com/llvm/llvm-project/pull/207274
More information about the libcxx-commits
mailing list