2 //===----------------------------------------------------------------------===//
4 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5 // See https://llvm.org/LICENSE.txt for license information.
6 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
8 //===----------------------------------------------------------------------===//
10 #ifndef _LIBCPP___ALGORITHM_COUNT_IF_H
11 #define _LIBCPP___ALGORITHM_COUNT_IF_H
13 #include <__algorithm/iterator_operations.h>
15 #include <__functional/identity.h>
16 #include <__iterator/iterator_traits.h>
17 #include <__type_traits/invoke.h>
19 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
20 # pragma GCC system_header
23 _LIBCPP_BEGIN_NAMESPACE_STD
25 template <class _AlgPolicy
, class _Iter
, class _Sent
, class _Proj
, class _Pred
>
26 _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX14 __policy_iter_diff_t
<_AlgPolicy
, _Iter
>
27 __count_if(_Iter __first
, _Sent __last
, _Pred
& __pred
, _Proj
& __proj
) {
28 __policy_iter_diff_t
<_AlgPolicy
, _Iter
> __counter(0);
29 for (; __first
!= __last
; ++__first
) {
30 if (std::__invoke(__pred
, std::__invoke(__proj
, *__first
)))
36 template <class _InputIterator
, class _Predicate
>
37 [[__nodiscard__
]] inline _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20
38 typename iterator_traits
<_InputIterator
>::difference_type
39 count_if(_InputIterator __first
, _InputIterator __last
, _Predicate __pred
) {
41 return std::__count_if
<_ClassicAlgPolicy
>(__first
, __last
, __pred
, __proj
);
44 _LIBCPP_END_NAMESPACE_STD
46 #endif // _LIBCPP___ALGORITHM_COUNT_IF_H