File indexing completed on 2026-05-03 08:13:07
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LIBCPP___ALGORITHM_COUNT_IF_H
0011 #define _LIBCPP___ALGORITHM_COUNT_IF_H
0012
0013 #include <__algorithm/iterator_operations.h>
0014 #include <__config>
0015 #include <__functional/identity.h>
0016 #include <__iterator/iterator_traits.h>
0017 #include <__type_traits/invoke.h>
0018
0019 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
0020 # pragma GCC system_header
0021 #endif
0022
0023 _LIBCPP_BEGIN_NAMESPACE_STD
0024
0025 template <class _AlgPolicy, class _Iter, class _Sent, class _Proj, class _Pred>
0026 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t<_AlgPolicy, _Iter>
0027 __count_if(_Iter __first, _Sent __last, _Pred& __pred, _Proj& __proj) {
0028 __policy_iter_diff_t<_AlgPolicy, _Iter> __counter(0);
0029 for (; __first != __last; ++__first) {
0030 if (std::__invoke(__pred, std::__invoke(__proj, *__first)))
0031 ++__counter;
0032 }
0033 return __counter;
0034 }
0035
0036 template <class _InputIterator, class _Predicate>
0037 [[__nodiscard__]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
0038 typename iterator_traits<_InputIterator>::difference_type
0039 count_if(_InputIterator __first, _InputIterator __last, _Predicate __pred) {
0040 __identity __proj;
0041 return std::__count_if<_ClassicAlgPolicy>(__first, __last, __pred, __proj);
0042 }
0043
0044 _LIBCPP_END_NAMESPACE_STD
0045
0046 #endif