aboutsummaryrefslogtreecommitdiff
path: root/lib/libcxx/include/__algorithm/count_if.h
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2025-04-05 01:46:13 -0400
committerGitHub <noreply@github.com>2025-04-05 01:46:13 -0400
commit0cd31fc7ff157551cfbba5da35cd79f118d2a2e3 (patch)
treea308488f5d85184c8ec402fb3f55f1cf2704443e /lib/libcxx/include/__algorithm/count_if.h
parent8acedfd5baabab705946ad097746f9183ef62420 (diff)
parentcefe65c1b8abe65a22d4b68410db1be264fdeda0 (diff)
downloadzig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.tar.gz
zig-0cd31fc7ff157551cfbba5da35cd79f118d2a2e3.zip
Merge pull request #22780 from ziglang/llvm20
LLVM 20
Diffstat (limited to 'lib/libcxx/include/__algorithm/count_if.h')
-rw-r--r--lib/libcxx/include/__algorithm/count_if.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/lib/libcxx/include/__algorithm/count_if.h b/lib/libcxx/include/__algorithm/count_if.h
index 25782069d0..26f945e6bd 100644
--- a/lib/libcxx/include/__algorithm/count_if.h
+++ b/lib/libcxx/include/__algorithm/count_if.h
@@ -10,8 +10,11 @@
#ifndef _LIBCPP___ALGORITHM_COUNT_IF_H
#define _LIBCPP___ALGORITHM_COUNT_IF_H
+#include <__algorithm/iterator_operations.h>
#include <__config>
+#include <__functional/identity.h>
#include <__iterator/iterator_traits.h>
+#include <__type_traits/invoke.h>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
@@ -19,15 +22,23 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+template <class _AlgPolicy, class _Iter, class _Sent, class _Proj, class _Pred>
+_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter>
+__count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
+ __policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0);
+ for (; __first != __last; ++__first) {
+ if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
+ ++__counter;
+ }
+ return __counter;
+}
+
template <class _InputIterator, class _Predicate>
-_LIBCPP_NODISCARD inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
+[[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
typename iterator_traits<_InputIterator>::difference_type
count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
- typename iterator_traits<_InputIterator>::difference_type __r(0);
- for (; __first != __last; ++__first)
- if (__pred(*__first))
- ++__r;
- return __r;
+ __identity __proj;
+ return std::__count_if<_ClassicAlgPolicy>(__first, __last, __pred, __proj);
}
_LIBCPP_END_NAMESPACE_STD